Clear caches of schematics when moving them

This commit is contained in:
ZacSharp 2021-02-17 01:59:23 +01:00
parent e97704b37f
commit c880f71dc8
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
5 changed files with 43 additions and 0 deletions

View File

@ -834,6 +834,13 @@ public final class Settings {
*/
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
* <p>

View File

@ -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();
}
}
}
}

View File

@ -73,6 +73,11 @@ public interface ISchematic {
*/
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
*/

View File

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

View File

@ -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);
}