Clear caches of schematics when moving them
This commit is contained in:
		| @@ -834,6 +834,13 @@ public final class Settings { | |||||||
|      */ |      */ | ||||||
|     public final Setting<Integer> buildRepeatCount = new Setting<>(-1); |     public final Setting<Integer> 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<Boolean> buildRepeatSneaky = new Setting<>(true); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Allow standing above a block while mining it, in BuilderProcess |      * Allow standing above a block while mining it, in BuilderProcess | ||||||
|      * <p> |      * <p> | ||||||
|   | |||||||
| @@ -71,4 +71,13 @@ public class CompositeSchematic extends AbstractSchematic { | |||||||
|         } |         } | ||||||
|         return entry.schematic.desiredState(x - entry.x, y - entry.y, z - entry.z, current, approxPlaceable); |         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(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -73,6 +73,11 @@ public interface ISchematic { | |||||||
|      */ |      */ | ||||||
|     IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable); |     IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> 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 |      * @return The width (X axis length) of this schematic | ||||||
|      */ |      */ | ||||||
|   | |||||||
| @@ -31,6 +31,18 @@ public class ReplaceSchematic extends MaskSchematic { | |||||||
|         this.cache = new Boolean[widthX()][heightY()][lengthZ()]; |         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 |     @Override | ||||||
|     protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { |     protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { | ||||||
|         if (cache[x][y][z] == null) { |         if (cache[x][y][z] == null) { | ||||||
|   | |||||||
| @@ -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); |                     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 |                 @Override | ||||||
|                 public int widthX() { |                 public int widthX() { | ||||||
|                     return realSchematic.widthX(); |                     return realSchematic.widthX(); | ||||||
| @@ -417,6 +424,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil | |||||||
|             // build repeat time |             // build repeat time | ||||||
|             layer = 0; |             layer = 0; | ||||||
|             origin = new BlockPos(origin).add(repeat); |             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); |             logDirect("Repeating build in vector " + repeat + ", new origin is " + origin); | ||||||
|             return onTick(calcFailed, isSafeToCancel); |             return onTick(calcFailed, isSafeToCancel); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user