From d5ccb179516ebf6311a504745c10bf496032cf06 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 20 May 2024 14:11:16 +0200 Subject: [PATCH] Add default firework flight length in 1.20.5->1.20.3 (#3866) --- .../rewriter/BlockItemPacketRewriter1_20_5.java | 7 +++++++ .../rewriter/StructuredDataConverter.java | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index c14ba1f21..ec312538a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -387,6 +387,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter structuredData : data.data().values()) { dataConverter.writeToTag(connection, structuredData, tag); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java index 3e0c2c3b0..27837639a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java @@ -234,14 +234,16 @@ public final class StructuredDataConverter { }); register(StructuredDataKey.FIREWORKS, (data, tag) -> { final CompoundTag fireworksTag = new CompoundTag(); - fireworksTag.putInt("Flight", data.flightDuration()); + fireworksTag.putByte("Flight", (byte) data.flightDuration()); tag.put("Fireworks", fireworksTag); - final ListTag explosionsTag = new ListTag<>(CompoundTag.class); - for (final FireworkExplosion explosion : data.explosions()) { - explosionsTag.add(convertExplosion(explosion)); + if (data.explosions().length > 0) { + final ListTag explosionsTag = new ListTag<>(CompoundTag.class); + for (final FireworkExplosion explosion : data.explosions()) { + explosionsTag.add(convertExplosion(explosion)); + } + fireworksTag.put("Explosions", explosionsTag); } - fireworksTag.put("Explosions", explosionsTag); }); register(StructuredDataKey.FIREWORK_EXPLOSION, (data, tag) -> tag.put("Explosion", convertExplosion(data))); register(StructuredDataKey.PROFILE, (data, tag) -> { @@ -871,6 +873,10 @@ public final class StructuredDataConverter { rewriters.put(key, c); } + public boolean backupInconvertibleData() { + return backupInconvertibleData; + } + @FunctionalInterface interface SimpleDataConverter {