diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java index 0916f90f..e18759c8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java @@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.BlockItemPack import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.ComponentRewriter1_21; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.EntityPacketRewriter1_21; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage; +import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.OpenScreenStorage; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.PlayerRotationStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Holder; @@ -76,7 +77,6 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol(this).register(ClientboundPackets1_21.AWARD_STATS); - translatableRewriter.registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT); @@ -187,6 +187,7 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol { + wrapper.passthrough(Types.VAR_INT); // Id + + // Tracking the type actually matters now with crafters also using container data above index 3 + final int menuType = wrapper.passthrough(Types.VAR_INT); + wrapper.user().get(OpenScreenStorage.class).setMenuType(menuType); + + protocol.getComponentRewriter().passthroughAndProcess(wrapper); + }); + protocol.registerClientbound(ClientboundPackets1_21.CONTAINER_SET_DATA, wrapper -> { wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id final short property = wrapper.passthrough(Types.SHORT); if (property >= 4 && property <= 6) { // Enchantment hints + final OpenScreenStorage openScreenStorage = wrapper.user().get(OpenScreenStorage.class); + if (openScreenStorage.menuType() != 13) { // Enchantment table + return; + } + final short enchantmentId = wrapper.read(Types.SHORT); final EnchantmentsPaintingsStorage storage = wrapper.user().get(EnchantmentsPaintingsStorage.class); final String key = storage.enchantments().idToKey(enchantmentId); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/storage/OpenScreenStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/storage/OpenScreenStorage.java new file mode 100644 index 00000000..895385da --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/storage/OpenScreenStorage.java @@ -0,0 +1,33 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; + +public final class OpenScreenStorage implements StorableObject { + + private int menuType = -1; + + public int menuType() { + return menuType; + } + + public void setMenuType(final int menuType) { + this.menuType = menuType; + } +}