fix chunk glitch

This commit is contained in:
Sen 2025-07-01 16:36:33 +02:00
parent 24e249913d
commit f241158cc1
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
3 changed files with 21 additions and 5 deletions

View file

@ -8,15 +8,19 @@ import common.init.Blocks;
import common.util.NibbleArray;
public class BlockArray {
private int yBase;
private final int yBase;
private final State filler;
private int blocks;
private int ticked;
private int filled;
private char[] data;
private NibbleArray blocklight;
private NibbleArray skylight;
public BlockArray(int y, boolean sky, State filler) {
this.yBase = y;
this.filler = filler;
this.data = new char[4096];
this.blocklight = new NibbleArray();
if(sky)
@ -47,6 +51,10 @@ public class BlockArray {
if(block.getTickRandomly())
++this.ticked;
}
if(ostate == this.filler)
++this.filled;
if(state == this.filler)
--this.filled;
this.data[y << 8 | z << 4 | x] = (char)BlockRegistry.getId(state);
}
@ -54,6 +62,10 @@ public class BlockArray {
return this.get(x, y, z).getBlock();
}
public boolean hasData() {
return this.filler != null ? (this.filled > 0) : (this.blocks > 0);
}
public boolean isEmpty() {
return this.blocks == 0;
}
@ -85,15 +97,19 @@ public class BlockArray {
public void update() {
this.blocks = 0;
this.ticked = 0;
this.filled = 0;
for(int i = 0; i < 16; ++i) {
for(int j = 0; j < 16; ++j) {
for(int k = 0; k < 16; ++k) {
Block block = this.getBlock(i, j, k);
State state = this.get(i, j, k);
Block block = state.getBlock();
if(block != Blocks.air) {
++this.blocks;
if(block.getTickRandomly())
++this.ticked;
}
if(this.filler != null && state != this.filler)
++this.filled;
}
}
}

View file

@ -875,14 +875,14 @@ public class Player extends User implements ICrafting, Executor, IPlayer
if(extend == null) {
for(BlockArray arr : aextendedblockstorage) {
if(arr != null && (!biomes || !arr.isEmpty()))
if(arr != null && (!biomes || arr.hasData()))
list.add(arr);
}
}
else {
for(int cy : extend) {
BlockArray arr = chunk.getArray(cy);
if(arr != null && (!biomes || !arr.isEmpty()))
if(arr != null && (!biomes || arr.hasData()))
list.add(arr);
}
}

View file

@ -562,7 +562,7 @@ public class Region {
for(int n = 0; n < sects.size(); ++n) {
TagObject sect = sects.get(n);
int y = sect.getInt("Y");
BlockArray storage = new BlockArray(y << 4, light, null);
BlockArray storage = new BlockArray(y << 4, light, y < 0 ? world.dimension.getFiller() : null);
byte[] blocks = sect.getByteArray("Dat0");
NibbleArray data = new NibbleArray(sect.getByteArray("Dat1"));
NibbleArray adddata = sect.hasByteArray("Dat2") ? new NibbleArray(sect.getByteArray("Dat2")) : null;