From e0ec308fa087e316136c53c3e33032d8c376583d Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Mon, 8 Jul 2024 12:34:37 +0200 Subject: [PATCH] Handle rarity changes in trident/banner pattern item in 1.21->1.20.5 (#813) --- .../rewriter/BlockItemPacketRewriter1_21.java | 19 ++++++++++++++++++- gradle/libs.versions.toml | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index 502c6787..cd88e9fa 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -17,12 +17,12 @@ */ package com.viaversion.viabackwards.protocol.v1_21to1_20_5.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.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; -import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage; @@ -53,6 +53,8 @@ import java.util.List; import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.downgradeItemData; import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData; +import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.resetRarityValues; + import static com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter.ENCHANTMENT_LEVEL_TRANSLATION; public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRewriter { @@ -153,9 +155,23 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe enchantmentRewriter.rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, idRewriteFunction, descriptionSupplier, false); enchantmentRewriter.rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, idRewriteFunction, descriptionSupplier, true); + final int identifier = item.identifier(); + // Order is important super.handleItemToClient(connection, item); downgradeItemData(item); + + final StructuredDataContainer dataContainer = item.dataContainer(); + if (dataContainer.contains(StructuredDataKey.RARITY)) { + return item; + } + + // Change rarity of trident and piglin banner pattern + final boolean trident = identifier == 1188; + if (trident || identifier == 1200) { + dataContainer.set(StructuredDataKey.RARITY, trident ? 3 : 1); // Epic or Uncommon + saveTag(createCustomTag(item), new ByteTag(true), "rarity"); + } return item; } @@ -179,6 +195,7 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe // Order is important super.handleItemToServer(connection, item); updateItemData(item); + resetRarityValues(item, nbtTagName("rarity")); return item; } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 561d4c90..a46e272e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "5.0.1-SNAPSHOT" +viaver = "5.0.2-SNAPSHOT" # Common provided netty = "4.0.20.Final"