initial bugfix for taller chunks

This commit is contained in:
Sen 2025-05-21 12:04:28 +02:00
parent caef42dc16
commit 7fd8a49d5c
6 changed files with 67 additions and 55 deletions

View file

@ -128,7 +128,7 @@ public class SPacketChunkData implements Packet<IClientPlayer>
}
extend = new int[list.size() - epos];
for(int z = 0; z < extend.length; z++) {
extend[z] = list.get(z + epos).getY();
extend[z] = list.get(z + epos).getY() >> 4;
}
s21packetchunkdata$extracted.extend = extend;

View file

@ -1,5 +1,7 @@
package common.world;
import java.util.Arrays;
import common.block.Block;
import common.init.BlockRegistry;
import common.init.Blocks;
@ -13,12 +15,17 @@ public class BlockArray {
private NibbleArray blocklight;
private NibbleArray skylight;
public BlockArray(int y, boolean sky) {
public BlockArray(int y, boolean sky, State filler) {
this.yBase = y;
this.data = new char[4096];
this.blocklight = new NibbleArray();
if(sky)
this.skylight = new NibbleArray();
if(filler != null && filler.getBlock() != Blocks.air) {
Arrays.fill(this.data, (char)BlockRegistry.STATEMAP.get(filler));
this.blocks = this.data.length;
this.ticked = filler.getBlock().getTickRandomly() ? this.data.length : 0;
}
}
public State get(int x, int y, int z) {

View file

@ -81,7 +81,7 @@ public class Chunk {
if(state != null && state.getBlock().getMaterial() != Material.air) {
int y = by >> 4;
if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky);
this.blocks[y] = new BlockArray(y << 4, sky, null);
this.blocks[y].set(bx, by & 15, bz, state);
}
}
@ -89,7 +89,7 @@ public class Chunk {
}
if(base != null) {
if(this.blocks[0] == null)
this.blocks[0] = new BlockArray(0, sky);
this.blocks[0] = new BlockArray(0, sky, null);
for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) {
for(int by = 0; by < 5; ++by) {
@ -102,10 +102,10 @@ public class Chunk {
if(ceil != null) {
int y = (height - 1) >> 4;
if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky);
this.blocks[y] = new BlockArray(y << 4, sky, null);
y = (height - 5) >> 4;
if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky);
this.blocks[y] = new BlockArray(y << 4, sky, null);
for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) {
for(int by = height - 1; by >= height - 5; --by) {
@ -119,7 +119,7 @@ public class Chunk {
this.biomes[n] = (byte)biomes[n].id;
}
this.bottom = height == 0 ? Integer.MAX_VALUE : 0;
this.top = height == 0 ? Integer.MIN_VALUE : (height + 15) >> 4;
this.top = height == 0 ? Integer.MIN_VALUE : ((height + 15) >> 4) << 4;
if(ceil == null)
this.genSkyLight();
else
@ -195,7 +195,7 @@ public class Chunk {
}
public BlockArray getArray(int y) {
return y >= 0 && y < this.blocks.length ? this.blocks[y] : (y < 0 ? (this.extendDown == null || -y > this.extendDown.length ? null : this.extendDown[-this.extendDown.length - y]) : (this.extendUp == null || y - this.blocks.length >= this.extendUp.length ? null : this.extendUp[y - this.blocks.length]));
return y >= 0 && y < this.blocks.length ? this.blocks[y] : (y < 0 ? (this.extendDown == null || -y > this.extendDown.length ? null : this.extendDown[this.extendDown.length + y]) : (this.extendUp == null || y - this.blocks.length >= this.extendUp.length ? null : this.extendUp[y - this.blocks.length]));
}
private void setArray(int y, BlockArray array) {
@ -211,7 +211,7 @@ public class Chunk {
this.extendDown = new BlockArray[-y];
System.arraycopy(extendDown, 0, this.extendDown, -y - extendDown.length, extendDown.length);
}
this.extendDown[-this.extendDown.length - y] = array;
this.extendDown[this.extendDown.length + y] = array;
}
else {
if(this.extendUp == null) {
@ -480,7 +480,7 @@ public class Chunk {
return stor != null ? stor.getBlock(x, y & 15, z) : Blocks.air;
}
else if(y < 0 && this.extendDown != null && -(y >> 4) <= this.extendDown.length) {
BlockArray stor = this.extendDown[-this.extendDown.length - (y >> 4)];
BlockArray stor = this.extendDown[this.extendDown.length + (y >> 4)];
return stor != null ? stor.getBlock(x, y & 15, z) : this.fillerBlock;
}
else if(y >> 4 >= this.blocks.length && this.extendUp != null && (y >> 4) - this.blocks.length < this.extendUp.length) {
@ -501,7 +501,7 @@ public class Chunk {
return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : Blocks.air.getState();
}
else if(pos.getY() < 0 && this.extendDown != null && -(pos.getY() >> 4) <= this.extendDown.length) {
BlockArray stor = this.extendDown[-this.extendDown.length - (pos.getY() >> 4)];
BlockArray stor = this.extendDown[this.extendDown.length + (pos.getY() >> 4)];
return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : this.filler;
}
else if(pos.getY() >> 4 >= this.blocks.length && this.extendUp != null && (pos.getY() >> 4) - this.blocks.length < this.extendUp.length) {
@ -538,11 +538,11 @@ public class Chunk {
boolean up = false;
if(stor == null) {
if(block == Blocks.air) {
if(block == Blocks.air && (y >= 0 || this.fillerBlock == Blocks.air)) {
return null;
}
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight());
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight(), y < 0 ? this.filler : null);
this.setArray(y >> 4, stor);
up = y >= h;
}
@ -631,7 +631,7 @@ public class Chunk {
BlockArray stor = this.getArray(y >> 4);
if(stor == null) {
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight());
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight(), y < 0 ? this.filler : null);
this.setArray(y >> 4, stor);
this.genSkyLight();
}
@ -939,7 +939,7 @@ public class Chunk {
for(int y = bottom; y <= top; y += 16) {
BlockArray stor = this.getArray(y >> 4);
if(stor != null && !stor.isEmpty()) {
if(stor != null ? !stor.isEmpty() : (y < 0 && this.fillerBlock != Blocks.air)) {
return false;
}
}
@ -970,7 +970,7 @@ public class Chunk {
for(int n = 0; n < this.blocks.length; ++n) {
if((update & 1 << n) != 0) {
if(this.blocks[n] == null) {
this.blocks[n] = new BlockArray(n << 4, sky);
this.blocks[n] = new BlockArray(n << 4, sky, null);
}
char[] blocks = this.blocks[n].getData();
@ -991,7 +991,8 @@ public class Chunk {
for(int cy : extend) {
BlockArray arr = this.getArray(cy);
if(arr == null) {
arr = new BlockArray(cy << 4, sky);
arr = new BlockArray(cy << 4, sky, null);
this.setArray(cy, arr);
}
char[] blocks = arr.getData();
@ -1111,11 +1112,11 @@ public class Chunk {
for(int n = 0; n < 8; ++n) {
if(this.top == Integer.MIN_VALUE)
return;
int h = 1 + this.top - this.bottom;
int h = 1 + (this.top >> 4) - (this.bottom >> 4);
if(this.lightChecks >= 256 * h)
return;
int s = (this.lightChecks % h) + this.bottom;
int s = (this.lightChecks % h) + (this.bottom >> 4);
int x = this.lightChecks / h % 16;
int z = this.lightChecks / 512;
++this.lightChecks;