From c13cf4f29cf7c0d6685356f5ea2eb81b09d22187 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 13 Apr 2021 23:09:54 +0200 Subject: [PATCH 1/2] Add setting to only build selected part of schematica schematic --- src/api/java/baritone/api/Settings.java | 5 ++ .../java/baritone/process/BuilderProcess.java | 8 ++- .../utils/schematic/SelectionSchematic.java | 56 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/main/java/baritone/utils/schematic/SelectionSchematic.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index ad0d487f..3756b0ee 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -847,6 +847,11 @@ public final class Settings { */ public final Setting skipFailedLayers = new Setting<>(false); + /** + * Only build the selected part of the schematic when using #schematica + */ + public final Setting schematicaOnlyBuildSelection = new Setting<>(false); + /** * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely */ diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index ca8ca534..b9f1c27c 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -43,6 +43,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.NotificationHelper; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; +import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SchematicSystem; import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -150,10 +151,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil Optional> schematic = SchematicaHelper.getOpenSchematic(); if (schematic.isPresent()) { IStaticSchematic s = schematic.get().getFirst(); + BlockPos origin = schematic.get().getSecond(); + ISchematic schem = Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s; + schem = Baritone.settings().schematicaOnlyBuildSelection.value ? new SelectionSchematic(schem, origin, baritone.getSelectionManager().getSelections()) : schem; this.build( schematic.get().getFirst().toString(), - Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s, - schematic.get().getSecond() + schem, + origin ); } else { logDirect("No schematic currently open"); diff --git a/src/main/java/baritone/utils/schematic/SelectionSchematic.java b/src/main/java/baritone/utils/schematic/SelectionSchematic.java new file mode 100644 index 00000000..81a381a3 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/SelectionSchematic.java @@ -0,0 +1,56 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.schematic; + +import baritone.api.schematic.ISchematic; +import baritone.api.schematic.MaskSchematic; +import baritone.api.selection.ISelection; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; + +import java.util.stream.Stream; + +public class SelectionSchematic extends MaskSchematic { + + private final ISelection[] selections; + + public SelectionSchematic(ISchematic schematic, BlockPos origin, ISelection[] selections) { + super(schematic); + baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", selections[0].min())); + this.selections = Stream.of(selections).map( + sel -> sel + .shift(EnumFacing.WEST, origin.getX()) + .shift(EnumFacing.DOWN, origin.getY()) + .shift(EnumFacing.NORTH, origin.getZ())) + .toArray(ISelection[]::new); + baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", this.selections[0].min())); + baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", origin)); + } + + @Override + protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { + for (ISelection selection : selections) { + if (x >= selection.min().x && y >= selection.min().y && z >= selection.min().z + && x <= selection.max().x && y <= selection.max().y && z <= selection.max().z) { + return true; + } + } + return false; + } +} From 46066d4cacc4d3076b95699dc2ea261bc04a34d4 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Wed, 14 Apr 2021 23:36:16 +0200 Subject: [PATCH 2/2] Misc * Rename schematicaOnlyBuildSelection to buildOnlySelection * Make it useable with #build as well * remove debugging code I forgot --- src/api/java/baritone/api/Settings.java | 4 ++-- src/main/java/baritone/process/BuilderProcess.java | 9 ++++++++- .../baritone/utils/schematic/SelectionSchematic.java | 7 ++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 3756b0ee..3481200c 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -848,9 +848,9 @@ public final class Settings { public final Setting skipFailedLayers = new Setting<>(false); /** - * Only build the selected part of the schematic when using #schematica + * Only build the selected part of schematics */ - public final Setting schematicaOnlyBuildSelection = new Setting<>(false); + public final Setting buildOnlySelection = new Setting<>(false); /** * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index b9f1c27c..cf5c0193 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -141,6 +141,11 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil parsed = new MapArtSchematic((IStaticSchematic) parsed); } + if (Baritone.settings().buildOnlySelection.value) { + parsed = new SelectionSchematic(parsed, origin, baritone.getSelectionManager().getSelections()); + } + + build(name, parsed, origin); return true; } @@ -153,7 +158,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil IStaticSchematic s = schematic.get().getFirst(); BlockPos origin = schematic.get().getSecond(); ISchematic schem = Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s; - schem = Baritone.settings().schematicaOnlyBuildSelection.value ? new SelectionSchematic(schem, origin, baritone.getSelectionManager().getSelections()) : schem; + if (Baritone.settings().buildOnlySelection.value) { + schem = new SelectionSchematic(schem, origin, baritone.getSelectionManager().getSelections()); + } this.build( schematic.get().getFirst().toString(), schem, diff --git a/src/main/java/baritone/utils/schematic/SelectionSchematic.java b/src/main/java/baritone/utils/schematic/SelectionSchematic.java index 81a381a3..243a3d4d 100644 --- a/src/main/java/baritone/utils/schematic/SelectionSchematic.java +++ b/src/main/java/baritone/utils/schematic/SelectionSchematic.java @@ -22,7 +22,7 @@ import baritone.api.schematic.MaskSchematic; import baritone.api.selection.ISelection; import net.minecraft.block.state.IBlockState; import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; import java.util.stream.Stream; @@ -30,17 +30,14 @@ public class SelectionSchematic extends MaskSchematic { private final ISelection[] selections; - public SelectionSchematic(ISchematic schematic, BlockPos origin, ISelection[] selections) { + public SelectionSchematic(ISchematic schematic, Vec3i origin, ISelection[] selections) { super(schematic); - baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", selections[0].min())); this.selections = Stream.of(selections).map( sel -> sel .shift(EnumFacing.WEST, origin.getX()) .shift(EnumFacing.DOWN, origin.getY()) .shift(EnumFacing.NORTH, origin.getZ())) .toArray(ISelection[]::new); - baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", this.selections[0].min())); - baritone.api.utils.Helper.HELPER.logDirect(String.format("%s", origin)); } @Override