Skip to content

Commit

Permalink
Add default firework flight length in 1.20.5->1.20.3 (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed May 20, 2024
1 parent 47f5617 commit d5ccb17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ public Item toOldItem(final UserConnection connection, final Item item, final St
return dataItem;
}

if (dataConverter.backupInconvertibleData()) {
// In 1.20.6, some items have default values which are not written into the components
if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) {
data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0]));
}
}

for (final StructuredData<?> structuredData : data.data().values()) {
dataConverter.writeToTag(connection, structuredData, tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,16 @@ public StructuredDataConverter(final boolean backupInconvertibleData) {
});
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<CompoundTag> explosionsTag = new ListTag<>(CompoundTag.class);
for (final FireworkExplosion explosion : data.explosions()) {
explosionsTag.add(convertExplosion(explosion));
if (data.explosions().length > 0) {
final ListTag<CompoundTag> 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) -> {
Expand Down Expand Up @@ -871,6 +873,10 @@ private <T> void register(final StructuredDataKey<T> key, final SimpleDataConver
rewriters.put(key, c);
}

public boolean backupInconvertibleData() {
return backupInconvertibleData;
}

@FunctionalInterface
interface SimpleDataConverter<T> {

Expand Down

0 comments on commit d5ccb17

Please sign in to comment.