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] 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) {