From c880f71dc8d4299080b9e3636c82ad5d04887825 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Wed, 17 Feb 2021 01:59:23 +0100 Subject: [PATCH] Clear caches of schematics when moving them --- src/api/java/baritone/api/Settings.java | 7 +++++++ .../baritone/api/schematic/CompositeSchematic.java | 9 +++++++++ src/api/java/baritone/api/schematic/ISchematic.java | 5 +++++ .../baritone/api/schematic/ReplaceSchematic.java | 12 ++++++++++++ src/main/java/baritone/process/BuilderProcess.java | 10 ++++++++++ 5 files changed, 43 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 9773fc0f..fe1f19ae 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -834,6 +834,13 @@ public final class Settings { */ public final Setting buildRepeatCount = new Setting<>(-1); + /** + * Don't notify schematics that they are moved. + * e.g. replacing will replace the same spots for every repetition + * Mainly for backward compatibility. + */ + public final Setting buildRepeatSneaky = new Setting<>(true); + /** * Allow standing above a block while mining it, in BuilderProcess *

diff --git a/src/api/java/baritone/api/schematic/CompositeSchematic.java b/src/api/java/baritone/api/schematic/CompositeSchematic.java index 2f119de1..17d31689 100644 --- a/src/api/java/baritone/api/schematic/CompositeSchematic.java +++ b/src/api/java/baritone/api/schematic/CompositeSchematic.java @@ -71,4 +71,13 @@ public class CompositeSchematic extends AbstractSchematic { } return entry.schematic.desiredState(x - entry.x, y - entry.y, z - entry.z, current, approxPlaceable); } + + @Override + public void reset(){ + for (CompositeSchematicEntry entry : schematicArr){ + if (!(entry.schematic instanceof IStaticSchematic)) { + entry.schematic.reset(); + } + } + } } diff --git a/src/api/java/baritone/api/schematic/ISchematic.java b/src/api/java/baritone/api/schematic/ISchematic.java index 88cfc899..82d71284 100644 --- a/src/api/java/baritone/api/schematic/ISchematic.java +++ b/src/api/java/baritone/api/schematic/ISchematic.java @@ -73,6 +73,11 @@ public interface ISchematic { */ IBlockState desiredState(int x, int y, int z, IBlockState current, List approxPlaceable); + /** + * Resets possible caches to avoid wrong behavior when moving the schematic around + */ + default void reset(){} + /** * @return The width (X axis length) of this schematic */ diff --git a/src/api/java/baritone/api/schematic/ReplaceSchematic.java b/src/api/java/baritone/api/schematic/ReplaceSchematic.java index f064435e..b9979b24 100644 --- a/src/api/java/baritone/api/schematic/ReplaceSchematic.java +++ b/src/api/java/baritone/api/schematic/ReplaceSchematic.java @@ -31,6 +31,18 @@ public class ReplaceSchematic extends MaskSchematic { this.cache = new Boolean[widthX()][heightY()][lengthZ()]; } + @Override + public void reset(){ + // it's final, can't use this.cache = new Boolean[widthX()][heightY()][lengthZ()] + for (int x = 0; x < cache.length; x++){ + for (int y = 0; y < cache[0].length; y++){ + for (int z = 0; z < cache[0][0].length; z++){ + cache[x][y][z] = null; + } + } + } + } + @Override protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { if (cache[x][y][z] == null) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 012b290e..18241fba 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -380,6 +380,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState); } + @Override + public void reset(){ + if (!(realSchematic instanceof IStaticSchematic)){ + realSchematic.reset(); + } + } + @Override public int widthX() { return realSchematic.widthX(); @@ -417,6 +424,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil // build repeat time layer = 0; origin = new BlockPos(origin).add(repeat); + if (!(schematic instanceof IStaticSchematic) && !Baritone.settings().buildRepeatSneaky.value){ + schematic.reset(); + } logDirect("Repeating build in vector " + repeat + ", new origin is " + origin); return onTick(calcFailed, isSafeToCancel); }