remove global palette bits, fix nullable block entity tags

This commit is contained in:
onebeastchris 2024-04-21 22:54:54 +02:00 committed by Camotoy
parent 57ce5706ee
commit b73f23de0f
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
4 changed files with 4 additions and 20 deletions

View File

@ -263,11 +263,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter @Setter
private ItemMappings itemMappings; private ItemMappings itemMappings;
/**
* Required to decode biomes correctly.
*/
@Setter
private int biomeGlobalPalette;
/** /**
* Stores the map between Java and Bedrock biome network IDs. * Stores the map between Java and Bedrock biome network IDs.
*/ */

View File

@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.chunk.DataPalette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.GlobalPalette; import com.github.steveice10.mc.protocol.data.game.chunk.palette.GlobalPalette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette; import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette;
import com.github.steveice10.mc.protocol.data.game.chunk.palette.SingletonPalette; import com.github.steveice10.mc.protocol.data.game.chunk.palette.SingletonPalette;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import org.geysermc.geyser.level.chunk.BlockStorage; import org.geysermc.geyser.level.chunk.BlockStorage;
import org.geysermc.geyser.level.chunk.bitarray.BitArray; import org.geysermc.geyser.level.chunk.bitarray.BitArray;
@ -39,7 +38,6 @@ import org.geysermc.geyser.level.chunk.bitarray.BitArrayVersion;
import org.geysermc.geyser.level.chunk.bitarray.SingletonBitArray; import org.geysermc.geyser.level.chunk.bitarray.SingletonBitArray;
import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.MathUtils;
import java.util.List; import java.util.List;
@ -49,8 +47,6 @@ public class BiomeTranslator {
public static void loadServerBiomes(GeyserSession session, List<RegistryEntry> entries) { public static void loadServerBiomes(GeyserSession session, List<RegistryEntry> entries) {
Int2IntMap biomeTranslations = new Int2IntOpenHashMap(); Int2IntMap biomeTranslations = new Int2IntOpenHashMap();
session.setBiomeGlobalPalette(MathUtils.getGlobalPaletteForSize(entries.size()));
int greatestBiomeId = 0; int greatestBiomeId = 0;
for (int i = 0; i < entries.size(); i++) { for (int i = 0; i < entries.size(); i++) {
RegistryEntry entry = entries.get(i); RegistryEntry entry = entries.get(i);

View File

@ -98,7 +98,6 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
// Ensure that, if the player is using lower world heights, the position is not offset // Ensure that, if the player is using lower world heights, the position is not offset
int yOffset = session.getChunkCache().getChunkMinY(); int yOffset = session.getChunkCache().getChunkMinY();
int chunkSize = session.getChunkCache().getChunkHeightY(); int chunkSize = session.getChunkCache().getChunkHeightY();
int biomeGlobalPalette = session.getBiomeGlobalPalette();
DataPalette[] javaChunks = new DataPalette[chunkSize]; DataPalette[] javaChunks = new DataPalette[chunkSize];
DataPalette[] javaBiomes = new DataPalette[chunkSize]; DataPalette[] javaBiomes = new DataPalette[chunkSize];
@ -122,7 +121,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData()); ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData());
boolean extendedCollisionNextSection = false; boolean extendedCollisionNextSection = false;
for (int sectionY = 0; sectionY < chunkSize; sectionY++) { for (int sectionY = 0; sectionY < chunkSize; sectionY++) {
ChunkSection javaSection = session.getDownstream().getCodecHelper().readChunkSection(in, biomeGlobalPalette); ChunkSection javaSection = session.getDownstream().getCodecHelper().readChunkSection(in);
javaChunks[sectionY] = javaSection.getChunkData(); javaChunks[sectionY] = javaSection.getChunkData();
javaBiomes[sectionY] = javaSection.getBiomeData(); javaBiomes[sectionY] = javaSection.getBiomeData();
boolean extendedCollision = extendedCollisionNextSection; boolean extendedCollision = extendedCollisionNextSection;
@ -393,12 +392,13 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
final int chunkBlockZ = packet.getZ() << 4; final int chunkBlockZ = packet.getZ() << 4;
for (BlockEntityInfo blockEntity : blockEntities) { for (BlockEntityInfo blockEntity : blockEntities) {
BlockEntityType type = blockEntity.getType(); BlockEntityType type = blockEntity.getType();
if (type == null) { CompoundTag tag = blockEntity.getNbt();
if (type == null || tag == null) {
// As an example: ViaVersion will send -1 if it cannot find the block entity type // As an example: ViaVersion will send -1 if it cannot find the block entity type
// Vanilla Minecraft gracefully handles this // Vanilla Minecraft gracefully handles this
// Since 1.20.5: tags sent here can be null, at which point the block entity is not translated
continue; continue;
} }
CompoundTag tag = blockEntity.getNbt();
int x = blockEntity.getX(); // Relative to chunk int x = blockEntity.getX(); // Relative to chunk
int y = blockEntity.getY(); int y = blockEntity.getY();
int z = blockEntity.getZ(); // Relative to chunk int z = blockEntity.getZ(); // Relative to chunk

View File

@ -189,11 +189,4 @@ public class MathUtils {
public static long chunkPositionToLong(int x, int z) { public static long chunkPositionToLong(int x, int z) {
return ((x & 0xFFFFFFFFL) << 32L) | (z & 0xFFFFFFFFL); return ((x & 0xFFFFFFFFL) << 32L) | (z & 0xFFFFFFFFL);
} }
/**
* @return the bits per entry used when this number is the maximum amount of entries.
*/
public static int getGlobalPaletteForSize(int size) {
return 32 - Integer.numberOfLeadingZeros(size - 1);
}
} }