3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Fix item_name<->default name priority for items in 1.21->1.21.2 (#4208)

Dieser Commit ist enthalten in:
EnZaXD 2024-10-29 11:56:23 +01:00 committet von GitHub
Ursprung ee16d7af28
Commit 82ff0bae49
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -17,8 +17,11 @@
*/
package com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.data.MappingData;
@ -56,6 +59,7 @@ import com.viaversion.viaversion.util.TagUtil;
import com.viaversion.viaversion.util.Unit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -357,15 +361,48 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
@Override
public Item handleItemToClient(final UserConnection connection, final Item item) {
if (item.isEmpty()) {
return item;
}
super.handleItemToClient(connection, item);
updateItemData(item);
// Item name is now overridden by custom implemented display names (compass, player head, potion, shield, tipped arrow)
final int identifier = item.identifier();
if (identifier == 952 || identifier == 1147 || identifier == 1039 || identifier == 1203 || identifier == 1200 || identifier == 1204 || identifier == 1202) {
final StructuredDataContainer data = item.dataContainer();
final Tag itemName = data.get(StructuredDataKey.ITEM_NAME);
if (itemName != null && !data.has(StructuredDataKey.CUSTOM_NAME)) {
final CompoundTag name = new CompoundTag();
name.putBoolean("italic", false);
name.putString("text", "");
name.put("extra", new ListTag<>(Collections.singletonList(itemName)));
data.set(StructuredDataKey.CUSTOM_NAME, name);
saveTag(createCustomTag(item), new ByteTag(true), nbtTagName("custom_name"));
}
}
return item;
}
@Override
public Item handleItemToServer(final UserConnection connection, final Item item) {
if (item.isEmpty()) {
return item;
}
super.handleItemToServer(connection, item);
downgradeItemData(item);
final StructuredDataContainer dataContainer = item.dataContainer();
final CompoundTag customData = dataContainer.get(StructuredDataKey.CUSTOM_DATA);
if (customData != null && customData.remove(nbtTagName("custom_name")) != null) {
dataContainer.remove(StructuredDataKey.CUSTOM_NAME);
if (customData.isEmpty()) {
dataContainer.remove(StructuredDataKey.CUSTOM_DATA);
}
}
return item;
}