From 40d1e3909301cbf9898fe2cbd45f24b3210f9b77 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 28 May 2021 16:35:54 -0400 Subject: [PATCH] Fix area effect cloud particle type for 1.16.220 (#2226) This commit stops hardcoded particle IDs from being used and instead uses the internal IDs per-version. --- connector/pom.xml | 2 +- .../entity/AreaEffectCloudEntity.java | 2 +- .../translators/effect/EffectRegistry.java | 24 +++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 9feb717b9..ba0f0cc39 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -32,7 +32,7 @@ com.github.CloudburstMC.Protocol bedrock-v431 - 9947665 + 530a0e3 compile diff --git a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java index 6f3d0204f..2e450343e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/AreaEffectCloudEntity.java @@ -59,7 +59,7 @@ public class AreaEffectCloudEntity extends Entity { metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue()); } else if (entityMetadata.getId() == 10) { Particle particle = (Particle) entityMetadata.getValue(); - int particleId = EffectRegistry.getParticleId(particle.getType()); + int particleId = EffectRegistry.getParticleId(session, particle.getType()); if (particleId != -1) { metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java index c71aa4f1d..f767b5827 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java @@ -32,10 +32,9 @@ import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.SoundEvent; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import lombok.NonNull; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.FileUtils; import java.io.InputStream; @@ -51,11 +50,6 @@ public class EffectRegistry { public static final Map SOUND_EFFECTS = new HashMap<>(); public static final Int2ObjectMap RECORDS = new Int2ObjectOpenHashMap<>(); - /** - * Java particle type to Bedrock particle ID - * Used for area effect clouds. - */ - private static final Object2IntMap PARTICLE_TO_ID = new Object2IntOpenHashMap<>(); /** * Java particle type to Bedrock level event */ @@ -84,11 +78,7 @@ public class EffectRegistry { while (particlesIterator.hasNext()) { Map.Entry entry = particlesIterator.next(); JsonNode bedrockId = entry.getValue().get("bedrockId"); - JsonNode bedrockIdNumeric = entry.getValue().get("bedrockNumericId"); JsonNode eventType = entry.getValue().get("eventType"); - if (bedrockIdNumeric != null) { - PARTICLE_TO_ID.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockIdNumeric.asInt()); - } if (bedrockId != null) { PARTICLE_TO_STRING.put(ParticleType.valueOf(entry.getKey().toUpperCase()), bedrockId.asText()); } @@ -164,11 +154,19 @@ public class EffectRegistry { } /** + * Used for area effect clouds. + * * @param type the Java particle to search for * @return the Bedrock integer ID of the particle, or -1 if it does not exist */ - public static int getParticleId(@NonNull ParticleType type) { - return PARTICLE_TO_ID.getOrDefault(type, -1); + public static int getParticleId(GeyserSession session, @NonNull ParticleType type) { + LevelEventType levelEventType = getParticleLevelEventType(type); + if (levelEventType == null) { + return -1; + } + + // Remove the legacy bit applied to particles for LevelEventType serialization + return session.getUpstream().getSession().getPacketCodec().getHelper().getLevelEventId(levelEventType) & ~0x4000; } /**