Fix firework rewriting in 1.20.3->.5 (#3860)

Makes the explosion tag optional like it is in 1.20.4 so the tooltip shows the correct duration when crafting a firework, also fixes the type used for Flight which is byte in 1.20.4
This commit is contained in:
EnZaXD 2024-05-19 09:29:05 +02:00 committed by GitHub
parent f92d241028
commit 7d9c6fea69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -499,10 +499,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final CompoundTag fireworksTag = tag.getCompoundTag("Fireworks");
if (fireworksTag != null) {
final ListTag<CompoundTag> explosionsTag = fireworksTag.getListTag("Explosions", CompoundTag.class);
if (explosionsTag != null) {
updateFireworks(data, fireworksTag, explosionsTag);
}
}
if (old.identifier() == 1085) {
updateWritableBookPages(data, tag);
@ -1022,10 +1020,11 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
private void updateFireworks(final StructuredDataContainer data, final CompoundTag fireworksTag, final ListTag<CompoundTag> explosionsTag) {
final int flightDuration = fireworksTag.getInt("Flight");
final int flightDuration = fireworksTag.getByte("Flight");
final Fireworks fireworks = new Fireworks(
flightDuration,
explosionsTag.stream().limit(256).map(this::readExplosion).toArray(FireworkExplosion[]::new)
explosionsTag != null ? explosionsTag.stream().limit(256).
map(this::readExplosion).toArray(FireworkExplosion[]::new) : new FireworkExplosion[0]
);
data.set(StructuredDataKey.FIREWORKS, fireworks);
}