fix Column erroneously caching

This commit is contained in:
dfsek
2022-06-19 02:05:36 -07:00
parent 33ca98ccaf
commit 865ec58d70
@@ -27,25 +27,19 @@ public class Column<T extends WritableWorld> {
private final int max; private final int max;
private final T world; private final T world;
private final BlockState[] cache;
public Column(int x, int z, T world) { public Column(int x, int z, T world) {
this(x, z, world, world.getMinHeight(), world.getMaxHeight(), new BlockState[world.getMaxHeight() - world.getMinHeight()]); this(x, z, world, world.getMinHeight(), world.getMaxHeight());
} }
public Column(int x, int z, T world, int min, int max) { public Column(int x, int z, T world, int min, int max) {
this(x, z, world, min, max, new BlockState[world.getMaxHeight() - world.getMinHeight()]);
}
private Column(int x, int z, T world, int min, int max, BlockState[] cache) {
this.x = x; this.x = x;
this.z = z; this.z = z;
this.world = world; this.world = world;
this.max = max; this.max = max;
this.min = min; this.min = min;
this.cache = cache;
} }
public int getX() { public int getX() {
return x; return x;
} }
@@ -55,13 +49,7 @@ public class Column<T extends WritableWorld> {
} }
public BlockState getBlock(int y) { public BlockState getBlock(int y) {
int i = y - world.getMinHeight(); return world.getBlockState(x, y, z);
BlockState state = cache[i];
if(state == null) {
state = world.getBlockState(x, y, z);
cache[i] = state;
}
return state;
} }
public T getWorld() { public T getWorld() {
@@ -84,7 +72,7 @@ public class Column<T extends WritableWorld> {
public Column<T> clamp(int min, int max) { public Column<T> clamp(int min, int max) {
if(min >= max) throw new IllegalArgumentException("Min greater than or equal to max: " + min + ", " + max); if(min >= max) throw new IllegalArgumentException("Min greater than or equal to max: " + min + ", " + max);
return new Column<>(x, z, world, min, max, cache); return new Column<>(x, z, world, min, max);
} }
public BinaryColumn newBinaryColumn(IntToBooleanFunction function) { public BinaryColumn newBinaryColumn(IntToBooleanFunction function) {