Merge pull request #2482 from ZacSharp/schematicCacheClearing

Clear caches of schematics when moving them
This commit is contained in:
Leijurv 2021-02-19 16:06:28 -08:00 committed by GitHub
commit b4eabe19cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 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,11 @@ 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) {
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

@ -387,6 +387,11 @@ 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() {
realSchematic.reset();
}
@Override
public int widthX() {
return realSchematic.widthX();
@ -424,6 +429,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
// build repeat time
layer = 0;
origin = new BlockPos(origin).add(repeat);
if (!Baritone.settings().buildRepeatSneaky.value) {
schematic.reset();
}
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
return onTick(calcFailed, isSafeToCancel, recursions + 1);
}