From 7988274d616a19d487d52739547edaa440806941 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 12 Jan 2021 23:59:11 +0100 Subject: [PATCH 01/13] =?UTF-8?q?=E2=9C=A8=20add=20buildSkipBlocks=20setti?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/java/baritone/api/Settings.java | 9 +++++++++ src/main/java/baritone/process/BuilderProcess.java | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 69b7e552..2de53e60 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -206,6 +206,15 @@ public final class Settings { ))); + /** + * A list of blocks to be treated as correct. + *

+ * If a schematic asks for any block on this list at a certain position, it will be treated as correct, regardless of what it currently is. + */ + public final Setting> buildSkipBlocks = new Setting<>(new ArrayList<>(Arrays.asList( + + ))); + /** * A list of blocks to become air *

diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 00d3831c..1d08a0f1 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -794,6 +794,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value && !itemVerify) { return true; } + if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock())) { + return true; + } return current.equals(desired); } From dba186347c192c12eeb764e55be8751143d1728d Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Wed, 13 Jan 2021 22:45:59 +0100 Subject: [PATCH 02/13] remove likely useless code breaking buildSkipBlocks --- src/api/java/baritone/api/schematic/FillSchematic.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/api/java/baritone/api/schematic/FillSchematic.java b/src/api/java/baritone/api/schematic/FillSchematic.java index de9ccf97..edb1d611 100644 --- a/src/api/java/baritone/api/schematic/FillSchematic.java +++ b/src/api/java/baritone/api/schematic/FillSchematic.java @@ -44,8 +44,6 @@ public class FillSchematic extends AbstractSchematic { public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) { if (bom.matches(current)) { return current; - } else if (current.getBlock() != Blocks.AIR) { - return Blocks.AIR.getDefaultState(); } for (IBlockState placeable : approxPlaceable) { if (bom.matches(placeable)) { From 5e4f31f39e337bd70fe01c9b15b74a527cd318b3 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 16 Jan 2021 02:05:59 +0100 Subject: [PATCH 03/13] proper place/break costs for skipped blocks --- src/main/java/baritone/process/BuilderProcess.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 1d08a0f1..9e76b04b 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -794,7 +794,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value && !itemVerify) { return true; } - if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock())) { + if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock()) && !itemVerify) { return true; } return current.equals(desired); @@ -834,7 +834,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return COST_INF; } IBlockState sch = getSchematic(x, y, z, current); - if (sch != null) { + if (sch != null && !Baritone.settings().buildSkipBlocks.value.contains(sch.getBlock())) { // TODO this can return true even when allowPlace is off.... is that an issue? if (sch.getBlock() == Blocks.AIR) { // we want this to be air, but they're asking if they can place here @@ -868,7 +868,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return COST_INF; } IBlockState sch = getSchematic(x, y, z, current); - if (sch != null) { + if (sch != null && !Baritone.settings().buildSkipBlocks.value.contains(sch.getBlock())) { if (sch.getBlock() == Blocks.AIR) { // it should be air // regardless of current contents, we can break it From d375d1abc97b77a12c2d61408b9fd351d2b29595 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 17 Jan 2021 00:16:34 +0100 Subject: [PATCH 04/13] Add setting parser for mappings --- .../java/baritone/api/utils/SettingsUtil.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index f9cb7136..48c8ee4d 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -35,6 +35,7 @@ import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; @@ -261,6 +262,36 @@ public class SettingsUtil { public boolean accepts(Type type) { return List.class.isAssignableFrom(TypeUtils.resolveBaseClass(type)); } + }, + MAPPING() { + @Override + public Object parse(ParserContext context, String raw) { + Type keyType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; + Type valueType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[1]; + Parser keyParser = Parser.getParser(keyType); + Parser valueParser = Parser.getParser(valueType); + + return Stream.of(raw.split(",(?=[^,]*->)")) + .map(s -> s.split("->")) + .collect(Collectors.toMap(s -> keyParser.parse(context, s[0]), s -> valueParser.parse(context, s[1]))); + } + + @Override + public String toString(ParserContext context, Object value) { + Type keyType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; + Type valueType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[1]; + Parser keyParser = Parser.getParser(keyType); + Parser valueParser = Parser.getParser(valueType); + + return ((Map) value).entrySet().stream() + .map(o -> keyParser.toString(context, o.getKey()) + "->" + valueParser.toString(context, o.getValue())) + .collect(Collectors.joining(",")); + } + + @Override + public boolean accepts(Type type) { + return Map.class.isAssignableFrom(TypeUtils.resolveBaseClass(type)); + } }; private final Class cla$$; From 13547781d2088b63c1fab6803e3ddb75b1b0865c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 17 Jan 2021 00:53:50 +0100 Subject: [PATCH 05/13] add buildValidSubstitutes setting to builder --- src/api/java/baritone/api/Settings.java | 7 +++++++ src/main/java/baritone/process/BuilderProcess.java | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 2de53e60..1b9b173a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -215,6 +215,13 @@ public final class Settings { ))); + /** + * A mapping of blocks to blocks treated as correct in their position + *

+ * If a schematic asks for a block on this mapping, all blocks on the mapped list will be accepted at that location as well + */ + public final Setting>> buildValidSubstitutes = new Setting<>(new HashMap<>()); + /** * A list of blocks to become air *

diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 9e76b04b..77f0ef1c 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -797,6 +797,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock()) && !itemVerify) { return true; } + if (Baritone.settings().buildValidSubstitutes.value.getOrDefault(desired.getBlock(), Arrays.asList()).contains(current.getBlock()) && !itemVerify) { + return true; + } return current.equals(desired); } From fc1a2a61126201f14f41891a868f67546999c993 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 17 Jan 2021 02:45:40 +0100 Subject: [PATCH 06/13] Add buildSubstitutes setting to builder --- src/api/java/baritone/api/Settings.java | 7 ++ .../api/schematic/SubstituteSchematic.java | 71 +++++++++++++++++++ .../java/baritone/process/BuilderProcess.java | 4 ++ 3 files changed, 82 insertions(+) create mode 100644 src/api/java/baritone/api/schematic/SubstituteSchematic.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1b9b173a..0641ff8a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -222,6 +222,13 @@ public final class Settings { */ public final Setting>> buildValidSubstitutes = new Setting<>(new HashMap<>()); + /** + * A mapping of blocks to blocks to be built instead + *

+ * If a schematic asks for a block on this mapping, Baritone will place the first placeable block in the mapped list + */ + public final Setting>> buildSubstitutes = new Setting<>(new HashMap<>()); + /** * A list of blocks to become air *

diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java new file mode 100644 index 00000000..fbd19da8 --- /dev/null +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -0,0 +1,71 @@ +/* + * 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.api.schematic; + +import baritone.api.utils.BlockOptionalMetaLookup; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import java.util.List; +import java.util.Map; + +public class SubstituteSchematic extends AbstractSchematic { + + private final ISchematic schematic; + private final Map> substitutions; + + public SubstituteSchematic(ISchematic schematic, Map> substitutions) { + super(schematic.widthX(), schematic.heightY(), schematic.lengthZ()); + this.schematic = schematic; + this.substitutions = substitutions; + } + + @Override + public boolean inSchematic(int x, int y, int z, IBlockState currentState) { + return schematic.inSchematic(x, y, z, currentState); + } + + @Override + public IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable) { + IBlockState desired = schematic.desiredState(x, y, z, current, approxPlaceable); + Block desiredBlock = desired.getBlock(); + if (!substitutions.containsKey(desiredBlock)) { + return desired; + } + List substitutes = substitutions.get(desiredBlock); + if (substitutes.contains(current.getBlock()) && !current.getBlock().equals(Blocks.AIR)) {// don't preserve air, it's almost always there and almost never wanted + System.out.println(String.format("%s is already placed", current)); + return current; + } + for (Block substitute : substitutes) { + if (substitute.equals(Blocks.AIR)) { + System.out.println("air, lol"); + return Blocks.AIR.getDefaultState(); // can always "place" air + } + for (IBlockState placeable : approxPlaceable) { + if (substitute.equals(placeable.getBlock())) { + System.out.println(String.format("%s can be placed", placeable)); + return placeable; + } + } + System.out.println(String.format("%s is not an option", substitute)); + } + System.out.println(String.format("%s fail", substitutes.get(0).getDefaultState())); + return substitutes.get(0).getDefaultState(); + } +} diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 77f0ef1c..c5be76f0 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -26,6 +26,7 @@ import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.schematic.FillSchematic; +import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.ISchematic; import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; @@ -84,6 +85,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.name = name; this.schematic = schematic; this.realSchematic = null; + if (!Baritone.settings().buildSubstitutes.value.isEmpty()) { + this.schematic = new SubstituteSchematic(this.schematic, Baritone.settings().buildSubstitutes.value); + } int x = origin.getX(); int y = origin.getY(); int z = origin.getZ(); From f6d4a315c7f306d0468638e894a0a9fe74daa83f Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 18 Jan 2021 11:58:42 +0100 Subject: [PATCH 07/13] Remove debug log --- src/api/java/baritone/api/schematic/SubstituteSchematic.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index fbd19da8..675ccbff 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -49,23 +49,18 @@ public class SubstituteSchematic extends AbstractSchematic { } List substitutes = substitutions.get(desiredBlock); if (substitutes.contains(current.getBlock()) && !current.getBlock().equals(Blocks.AIR)) {// don't preserve air, it's almost always there and almost never wanted - System.out.println(String.format("%s is already placed", current)); return current; } for (Block substitute : substitutes) { if (substitute.equals(Blocks.AIR)) { - System.out.println("air, lol"); return Blocks.AIR.getDefaultState(); // can always "place" air } for (IBlockState placeable : approxPlaceable) { if (substitute.equals(placeable.getBlock())) { - System.out.println(String.format("%s can be placed", placeable)); return placeable; } } - System.out.println(String.format("%s is not an option", substitute)); } - System.out.println(String.format("%s fail", substitutes.get(0).getDefaultState())); return substitutes.get(0).getDefaultState(); } } From 8c1a9f460defa29c9086ed467aeded8fbce1f661 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 18 Jan 2021 12:06:50 +0100 Subject: [PATCH 08/13] Simple blockstate preservation for buildSubstitutes --- .../api/schematic/SubstituteSchematic.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index 675ccbff..fbc07580 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -19,8 +19,10 @@ package baritone.api.schematic; import baritone.api.utils.BlockOptionalMetaLookup; import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -49,7 +51,7 @@ public class SubstituteSchematic extends AbstractSchematic { } List substitutes = substitutions.get(desiredBlock); if (substitutes.contains(current.getBlock()) && !current.getBlock().equals(Blocks.AIR)) {// don't preserve air, it's almost always there and almost never wanted - return current; + return withBlock(desired, current.getBlock()); } for (Block substitute : substitutes) { if (substitute.equals(Blocks.AIR)) { @@ -57,10 +59,25 @@ public class SubstituteSchematic extends AbstractSchematic { } for (IBlockState placeable : approxPlaceable) { if (substitute.equals(placeable.getBlock())) { - return placeable; + return withBlock(desired, placeable.getBlock()); } } } return substitutes.get(0).getDefaultState(); } + + private IBlockState withBlock(IBlockState state, Block block) { + Collection> properties = state.getPropertyKeys(); + IBlockState newState = block.getDefaultState(); + for (IProperty property : properties) { + try { + newState = copySingleProp(state, newState, property); + } catch (IllegalArgumentException e) { //property does not exist for target block + } + } + return newState; + } + private > IBlockState copySingleProp(IBlockState fromState, IBlockState toState, IProperty prop) { + return toState.withProperty(prop, fromState.getValue(prop)); + } } From 34606415d75eb78e8e191c5ed93eabf2d66e34bc Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:44:43 +0100 Subject: [PATCH 09/13] Don't mark skipped blocks as invalid just because they are far away --- src/main/java/baritone/process/BuilderProcess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index c5be76f0..f6a69a0e 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -576,7 +576,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; } // this is not in render distance - if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ))) { + if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ)) + && !Baritone.settings().buildSkipBlocks.value.contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) { // and we've never seen this position be correct // therefore mark as incorrect incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); From 113d26937d2a8dc3b2a872266ee71b75c2c10146 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Thu, 11 Feb 2021 01:08:33 +0100 Subject: [PATCH 10/13] remove unused imports --- src/api/java/baritone/api/schematic/FillSchematic.java | 1 - src/api/java/baritone/api/schematic/SubstituteSchematic.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/api/java/baritone/api/schematic/FillSchematic.java b/src/api/java/baritone/api/schematic/FillSchematic.java index edb1d611..f2fb203c 100644 --- a/src/api/java/baritone/api/schematic/FillSchematic.java +++ b/src/api/java/baritone/api/schematic/FillSchematic.java @@ -19,7 +19,6 @@ package baritone.api.schematic; import baritone.api.utils.BlockOptionalMeta; import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; import java.util.List; diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index fbc07580..c1cb5a18 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -17,7 +17,6 @@ package baritone.api.schematic; -import baritone.api.utils.BlockOptionalMetaLookup; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; From 363519db029b8fcc63103eb73a5d68dc6b0d09f9 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 9 Mar 2021 11:53:43 +0100 Subject: [PATCH 11/13] treat all airs as air --- .../java/baritone/api/schematic/SubstituteSchematic.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index c1cb5a18..439ba244 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -18,6 +18,7 @@ package baritone.api.schematic; import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -49,12 +50,12 @@ public class SubstituteSchematic extends AbstractSchematic { return desired; } List substitutes = substitutions.get(desiredBlock); - if (substitutes.contains(current.getBlock()) && !current.getBlock().equals(Blocks.AIR)) {// don't preserve air, it's almost always there and almost never wanted + if (substitutes.contains(current.getBlock()) && !(current.getBlock() instanceof BlockAir)) {// don't preserve air, it's almost always there and almost never wanted return withBlock(desired, current.getBlock()); } for (Block substitute : substitutes) { - if (substitute.equals(Blocks.AIR)) { - return Blocks.AIR.getDefaultState(); // can always "place" air + if (substitute instanceof BlockAir) { + return current.getBlock() instanceof BlockAir ? current : Blocks.AIR.getDefaultState(); // can always "place" air } for (IBlockState placeable : approxPlaceable) { if (substitute.equals(placeable.getBlock())) { From 61e0525ee86475a67b461e6174e99f94116d855a Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 9 Mar 2021 12:26:47 +0100 Subject: [PATCH 12/13] Don't copy block state properties every time --- .../java/baritone/api/schematic/SubstituteSchematic.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index 439ba244..72787c24 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -23,6 +23,7 @@ import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,6 +31,7 @@ public class SubstituteSchematic extends AbstractSchematic { private final ISchematic schematic; private final Map> substitutions; + private final Map> blockStateCache = new HashMap<>(); public SubstituteSchematic(ISchematic schematic, Map> substitutions) { super(schematic.widthX(), schematic.heightY(), schematic.lengthZ()); @@ -67,6 +69,9 @@ public class SubstituteSchematic extends AbstractSchematic { } private IBlockState withBlock(IBlockState state, Block block) { + if (blockStateCache.containsKey(state) && blockStateCache.get(state).containsKey(block)) { + return blockStateCache.get(state).get(block); + } Collection> properties = state.getPropertyKeys(); IBlockState newState = block.getDefaultState(); for (IProperty property : properties) { @@ -75,6 +80,7 @@ public class SubstituteSchematic extends AbstractSchematic { } catch (IllegalArgumentException e) { //property does not exist for target block } } + blockStateCache.computeIfAbsent(state, s -> new HashMap()).put(block, newState); return newState; } private > IBlockState copySingleProp(IBlockState fromState, IBlockState toState, IProperty prop) { From 67d9ae881f066891128e84295a219ef7704bfadc Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 9 Mar 2021 12:31:02 +0100 Subject: [PATCH 13/13] don't allocate tons of empty lists --- src/main/java/baritone/process/BuilderProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index f6a69a0e..08df9bad 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -802,7 +802,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (Baritone.settings().buildSkipBlocks.value.contains(desired.getBlock()) && !itemVerify) { return true; } - if (Baritone.settings().buildValidSubstitutes.value.getOrDefault(desired.getBlock(), Arrays.asList()).contains(current.getBlock()) && !itemVerify) { + if (Baritone.settings().buildValidSubstitutes.value.getOrDefault(desired.getBlock(), Collections.emptyList()).contains(current.getBlock()) && !itemVerify) { return true; } return current.equals(desired);