|
45 | 45 | import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; |
46 | 46 | import com.viaversion.viaversion.api.minecraft.item.Item; |
47 | 47 | import com.viaversion.viaversion.api.minecraft.item.StructuredItem; |
| 48 | +import com.viaversion.viaversion.api.minecraft.item.data.DamageResistant1_21_2; |
48 | 49 | import com.viaversion.viaversion.api.minecraft.item.data.DeathProtection; |
49 | 50 | import com.viaversion.viaversion.api.minecraft.item.data.Enchantable; |
50 | 51 | import com.viaversion.viaversion.api.minecraft.item.data.Enchantments; |
51 | 52 | import com.viaversion.viaversion.api.minecraft.item.data.Equippable; |
52 | 53 | import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties1_20_5; |
53 | 54 | import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2; |
54 | 55 | import com.viaversion.viaversion.api.minecraft.item.data.ItemModel; |
| 56 | +import com.viaversion.viaversion.api.minecraft.item.data.PotionContents; |
55 | 57 | import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect; |
56 | 58 | import com.viaversion.viaversion.api.minecraft.item.data.PotionEffectData; |
57 | 59 | import com.viaversion.viaversion.api.minecraft.item.data.Repairable; |
58 | 60 | import com.viaversion.viaversion.api.minecraft.item.data.UseCooldown; |
59 | 61 | import com.viaversion.viaversion.api.minecraft.item.data.consumable.ApplyStatusEffects; |
| 62 | +import com.viaversion.viaversion.api.minecraft.item.data.consumable.Consumable1_21_2; |
60 | 63 | import com.viaversion.viaversion.api.minecraft.item.data.consumable.ConsumeEffect; |
61 | 64 | import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; |
62 | 65 | import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; |
@@ -570,6 +573,34 @@ private void backupInconvertibleData(final Item item) { |
570 | 573 | backupTag.put("death_protection", tag); |
571 | 574 | } |
572 | 575 |
|
| 576 | + final Consumable1_21_2 consumable = data.get(StructuredDataKey.CONSUMABLE1_21_2); |
| 577 | + if (consumable != null) { |
| 578 | + final CompoundTag tag = new CompoundTag(); |
| 579 | + tag.putFloat("consume_seconds", consumable.consumeSeconds()); |
| 580 | + tag.putInt("animation", consumable.animationType()); |
| 581 | + saveSoundEventHolder(tag, consumable.sound()); |
| 582 | + tag.putBoolean("has_consume_particles", consumable.hasConsumeParticles()); |
| 583 | + |
| 584 | + final ListTag<CompoundTag> effects = new ListTag<>(CompoundTag.class); |
| 585 | + for (final ConsumeEffect<?> effect : consumable.consumeEffects()) { |
| 586 | + final CompoundTag effectTag = new CompoundTag(); |
| 587 | + convertConsumableEffect(effectTag, effect); |
| 588 | + effects.add(effectTag); |
| 589 | + } |
| 590 | + tag.put("consume_effects", effects); |
| 591 | + backupTag.put("consumable", tag); |
| 592 | + } |
| 593 | + |
| 594 | + final DamageResistant1_21_2 damageResistant = data.get(StructuredDataKey.DAMAGE_RESISTANT1_21_2); |
| 595 | + if (damageResistant != null) { |
| 596 | + backupTag.putString("damage_resistant", damageResistant.typesTagKey().original()); |
| 597 | + } |
| 598 | + |
| 599 | + final PotionContents potionContents = data.get(StructuredDataKey.POTION_CONTENTS1_21_2); |
| 600 | + if (potionContents != null && potionContents.customName() != null) { |
| 601 | + backupTag.putString("potion_custom_name", potionContents.customName()); |
| 602 | + } |
| 603 | + |
573 | 604 | if (!backupTag.isEmpty()) { |
574 | 605 | saveTag(createCustomTag(item), backupTag, "inconvertible_data"); |
575 | 606 | } |
@@ -730,6 +761,34 @@ private void restoreInconvertibleData(final Item item) { |
730 | 761 | data.set(StructuredDataKey.DEATH_PROTECTION1_21_2, new DeathProtection(effects.toArray(ConsumeEffect[]::new))); |
731 | 762 | } |
732 | 763 |
|
| 764 | + final CompoundTag consumable = backupTag.getCompoundTag("consumable"); |
| 765 | + if (consumable != null) { |
| 766 | + final List<ConsumeEffect<?>> effects = new ArrayList<>(); |
| 767 | + for (final CompoundTag effectTag : consumable.getListTag("consume_effects", CompoundTag.class)) { |
| 768 | + final ConsumeEffect<?> effect = convertConsumableEffect(effectTag); |
| 769 | + if (effect != null) { |
| 770 | + effects.add(effect); |
| 771 | + } |
| 772 | + } |
| 773 | + data.set(StructuredDataKey.CONSUMABLE1_21_2, new Consumable1_21_2( |
| 774 | + consumable.getFloat("consume_seconds"), |
| 775 | + consumable.getInt("animation"), |
| 776 | + restoreSoundEventHolder(consumable), |
| 777 | + consumable.getBoolean("has_consume_particles"), |
| 778 | + effects.toArray(ConsumeEffect[]::new) |
| 779 | + )); |
| 780 | + } |
| 781 | + |
| 782 | + final String damageResistant = backupTag.getString("damage_resistant"); |
| 783 | + if (damageResistant != null) { |
| 784 | + data.set(StructuredDataKey.DAMAGE_RESISTANT1_21_2, new DamageResistant1_21_2(Key.of(damageResistant))); |
| 785 | + } |
| 786 | + |
| 787 | + final String potionCustomName = backupTag.getString("potion_custom_name"); |
| 788 | + if (potionCustomName != null) { |
| 789 | + data.replace(StructuredDataKey.POTION_CONTENTS1_21_2, potionContents -> new PotionContents(potionContents.potion(), potionContents.customColor(), potionContents.customEffects(), potionCustomName)); |
| 790 | + } |
| 791 | + |
733 | 792 | removeCustomTag(data, customData); |
734 | 793 | } |
735 | 794 | } |
0 commit comments