Fix banner pattern backup

Fixes #3816
This commit is contained in:
Nassim Jahnke 2024-05-01 00:06:22 +02:00
parent 07bb0269c3
commit fa3c933b2f
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 28 additions and 21 deletions

View File

@ -627,24 +627,22 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final int useDuration = instrument.getInt("use_duration"); final int useDuration = instrument.getInt("use_duration");
final float range = instrument.getFloat("range"); final float range = instrument.getFloat("range");
Holder<SoundEvent> soundEvent; final Holder<SoundEvent> soundEvent;
final Tag soundEventTag = instrument.get("sound_event"); final CompoundTag soundEventTag = instrument.getCompoundTag("sound_event");
if (soundEventTag instanceof IntTag) { if (soundEventTag != null) {
soundEvent = Holder.of(((IntTag) soundEventTag).asInt()); final StringTag identifier = soundEventTag.getStringTag("identifier");
} else if (soundEventTag instanceof CompoundTag) {
final CompoundTag soundEventCompound = (CompoundTag) soundEventTag;
final StringTag identifier = soundEventCompound.getStringTag("identifier");
if (identifier == null) { if (identifier == null) {
return; return;
} }
soundEvent = Holder.of(new SoundEvent( soundEvent = Holder.of(new SoundEvent(
identifier.getValue(), identifier.getValue(),
soundEventCompound.contains("fixed_range") ? soundEventTag.contains("fixed_range") ? soundEventTag.getFloat("fixed_range") : null
soundEventCompound.getFloat("fixed_range") : null
)); ));
} else { } else {
return; soundEvent = Holder.of(instrument.getInt("sound_event"));
} }
data.set(StructuredDataKey.INSTRUMENT, Holder.of(new Instrument(soundEvent, useDuration, range))); data.set(StructuredDataKey.INSTRUMENT, Holder.of(new Instrument(soundEvent, useDuration, range)));
} }
@ -665,6 +663,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
if (potionEffectTag == null) { if (potionEffectTag == null) {
continue; continue;
} }
possibleEffects.add(new FoodEffect( possibleEffects.add(new FoodEffect(
new PotionEffect( new PotionEffect(
potionEffectTag.getInt("effect"), potionEffectTag.getInt("effect"),
@ -696,6 +695,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
if (blocks == null) { if (blocks == null) {
continue; continue;
} }
rules.add(new ToolRule( rules.add(new ToolRule(
blocks, blocks,
tag.contains("speed") ? tag.getFloat("speed") : null, tag.contains("speed") ? tag.getFloat("speed") : null,
@ -713,14 +713,17 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final List<BannerPatternLayer> patternLayer = new ArrayList<>(); final List<BannerPatternLayer> patternLayer = new ArrayList<>();
for (final CompoundTag tag : bannerPatterns) { for (final CompoundTag tag : bannerPatterns) {
final CompoundTag patternTag = tag.getCompoundTag("pattern"); final CompoundTag patternTag = tag.getCompoundTag("pattern");
if (patternTag == null) { final Holder<BannerPattern> pattern;
continue; if (patternTag != null) {
final String assetId = patternTag.getString("asset_id");
final String translationKey = patternTag.getString("translation_key");
pattern = Holder.of(new BannerPattern(assetId, translationKey));
} else {
pattern = Holder.of(tag.getInt("pattern"));
} }
final String assetId = patternTag.getString("asset_id");
final String translationKey = patternTag.getString("translation_key");
final int dyeColor = tag.getInt("dye_color"); final int dyeColor = tag.getInt("dye_color");
patternLayer.add(new BannerPatternLayer(Holder.of(new BannerPattern(assetId, translationKey)), dyeColor)); patternLayer.add(new BannerPatternLayer(pattern, dyeColor));
} }
data.set(StructuredDataKey.BANNER_PATTERNS, patternLayer.toArray(new BannerPatternLayer[0])); data.set(StructuredDataKey.BANNER_PATTERNS, patternLayer.toArray(new BannerPatternLayer[0]));
} }

View File

@ -61,7 +61,6 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEff
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimMaterials1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimMaterials1_20_3;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.UUIDUtil; import com.viaversion.viaversion.util.UUIDUtil;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -436,11 +435,16 @@ public final class StructuredDataConverter {
final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class);
for (final BannerPatternLayer layer : data) { for (final BannerPatternLayer layer : data) {
final CompoundTag layerTag = new CompoundTag(); final CompoundTag layerTag = new CompoundTag();
final CompoundTag patternTag = new CompoundTag(); if (layer.pattern().isDirect()) {
final BannerPattern pattern = layer.pattern().value(); final CompoundTag patternTag = new CompoundTag();
patternTag.putString("asset_id", pattern.assetId()); final BannerPattern pattern = layer.pattern().value();
patternTag.putString("translation_key", pattern.translationKey()); patternTag.putString("asset_id", pattern.assetId());
layerTag.put("pattern", patternTag); patternTag.putString("translation_key", pattern.translationKey());
layerTag.put("pattern", patternTag);
} else {
layerTag.putInt("pattern", layer.pattern().id());
}
layerTag.putInt("dye_color", layer.dyeColor()); layerTag.putInt("dye_color", layer.dyeColor());
originalPatterns.add(layerTag); originalPatterns.add(layerTag);
} }