mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 19:45:21 +01:00
Improve InventoryTracker16 Code (#3302)
This commit is contained in:
parent
54d8e29a7e
commit
a2e214ae18
@ -277,7 +277,7 @@ public class EntityPackets {
|
||||
protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, wrapper -> {
|
||||
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
|
||||
// Don't send an arm swing if the player has an inventory opened.
|
||||
if (inventoryTracker.getInventory() != -1) {
|
||||
if (inventoryTracker.isInventoryOpen()) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
|
@ -67,12 +67,11 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
||||
handler(cursorRemapper);
|
||||
handler(wrapper -> {
|
||||
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);
|
||||
if (windowType >= 20) { // smithing added with id 20
|
||||
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(wrapper -> {
|
||||
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 -> {
|
||||
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)));
|
||||
|
@ -20,13 +20,13 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class InventoryTracker1_16 implements StorableObject {
|
||||
private short inventory = -1;
|
||||
private boolean inventoryOpen = false;
|
||||
|
||||
public short getInventory() {
|
||||
return this.inventory;
|
||||
public boolean isInventoryOpen() {
|
||||
return inventoryOpen;
|
||||
}
|
||||
|
||||
public void setInventory(short inventory) {
|
||||
this.inventory = inventory;
|
||||
public void setInventoryOpen(boolean inventoryOpen) {
|
||||
this.inventoryOpen = inventoryOpen;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user