From 16e8dd0df1be3c924208e6586f9608286f27db23 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:04:11 -0500 Subject: [PATCH] Don't confirm if the inventory is the same type --- .../connector/inventory/AnvilContainer.java | 6 ++++-- .../connector/inventory/BeaconContainer.java | 5 +++-- .../connector/inventory/CartographyContainer.java | 6 ++++-- .../geysermc/connector/inventory/Container.java | 5 +++-- .../connector/inventory/EnchantingContainer.java | 5 +++-- .../connector/inventory/Generic3X3Container.java | 5 +++-- .../geysermc/connector/inventory/Inventory.java | 14 +++++++++++--- .../connector/inventory/LecternContainer.java | 5 +++-- .../connector/inventory/MerchantContainer.java | 5 +++-- .../connector/inventory/PlayerInventory.java | 2 +- .../connector/inventory/StonecutterContainer.java | 5 +++-- .../translators/AnvilInventoryTranslator.java | 2 +- .../translators/BaseInventoryTranslator.java | 2 +- .../translators/BeaconInventoryTranslator.java | 2 +- .../CartographyInventoryTranslator.java | 2 +- .../translators/EnchantingInventoryTranslator.java | 2 +- .../translators/Generic3X3InventoryTranslator.java | 2 +- .../translators/LecternInventoryTranslator.java | 2 +- .../translators/MerchantInventoryTranslator.java | 2 +- .../StonecutterInventoryTranslator.java | 2 +- .../java/window/JavaOpenHorseWindowTranslator.java | 2 +- .../java/window/JavaOpenWindowTranslator.java | 3 ++- 22 files changed, 53 insertions(+), 33 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/inventory/AnvilContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/AnvilContainer.java index 02e1c225e..71b5cbda9 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/AnvilContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/AnvilContainer.java @@ -25,11 +25,13 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; + /** * Used to determine if rename packets should be sent. */ public class AnvilContainer extends Container { - public AnvilContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public AnvilContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/BeaconContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/BeaconContainer.java index 66de2d8a9..3798d9009 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/BeaconContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/BeaconContainer.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; import lombok.Setter; @@ -34,7 +35,7 @@ public class BeaconContainer extends Container { private int primaryId; private int secondaryId; - public BeaconContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public BeaconContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/CartographyContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/CartographyContainer.java index be4abd9e1..0ac93b431 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/CartographyContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/CartographyContainer.java @@ -25,8 +25,10 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; + public class CartographyContainer extends Container { - public CartographyContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public CartographyContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Container.java b/connector/src/main/java/org/geysermc/connector/inventory/Container.java index 6302a7daa..d61b2b71d 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Container.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Container.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; import lombok.NonNull; import org.geysermc.connector.network.session.GeyserSession; @@ -43,8 +44,8 @@ public class Container extends Inventory { */ private boolean isUsingRealBlock = false; - public Container(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size); + public Container(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType); this.playerInventory = playerInventory; this.containerSize = this.size + InventoryTranslator.PLAYER_INVENTORY_SIZE; } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/EnchantingContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/EnchantingContainer.java index d11ca6788..e8c935649 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/EnchantingContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/EnchantingContainer.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import com.nukkitx.protocol.bedrock.data.inventory.EnchantOptionData; import lombok.Getter; @@ -40,8 +41,8 @@ public class EnchantingContainer extends Container { @Getter private final GeyserEnchantOption[] geyserEnchantOptions; - public EnchantingContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public EnchantingContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); enchantOptions = new EnchantOptionData[3]; geyserEnchantOptions = new GeyserEnchantOption[3]; diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java b/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java index be8d13a74..8c89cdeb6 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Generic3X3Container.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; public class Generic3X3Container extends Container { @@ -34,8 +35,8 @@ public class Generic3X3Container extends Container { @Getter private boolean isDropper = false; - public Generic3X3Container(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public Generic3X3Container(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java index 179801825..9246c0478 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import lombok.NonNull; @@ -41,6 +42,12 @@ public class Inventory { @Getter protected final int size; + /** + * Used for smooth transitions between two windows of the same type. + */ + @Getter + protected final WindowType windowType; + @Getter @Setter protected String title; @@ -65,14 +72,15 @@ public class Inventory { @Setter private boolean pending = false; - protected Inventory(int id, int size) { - this("Inventory", id, size); + protected Inventory(int id, int size, WindowType windowType) { + this("Inventory", id, size, windowType); } - protected Inventory(String title, int id, int size) { + protected Inventory(String title, int id, int size, WindowType windowType) { this.title = title; this.id = id; this.size = size; + this.windowType = windowType; this.items = new GeyserItemStack[size]; Arrays.fill(items, GeyserItemStack.EMPTY); } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/LecternContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/LecternContainer.java index 1b686a8f3..be1b8b34b 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/LecternContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/LecternContainer.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.nbt.NbtMap; import lombok.Getter; @@ -38,7 +39,7 @@ public class LecternContainer extends Container { @Getter @Setter private Vector3i position; - public LecternContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public LecternContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/MerchantContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/MerchantContainer.java index f4f2d90eb..5941b2a7d 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/MerchantContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/MerchantContainer.java @@ -26,6 +26,7 @@ package org.geysermc.connector.inventory; import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; import lombok.Setter; import org.geysermc.connector.entity.Entity; @@ -36,7 +37,7 @@ public class MerchantContainer extends Container { private Entity villager; private VillagerTrade[] villagerTrades; - public MerchantContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public MerchantContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java b/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java index 9d03c69ab..4b81853aa 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java @@ -45,7 +45,7 @@ public class PlayerInventory extends Inventory { private GeyserItemStack cursor = GeyserItemStack.EMPTY; public PlayerInventory() { - super(0, 46); + super(0, 46, null); heldItemSlot = 0; } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/StonecutterContainer.java b/connector/src/main/java/org/geysermc/connector/inventory/StonecutterContainer.java index 48620282f..d558fab34 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/StonecutterContainer.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/StonecutterContainer.java @@ -25,6 +25,7 @@ package org.geysermc.connector.inventory; +import com.github.steveice10.mc.protocol.data.game.window.WindowType; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -38,8 +39,8 @@ public class StonecutterContainer extends Container { @Setter private int stonecutterButton = -1; - public StonecutterContainer(String title, int id, int size, PlayerInventory playerInventory) { - super(title, id, size, playerInventory); + public StonecutterContainer(String title, int id, int size, WindowType windowType, PlayerInventory playerInventory) { + super(title, id, size, windowType, playerInventory); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java index ded198ef6..38a0935e6 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java @@ -139,6 +139,6 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator { @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new AnvilContainer(name, windowId, this.size, playerInventory); + return new AnvilContainer(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BaseInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BaseInventoryTranslator.java index b67ca008e..5b3be5b27 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BaseInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BaseInventoryTranslator.java @@ -96,6 +96,6 @@ public abstract class BaseInventoryTranslator extends InventoryTranslator { @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new Container(name, windowId, this.size, playerInventory); + return new Container(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BeaconInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BeaconInventoryTranslator.java index b0cb77151..46c09b66b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BeaconInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BeaconInventoryTranslator.java @@ -127,6 +127,6 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new BeaconContainer(name, windowId, this.size, playerInventory); + return new BeaconContainer(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java index 047944336..2038a5ba0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java @@ -98,6 +98,6 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new CartographyContainer(name, windowId, this.size, playerInventory); + return new CartographyContainer(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/EnchantingInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/EnchantingInventoryTranslator.java index 3a25c2a89..03f8bb104 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/EnchantingInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/EnchantingInventoryTranslator.java @@ -164,7 +164,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new EnchantingContainer(name, windowId, this.size, playerInventory); + return new EnchantingContainer(name, windowId, this.size, windowType, playerInventory); } /** diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/Generic3X3InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/Generic3X3InventoryTranslator.java index 133ec635d..ceac1b2c1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/Generic3X3InventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/Generic3X3InventoryTranslator.java @@ -47,7 +47,7 @@ public class Generic3X3InventoryTranslator extends AbstractBlockInventoryTransla @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new Generic3X3Container(name, windowId, this.size, playerInventory); + return new Generic3X3Container(name, windowId, this.size, windowType, playerInventory); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java index 084c4fc17..c1a623ab6 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LecternInventoryTranslator.java @@ -151,7 +151,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new LecternContainer(name, windowId, this.size, playerInventory); + return new LecternContainer(name, windowId, this.size, windowType, playerInventory); } public static NbtMapBuilder getBaseLecternTag(int x, int y, int z, int totalPages) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java index e2808819b..34feb40d9 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java @@ -157,6 +157,6 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator { @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new MerchantContainer(name, windowId, this.size, playerInventory); + return new MerchantContainer(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java index 3c267e121..4bb5748dc 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java @@ -133,6 +133,6 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl @Override public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) { - return new StonecutterContainer(name, windowId, this.size, playerInventory); + return new StonecutterContainer(name, windowId, this.size, windowType, playerInventory); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenHorseWindowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenHorseWindowTranslator.java index 4affcc904..8952ddcb3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenHorseWindowTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenHorseWindowTranslator.java @@ -132,6 +132,6 @@ public class JavaOpenHorseWindowTranslator extends PacketTranslator