Skip to content

Commit 99618af

Browse files
committed
Fix enchantment table hints
1 parent ede8b87 commit 99618af

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.viaversion.nbt.tag.StringTag;
2424
import com.viaversion.nbt.tag.Tag;
2525
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
26+
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
2627
import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter;
2728
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
2829
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
@@ -51,11 +52,8 @@
5152
import java.util.List;
5253

5354
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.downgradeItemData;
54-
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData;
55-
5655
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.resetRarityValues;
57-
58-
import static com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter.ENCHANTMENT_LEVEL_TRANSLATION;
56+
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData;
5957

6058
public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_20_5, Protocol1_21To1_20_5> {
6159

@@ -82,10 +80,21 @@ public void registerPackets() {
8280
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
8381
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS, Types1_21.ITEM_COST, Types1_20_5.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST);
8482
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
85-
registerContainerSetData(ClientboundPackets1_21.CONTAINER_SET_DATA);
8683
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
8784
registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
8885

86+
protocol.registerClientbound(ClientboundPackets1_21.CONTAINER_SET_DATA, wrapper -> {
87+
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
88+
final short property = wrapper.passthrough(Types.SHORT);
89+
if (property >= 4 && property <= 6) { // Enchantment hints
90+
final short enchantmentId = wrapper.read(Types.SHORT);
91+
final EnchantmentsPaintingsStorage storage = wrapper.user().get(EnchantmentsPaintingsStorage.class);
92+
final String key = storage.enchantments().idToKey(enchantmentId);
93+
final int mappedId = key != null ? Enchantments1_20_5.keyToId(key) : -1;
94+
wrapper.write(Types.SHORT, (short) mappedId);
95+
}
96+
});
97+
8998
protocol.registerClientbound(ClientboundPackets1_21.HORSE_SCREEN_OPEN, wrapper -> {
9099
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
91100

@@ -149,7 +158,7 @@ public Item handleItemToClient(final UserConnection connection, final Item item)
149158

150159
final CompoundTag fullDescription = new CompoundTag();
151160
fullDescription.putString("translate", "%s %s");
152-
fullDescription.put("with", new ListTag<>(Arrays.asList(description, new StringTag(ENCHANTMENT_LEVEL_TRANSLATION.formatted(level)))));
161+
fullDescription.put("with", new ListTag<>(Arrays.asList(description, new StringTag(EnchantmentRewriter.ENCHANTMENT_LEVEL_TRANSLATION.formatted(level)))));
153162
return fullDescription;
154163
};
155164
enchantmentRewriter.rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, idRewriteFunction, descriptionSupplier, false);

0 commit comments

Comments
 (0)