From 66d578eadc08d8727417e77713fca3ca066ff5a0 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 19 Nov 2021 19:11:36 -0500 Subject: [PATCH] Implement proper biome palette reading probably With thanks to @kennytv for the magic required to get global palette bits. --- .../org/geysermc/connector/entity/EntityDefinitions.java | 5 +++++ .../geysermc/connector/network/session/GeyserSession.java | 5 +++++ .../java/level/JavaLevelChunkWithLightTranslator.java | 5 +++-- .../network/translators/world/BiomeTranslator.java | 2 ++ .../registry/loader/ParticleTypesRegistryLoader.java | 8 +++++++- .../main/java/org/geysermc/connector/utils/MathUtils.java | 7 +++++++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java index be51687c0..677ec1d3b 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java +++ b/connector/src/main/java/org/geysermc/connector/entity/EntityDefinitions.java @@ -695,6 +695,7 @@ public final class EntityDefinitions { .type(EntityType.WITCH) .height(1.8f).width(0.6f) .offset(1.62f) + .addTranslator(null) // Using item .build(); } @@ -792,8 +793,12 @@ public final class EntityDefinitions { TURTLE = EntityDefinition.inherited(TurtleEntity::new, ageableEntityBase) .type(EntityType.TURTLE) .height(0.4f).width(1.2f) + .addTranslator(null) // Home position .addTranslator(MetadataType.BOOLEAN, TurtleEntity::setPregnant) .addTranslator(MetadataType.BOOLEAN, TurtleEntity::setLayingEgg) + .addTranslator(null) // Travel position + .addTranslator(null) // Going home + .addTranslator(null) // Travelling .build(); EntityDefinition abstractVillagerEntityBase = EntityDefinition.inherited(AbstractMerchantEntity::new, ageableEntityBase) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 72dcf3710..339509d6b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -204,6 +204,11 @@ public class GeyserSession implements CommandSender { private final Map skullCache = new Object2ObjectOpenHashMap<>(); private final Long2ObjectMap storedMaps = new Long2ObjectOpenHashMap<>(); + /** + * Required to decode biomes correctly. + */ + @Setter + private int biomeGlobalPalette; /** * Stores the map between Java and Bedrock biome network IDs. */ diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/level/JavaLevelChunkWithLightTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/level/JavaLevelChunkWithLightTranslator.java index 6a4add70c..9fd862dfe 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/level/JavaLevelChunkWithLightTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/level/JavaLevelChunkWithLightTranslator.java @@ -85,6 +85,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator bedrockOnlyBlockEntities = new ArrayList<>(); @@ -105,7 +106,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator entry = particlesIterator.next(); + String key = entry.getKey().toUpperCase(Locale.ROOT); JsonNode bedrockId = entry.getValue().get("bedrockId"); JsonNode eventType = entry.getValue().get("eventType"); - particles.put(ParticleType.valueOf(entry.getKey().toUpperCase(Locale.ROOT)), new ParticleMapping( + if (eventType == null && bedrockId == null) { + GeyserConnector.getInstance().getLogger().debug("Skipping particle mapping " + key + " because no Bedrock equivalent exists."); + continue; + } + particles.put(ParticleType.valueOf(key), new ParticleMapping( eventType == null ? null : LevelEventType.valueOf(eventType.asText().toUpperCase(Locale.ROOT)), bedrockId == null ? null : bedrockId.asText()) ); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MathUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MathUtils.java index 927f72202..3ccf812d3 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MathUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MathUtils.java @@ -105,4 +105,11 @@ public class MathUtils { public static long chunkPositionToLong(int x, int z) { 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); + } }