Skip to content

Commit

Permalink
Reduce Frequency of Crashes Due to Dispensers, Droppers, and Chiseled…
Browse files Browse the repository at this point in the history
… Bookshelves (GeyserMC#4248)

* Revert to subchunk v8; reduces freq of GeyserMC#4240

* Full resolution
  • Loading branch information
Kas-tle authored Oct 26, 2023
1 parent 2e68244 commit 8d2ebcf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@

public class GeyserChunkSection {

// As of at least 1.19.80
private static final int CHUNK_SECTION_VERSION = 9;
// Temporary reversion to v8 as it reduces the frequnecy of https://github.com/GeyserMC/Geyser/issues/4240
// This does not fully resolve the issue so a better solution is still needed
private static final int CHUNK_SECTION_VERSION = 8;

private final BlockStorage[] storage;
private final int sectionY;

public GeyserChunkSection(int airBlockId, int sectionY) {
this(new BlockStorage[]{new BlockStorage(airBlockId), new BlockStorage(airBlockId)}, sectionY);
public GeyserChunkSection(int airBlockId) {
this(new BlockStorage[]{new BlockStorage(airBlockId), new BlockStorage(airBlockId)});
}

public GeyserChunkSection(BlockStorage[] storage, int sectionY) {
public GeyserChunkSection(BlockStorage[] storage) {
this.storage = storage;
this.sectionY = sectionY;
}

public int getFullBlock(int x, int y, int z, int layer) {
Expand All @@ -61,7 +60,6 @@ public void writeToNetwork(ByteBuf buffer) {
buffer.writeByte(CHUNK_SECTION_VERSION);
buffer.writeByte(this.storage.length);
// Required for chunk version 9+
buffer.writeByte(this.sectionY);
for (BlockStorage blockStorage : this.storage) {
blockStorage.writeToNetwork(buffer);
}
Expand All @@ -88,12 +86,12 @@ public boolean isEmpty() {
return true;
}

public GeyserChunkSection copy(int sectionY) {
public GeyserChunkSection copy() {
BlockStorage[] storage = new BlockStorage[this.storage.length];
for (int i = 0; i < storage.length; i++) {
storage[i] = this.storage[i].copy();
}
return new GeyserChunkSection(storage, sectionY);
return new GeyserChunkSection(storage);
}

public static int blockPosition(int x, int y, int z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
}

BlockStorage[] layers = new BlockStorage[]{ layer0 };
sections[bedrockSectionY] = new GeyserChunkSection(layers, bedrockSectionY);
sections[bedrockSectionY] = new GeyserChunkSection(layers);
}
EXTENDED_COLLISIONS_STORAGE.get().clear();
extendedCollisionNextSection = false;
Expand All @@ -167,7 +167,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke

if (javaPalette instanceof GlobalPalette) {
// As this is the global palette, simply iterate through the whole chunk section once
GeyserChunkSection section = new GeyserChunkSection(session.getBlockMappings().getBedrockAir().getRuntimeId(), bedrockSectionY);
GeyserChunkSection section = new GeyserChunkSection(session.getBlockMappings().getBedrockAir().getRuntimeId());
for (int yzx = 0; yzx < BlockStorage.SIZE; yzx++) {
int javaId = javaData.get(yzx);
int bedrockId = session.getBlockMappings().getBedrockBlockId(javaId);
Expand Down Expand Up @@ -217,9 +217,9 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke

if (BlockRegistries.WATERLOGGED.get().get(javaId)) {
BlockStorage waterlogged = new BlockStorage(SingletonBitArray.INSTANCE, IntLists.singleton(session.getBlockMappings().getBedrockWater().getRuntimeId()));
sections[bedrockSectionY] = new GeyserChunkSection(new BlockStorage[] {blockStorage, waterlogged}, bedrockSectionY);
sections[bedrockSectionY] = new GeyserChunkSection(new BlockStorage[] {blockStorage, waterlogged});
} else {
sections[bedrockSectionY] = new GeyserChunkSection(new BlockStorage[] {blockStorage}, bedrockSectionY);
sections[bedrockSectionY] = new GeyserChunkSection(new BlockStorage[] {blockStorage});
}
if (useExtendedCollisions) {
EXTENDED_COLLISIONS_STORAGE.get().clear();
Expand Down Expand Up @@ -378,7 +378,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
layers = new BlockStorage[]{ layer0, new BlockStorage(BitArrayVersion.V1.createArray(BlockStorage.SIZE, layer1Data), layer1Palette) };
}

sections[bedrockSectionY] = new GeyserChunkSection(layers, bedrockSectionY);
sections[bedrockSectionY] = new GeyserChunkSection(layers);
extendedCollisionNextSection = thisExtendedCollisionNextSection;
}

Expand Down Expand Up @@ -432,7 +432,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
IntList palette = bedrockSection.getBlockStorageArray()[0].getPalette();
if (palette instanceof IntImmutableList || palette instanceof IntLists.Singleton) {
// TODO there has to be a better way to expand the palette .-.
bedrockSection = bedrockSection.copy(bedrockSectionY);
bedrockSection = bedrockSection.copy();
sections[bedrockSectionY] = bedrockSection;
}
bedrockSection.setFullBlock(x, y & 0xF, z, 0, blockDefinition.getRuntimeId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ChunkUtils {
static {
ByteBuf byteBuf = Unpooled.buffer();
try {
new GeyserChunkSection(new BlockStorage[0], 0)
new GeyserChunkSection(new BlockStorage[0])
.writeToNetwork(byteBuf);
SERIALIZED_CHUNK_DATA = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(SERIALIZED_CHUNK_DATA);
Expand Down

0 comments on commit 8d2ebcf

Please sign in to comment.