From 5ceb4145ac281ab02a20f45b263bedb818b3ca82 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 11 Jul 2020 19:40:26 -0500 Subject: [PATCH] Fix fireworks (Closes #917) --- .../java/org/geysermc/connector/entity/FireworkEntity.java | 4 +++- .../translators/item/translators/nbt/FireworkTranslator.java | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java index cf49dc5f..3e1d05f4 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java @@ -116,7 +116,9 @@ public class FireworkEntity extends Entity { fireworksBuilder.putList("Explosions", NbtType.COMPOUND, explosions); - metadata.put(EntityData.DISPLAY_ITEM, NbtMap.builder().put("Fireworks", fireworksBuilder.build())); + NbtMapBuilder builder = NbtMap.builder(); + builder.put("Fireworks", fireworksBuilder.build()); + metadata.put(EntityData.DISPLAY_ITEM, builder.build()); } else if (entityMetadata.getId() == 8 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) { //Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too. PlayerEntity entity = session.getPlayerEntity(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java index 5b5182a5..0e23169f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/FireworkTranslator.java @@ -98,8 +98,11 @@ public class FireworkTranslator extends NbtItemStackTranslator { @Override public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) { + if (!itemTag.contains("Fireworks")) { + return; + } CompoundTag fireworks = itemTag.get("Fireworks"); - if (fireworks.get("Flight") != null) { + if (fireworks.contains("Flight")) { fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue()))); }