mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-19 14:59:27 +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:
@@ -28,6 +28,7 @@ package org.geysermc.geyser.session.cache;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.level.chunk.GeyserChunk;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
@@ -81,21 +82,28 @@ public class ChunkCache {
|
||||
return;
|
||||
}
|
||||
|
||||
DataPalette palette = chunk.sections()[(y - minY) >> 4];
|
||||
if (palette == null) {
|
||||
if (block != Block.JAVA_AIR_ID) {
|
||||
// A previously empty chunk, which is no longer empty as a block has been added to it
|
||||
palette = DataPalette.createForChunk();
|
||||
// Fixes the chunk assuming that all blocks is the `block` variable we are updating. /shrug
|
||||
palette.getPalette().stateToId(Block.JAVA_AIR_ID);
|
||||
chunk.sections()[(y - minY) >> 4] = palette;
|
||||
} else {
|
||||
// Nothing to update
|
||||
return;
|
||||
boolean previouslyEmpty = false;
|
||||
try {
|
||||
DataPalette palette = chunk.sections()[(y - minY) >> 4];
|
||||
if (palette == null) {
|
||||
previouslyEmpty = true;
|
||||
if (block != Block.JAVA_AIR_ID) {
|
||||
// A previously empty chunk, which is no longer empty as a block has been added to it
|
||||
palette = DataPalette.createForChunk();
|
||||
// Fixes the chunk assuming that all blocks is the `block` variable we are updating. /shrug
|
||||
palette.getPalette().stateToId(Block.JAVA_AIR_ID);
|
||||
chunk.sections()[(y - minY) >> 4] = palette;
|
||||
} else {
|
||||
// Nothing to update
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -51,6 +51,8 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.Clie
|
||||
@Translator(packet = ClientboundAddEntityPacket.class)
|
||||
public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEntityPacket> {
|
||||
|
||||
private static final boolean SHOW_PLAYER_LIST_LOGS = Boolean.parseBoolean(System.getProperty("Geyser.ShowPlayerListLogs", "true"));
|
||||
|
||||
@Override
|
||||
public void translate(GeyserSession session, ClientboundAddEntityPacket packet) {
|
||||
EntityDefinition<?> definition = Registries.ENTITY_DEFINITIONS.get(packet.getType());
|
||||
@@ -76,7 +78,9 @@ public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEnti
|
||||
} else {
|
||||
entity = session.getEntityCache().getPlayerEntity(packet.getUuid());
|
||||
if (entity == null) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid()));
|
||||
if (SHOW_PLAYER_LIST_LOGS) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.entity.player.failed_list", packet.getUuid()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ import org.geysermc.geyser.text.GeyserLocale;
|
||||
@UtilityClass
|
||||
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 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
|
||||
// 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. :/ )
|
||||
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",
|
||||
String.valueOf(bedrockDimension.minY()),
|
||||
String.valueOf(bedrockDimension.maxY()),
|
||||
|
||||
Reference in New Issue
Block a user