Actually track inventory state id

This commit is contained in:
Nassim Jahnke 2024-08-21 19:07:14 +02:00
parent 681e8a2f07
commit ff94019b08
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 11 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -108,6 +109,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPac
@Override
public void init(final UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
user.put(new InventoryStateIdStorage());
}
@Override

View File

@ -91,8 +91,11 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> {
updateContainerId(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id
Item[] items = wrapper.read(itemArrayType());
final int stateId = wrapper.passthrough(Types.VAR_INT);
wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId);
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(mappedItemArrayType(), items);
for (int i = 0; i < items.length; i++) {
items[i] = handleItemToClient(wrapper.user(), items[i]);
@ -101,7 +104,10 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, wrapper -> {
updateContainerId(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id
final int stateId = wrapper.passthrough(Types.VAR_INT);
wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId);
wrapper.passthrough(Types.SHORT); // Slot id
passthroughClientboundItem(wrapper);
});