3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-16 04:50:08 +01:00

Handle rarity changes in trident/banner pattern item in 1.20.5->1.21 (#4001)

Dieser Commit ist enthalten in:
EnZaXD 2024-07-07 17:39:30 +02:00 committet von GitHub
Ursprung 303d9ecf51
Commit 365040f59d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -17,7 +17,10 @@
*/ */
package com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter; package com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
@ -114,6 +117,17 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
super.handleItemToClient(connection, item); super.handleItemToClient(connection, item);
updateItemData(item); updateItemData(item);
final StructuredDataContainer dataContainer = item.dataContainer();
if (dataContainer.contains(StructuredDataKey.RARITY)) {
return item;
}
// Change rarity of trident and piglin banner pattern
if (item.identifier() == 1188 || item.identifier() == 1200) {
dataContainer.set(StructuredDataKey.RARITY, 0); // Common
saveTag(createCustomTag(item), new ByteTag(true), "rarity");
}
return item; return item;
} }
@ -141,6 +155,7 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
super.handleItemToServer(connection, item); super.handleItemToServer(connection, item);
downgradeItemData(item); downgradeItemData(item);
resetRarityValues(item, nbtTagName("rarity"));
return item; return item;
} }
@ -167,6 +182,21 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
}); });
} }
public static void resetRarityValues(final Item item, final String tagName) {
final StructuredDataContainer dataContainer = item.dataContainer();
final StructuredData<CompoundTag> customData = dataContainer.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
if (customData == null) {
return;
}
if (customData.value().remove(tagName) != null) {
dataContainer.remove(StructuredDataKey.RARITY);
if (customData.value().isEmpty()) {
dataContainer.remove(StructuredDataKey.CUSTOM_DATA);
}
}
}
private int itemToJubeboxSong(final int id) { private int itemToJubeboxSong(final int id) {
String identifier = Protocol1_20_5To1_21.MAPPINGS.getFullItemMappings().identifier(id); String identifier = Protocol1_20_5To1_21.MAPPINGS.getFullItemMappings().identifier(id);
if (!identifier.contains("music_disc_")) { if (!identifier.contains("music_disc_")) {