1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-20 07:19:29 +00:00

Catch block caching exceptions (#5771)

* Catch block caching exceptions, add ShowPlayerListLogs / ShowChunkHeightWarningLogs system properties to disable warnings

* Update ChunkCache.java
This commit is contained in:
chris
2025-08-21 01:27:26 +03:00
committed by GitHub
parent 35210be891
commit 92a8b01f5c
3 changed files with 29 additions and 15 deletions

View File

@@ -28,6 +28,7 @@ package org.geysermc.geyser.session.cache;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import lombok.Setter; import lombok.Setter;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.level.block.type.Block; import org.geysermc.geyser.level.block.type.Block;
import org.geysermc.geyser.level.chunk.GeyserChunk; import org.geysermc.geyser.level.chunk.GeyserChunk;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
@@ -81,8 +82,11 @@ public class ChunkCache {
return; return;
} }
boolean previouslyEmpty = false;
try {
DataPalette palette = chunk.sections()[(y - minY) >> 4]; DataPalette palette = chunk.sections()[(y - minY) >> 4];
if (palette == null) { if (palette == null) {
previouslyEmpty = true;
if (block != Block.JAVA_AIR_ID) { if (block != Block.JAVA_AIR_ID) {
// A previously empty chunk, which is no longer empty as a block has been added to it // A previously empty chunk, which is no longer empty as a block has been added to it
palette = DataPalette.createForChunk(); palette = DataPalette.createForChunk();
@@ -96,6 +100,10 @@ public class ChunkCache {
} }
palette.set(x & 0xF, y & 0xF, z & 0xF, block); palette.set(x & 0xF, y & 0xF, z & 0xF, block);
} catch (Throwable e) {
GeyserImpl.getInstance().getLogger().error("Failed to update block in chunk cache! ", e);
GeyserImpl.getInstance().getLogger().error("Info: newChunk=%s, block=%s, pos=%s,%s,%s", previouslyEmpty, block, x, y, z);
}
} }
public int getBlockAt(int x, int y, int z) { public int getBlockAt(int x, int y, int z) {

View File

@@ -51,6 +51,8 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.Clie
@Translator(packet = ClientboundAddEntityPacket.class) @Translator(packet = ClientboundAddEntityPacket.class)
public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEntityPacket> { public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEntityPacket> {
private static final boolean SHOW_PLAYER_LIST_LOGS = Boolean.parseBoolean(System.getProperty("Geyser.ShowPlayerListLogs", "true"));
@Override @Override
public void translate(GeyserSession session, ClientboundAddEntityPacket packet) { public void translate(GeyserSession session, ClientboundAddEntityPacket packet) {
EntityDefinition<?> definition = Registries.ENTITY_DEFINITIONS.get(packet.getType()); EntityDefinition<?> definition = Registries.ENTITY_DEFINITIONS.get(packet.getType());
@@ -76,7 +78,9 @@ public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEnti
} else { } else {
entity = session.getEntityCache().getPlayerEntity(packet.getUuid()); entity = session.getEntityCache().getPlayerEntity(packet.getUuid());
if (entity == null) { if (entity == null) {
if (SHOW_PLAYER_LIST_LOGS) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid())); GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid()));
}
return; return;
} }

View File

@@ -51,6 +51,8 @@ import org.geysermc.geyser.text.GeyserLocale;
@UtilityClass @UtilityClass
public class ChunkUtils { public class ChunkUtils {
private static final boolean SHOW_CHUNK_HEIGHT_WARNING_LOGS = Boolean.parseBoolean(System.getProperty("Geyser.ShowChunkHeightWarningLogs", "true"));
public static final byte[] EMPTY_BIOME_DATA; public static final byte[] EMPTY_BIOME_DATA;
public static final BlockStorage[] EMPTY_BLOCK_STORAGE; public static final BlockStorage[] EMPTY_BLOCK_STORAGE;
@@ -220,7 +222,7 @@ public class ChunkUtils {
// Yell in the console if the world height is too height in the current scenario // Yell in the console if the world height is too height in the current scenario
// The constraints change depending on if the player is in the overworld or not, and if experimental height is enabled // The constraints change depending on if the player is in the overworld or not, and if experimental height is enabled
// (Ignore this for the Nether. We can't change that at the moment without the workaround. :/ ) // (Ignore this for the Nether. We can't change that at the moment without the workaround. :/ )
if (minY < bedrockDimension.minY() || (bedrockDimension.doUpperHeightWarn() && maxY > bedrockDimension.maxY())) { if (SHOW_CHUNK_HEIGHT_WARNING_LOGS && (minY < bedrockDimension.minY() || (bedrockDimension.doUpperHeightWarn() && maxY > bedrockDimension.maxY()))) {
session.getGeyser().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.translator.chunk.out_of_bounds", session.getGeyser().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.translator.chunk.out_of_bounds",
String.valueOf(bedrockDimension.minY()), String.valueOf(bedrockDimension.minY()),
String.valueOf(bedrockDimension.maxY()), String.valueOf(bedrockDimension.maxY()),