Improve InventoryTracker16 Code (#3302)

This commit is contained in:
EnZaXD 2023-04-22 08:57:47 +02:00 committed by GitHub
parent 54d8e29a7e
commit a2e214ae18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

View File

@ -277,7 +277,7 @@ public class EntityPackets {
protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, wrapper -> { protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
// Don't send an arm swing if the player has an inventory opened. // Don't send an arm swing if the player has an inventory opened.
if (inventoryTracker.getInventory() != -1) { if (inventoryTracker.isInventoryOpen()) {
wrapper.cancel(); wrapper.cancel();
} }
}); });

View File

@ -67,12 +67,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
handler(cursorRemapper); handler(cursorRemapper);
handler(wrapper -> { handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
int windowId = wrapper.get(Type.VAR_INT, 0);
int windowType = wrapper.get(Type.VAR_INT, 1); int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType >= 20) { // smithing added with id 20 if (windowType >= 20) { // smithing added with id 20
wrapper.set(Type.VAR_INT, 1, ++windowType); wrapper.set(Type.VAR_INT, 1, ++windowType);
} }
inventoryTracker.setInventory((short) windowId); inventoryTracker.setInventoryOpen(true);
}); });
} }
}); });
@ -83,7 +82,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
handler(cursorRemapper); handler(cursorRemapper);
handler(wrapper -> { handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1); inventoryTracker.setInventoryOpen(false);
}); });
} }
}); });
@ -133,7 +132,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, wrapper -> { protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1); inventoryTracker.setInventoryOpen(false);
}); });
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));

View File

@ -20,13 +20,13 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
public class InventoryTracker1_16 implements StorableObject { public class InventoryTracker1_16 implements StorableObject {
private short inventory = -1; private boolean inventoryOpen = false;
public short getInventory() { public boolean isInventoryOpen() {
return this.inventory; return inventoryOpen;
} }
public void setInventory(short inventory) { public void setInventoryOpen(boolean inventoryOpen) {
this.inventory = inventory; this.inventoryOpen = inventoryOpen;
} }
} }