3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Improve InventoryTracker16 Code (#3302)

Dieser Commit ist enthalten in:
EnZaXD 2023-04-22 08:57:47 +02:00 committet von GitHub
Ursprung 54d8e29a7e
Commit a2e214ae18
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 9 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -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();
}
});

Datei anzeigen

@ -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)));

Datei anzeigen

@ -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;
}
}