Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Nov 22, 2024
1 parent cbb8f53 commit a040dc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ private void updateContainerIdServerbound(final PacketWrapper wrapper) {

@Override
public Item handleItemToClient(final UserConnection connection, final Item item) {
super.handleItemToClient(connection, item);
backupInconvertibleData(item);
super.handleItemToClient(connection, item);
downgradeItemData(item);
return item;
}
Expand All @@ -312,6 +312,8 @@ public Item handleItemToServer(final UserConnection connection, final Item item)
// Backup inconvertible data and later restore to prevent data loss for creative mode clients
private void backupInconvertibleData(final Item item) {
final StructuredDataContainer data = item.dataContainer();
data.setIdLookup(protocol, true);

final CompoundTag backupTag = new CompoundTag();

final Holder<Instrument1_21_2> instrument = data.get(StructuredDataKey.INSTRUMENT1_21_2);
Expand Down Expand Up @@ -389,10 +391,9 @@ private void backupInconvertibleData(final Item item) {
backupTag.put("death_protection", tag);
}

if (backupTag.isEmpty()) {
return;
if (!backupTag.isEmpty()) {
saveTag(createCustomTag(item), backupTag, "inconvertible_data");
}
saveTag(createCustomTag(item), backupTag, "inconvertible_data");
}

private void convertConsumableEffect(final CompoundTag tag, Consumable1_21_2.ConsumeEffect<?> effect) {
Expand Down Expand Up @@ -504,7 +505,7 @@ private void restoreInconvertibleData(final Item item) {

final Holder<Instrument1_21_2> instrument = data.get(StructuredDataKey.INSTRUMENT1_21_2);
if (instrument != null && instrument.isDirect()) {
final Tag description = backupTag.get(nbtTagName("instrument_description"));
final Tag description = backupTag.get("instrument_description");
if (description != null) {
final Instrument1_21_2 delegate = instrument.value();
data.set(StructuredDataKey.INSTRUMENT1_21_2, Holder.of(new Instrument1_21_2(delegate.soundEvent(), delegate.useDuration(), delegate.range(), description)));
Expand Down Expand Up @@ -532,7 +533,7 @@ private void restoreInconvertibleData(final Item item) {
data.set(StructuredDataKey.ITEM_MODEL, itemModel);
}

final CompoundTag equippable = backupTag.getCompoundTag("equitable");
final CompoundTag equippable = backupTag.getCompoundTag("equippable");
if (equippable != null) {
final int equipmentSlot = equippable.getInt("equipment_slot");
final Holder<SoundEvent> soundEvent = convertSoundEventHolder(equippable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public Item handleItemToClient(final UserConnection connection, final Item item)
final int identifier = item.identifier();

// Order is important
super.handleItemToClient(connection, item);
backupInconvertibleData(item);
super.handleItemToClient(connection, item);
downgradeItemData(item);

if (data.has(StructuredDataKey.RARITY)) {
Expand Down Expand Up @@ -272,6 +272,8 @@ private void rewriteEnchantmentToServer(final EnchantmentsPaintingsStorage stora

private void backupInconvertibleData(final Item item) {
final StructuredDataContainer data = item.dataContainer();
data.setIdLookup(protocol, true);

final JukeboxPlayable jukeboxPlayable = data.get(StructuredDataKey.JUKEBOX_PLAYABLE);
if (jukeboxPlayable == null) {
return;
Expand All @@ -295,6 +297,7 @@ private void backupInconvertibleData(final Item item) {
tag.putString("song_identifier", jukeboxPlayable.song().right());
}
tag.putBoolean("show_in_tooltip", jukeboxPlayable.showInTooltip());

saveTag(createCustomTag(item), tag, "jukebox_playable");
}

Expand Down

0 comments on commit a040dc7

Please sign in to comment.