From db25dcce48fda2f03c11e12508d06dc26a1cf97b Mon Sep 17 00:00:00 2001 From: Algent Date: Sat, 4 Jul 2026 20:57:41 +0200 Subject: [PATCH] Dupe Fix - Make bag logic more lag resistant (#121) --- src/main/java/forestry/core/inventory/ItemInventory.java | 6 +++++- src/main/java/forestry/core/items/ItemWithGui.java | 2 +- .../storage/inventory/ItemInventoryBackpackPaged.java | 7 ++++++- src/main/java/forestry/storage/items/ItemBackpack.java | 2 +- .../forestry/storage/items/ItemBackpackNaturalist.java | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/forestry/core/inventory/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java index e4c0c632c..88f16fa86 100755 --- a/src/main/java/forestry/core/inventory/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -87,7 +87,7 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { public boolean isParentItemEquipped() { return switch (location.type()) { case HELD_BY_PLAYER, UNKNOWN -> isSameItemInventory(player.getCurrentEquippedItem(), parent); - case PLAYER_INVENTORY -> true; + case PLAYER_INVENTORY -> isSameItemInventory(player.inventory.getStackInSlot(location.slotIdx()), parent); }; } @@ -95,6 +95,10 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { return player; } + public ItemLocation getLocation() { + return location; + } + public boolean isParentItemInventory(ItemStack itemStack) { ItemStack parent = getParent(); return isSameItemInventory(parent, itemStack); diff --git a/src/main/java/forestry/core/items/ItemWithGui.java b/src/main/java/forestry/core/items/ItemWithGui.java index a682de7e1..524bc99c5 100644 --- a/src/main/java/forestry/core/items/ItemWithGui.java +++ b/src/main/java/forestry/core/items/ItemWithGui.java @@ -33,7 +33,7 @@ public abstract class ItemWithGui extends ItemForestry implements IGuiHandlerIte } protected void openGui(EntityPlayer entityplayer) { - GuiHandler.openGui(entityplayer, this); + GuiHandler.openGui(entityplayer, this, (short) 0, entityplayer.inventory.currentItem); } @Override diff --git a/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java b/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java index 7779d74cd..cc0a196ef 100644 --- a/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java +++ b/src/main/java/forestry/storage/inventory/ItemInventoryBackpackPaged.java @@ -28,6 +28,11 @@ public class ItemInventoryBackpackPaged extends ItemInventoryBackpack implements @Override public void flipPage(EntityPlayer player, short page) { - GuiHandler.openGui(player, backpackNaturalist, page); + ItemLocation loc = getLocation(); + if (loc.type() == ItemLocation.Type.PLAYER_INVENTORY) { + GuiHandler.openGui(player, backpackNaturalist, page, loc.slotIdx()); + } else { + GuiHandler.openGui(player, backpackNaturalist, page); + } } } diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index 0f7ea4462..917085bf6 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -72,7 +72,7 @@ public class ItemBackpack extends ItemWithGui implements ActivatableFromInventor @Override protected void openGui(EntityPlayer entityplayer) { - GuiHandler.openGui(entityplayer, this, (short) type.ordinal()); + GuiHandler.openGui(entityplayer, this, (short) type.ordinal(), entityplayer.inventory.currentItem); } @Override diff --git a/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java b/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java index 7070a3f7e..fa6434094 100644 --- a/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java +++ b/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java @@ -34,7 +34,7 @@ public class ItemBackpackNaturalist extends ItemBackpack { @Override protected void openGui(EntityPlayer entityplayer) { - GuiHandler.openGui(entityplayer, this); + GuiHandler.openGui(entityplayer, this, (short) 0, entityplayer.inventory.currentItem); } @Override