From a6733856977befb316527c7f67e9a30cf027e68b Mon Sep 17 00:00:00 2001 From: HbmMods Date: Fri, 12 Jun 2026 23:25:19 +0200 Subject: [PATCH] mh yis --- src/main/java/api/hbm/ntl/SlotMonitor.java | 3 - .../ContainerPneumoStorageAccess.java | 111 +++++++++++------- .../networkproviders/PneumaticNetwork.java | 11 +- 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/src/main/java/api/hbm/ntl/SlotMonitor.java b/src/main/java/api/hbm/ntl/SlotMonitor.java index 2422456be..63da74ef3 100644 --- a/src/main/java/api/hbm/ntl/SlotMonitor.java +++ b/src/main/java/api/hbm/ntl/SlotMonitor.java @@ -109,7 +109,6 @@ public class SlotMonitor { CacheSlot slot = iterator.next(); slot.removeMonitor(this); iterator.remove(); - System.out.println("Removing"); } // set updated traits @@ -129,10 +128,8 @@ public class SlotMonitor { if(pneumoNet != null) { for(StackCache cache : pneumoNet.accessors) { - System.out.println("Adding to cache..."); if(!cache.hasExpired && parent.isAvailableToCache(cache)) { cache.addToCache(this); - System.out.println("Added!"); } } } diff --git a/src/main/java/com/hbm/inventory/container/ContainerPneumoStorageAccess.java b/src/main/java/com/hbm/inventory/container/ContainerPneumoStorageAccess.java index 7ea2babd7..348e8617f 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerPneumoStorageAccess.java +++ b/src/main/java/com/hbm/inventory/container/ContainerPneumoStorageAccess.java @@ -11,6 +11,7 @@ import com.hbm.packet.PacketDispatcher; import com.hbm.packet.toclient.ContainerCustomPayloadPacket; import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageAccess; import com.hbm.util.EnumUtil; +import com.hbm.util.InventoryUtil; import api.hbm.ntl.StackCache; import api.hbm.ntl.StackCache.CacheSlot; @@ -54,9 +55,41 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, 8 + i * 18, 227)); } - inventory.updateListing(); + updateListing(); this.detectAndSendChanges(); } + + public void updateListing() { // DEMO + if(this.access.cache == null || this.access.cache.hasExpired) return; + StackCache cache = this.access.cache; + List cacheSlots = new ArrayList(cache.cacheSlots.size()); + cacheSlots.addAll(cache.cacheSlots.values()); + cacheSlots.removeIf(x -> { return x.stacksize <= 0; }); + Collections.sort(cacheSlots, SORT_BY_STACK_SIZE); + int size = cacheSlots.size(); + + for(int i = 0; i < inventory.slots.length; i++) { + if(i < size) { + CacheSlot cacheSlot = cacheSlots.get(i); + if(cacheSlot.displayStack != null) { + inventory.slots[i] = cacheSlot.displayStack.copy(); + } + } else { + inventory.slots[i] = null; + } + } + } + + public static final Comparator SORT_BY_STACK_SIZE = new Comparator() { + @Override + public int compare(CacheSlot o1, CacheSlot o2) { + if(o1.stacksize > o2.stacksize) return -1; if(o1.stacksize < o2.stacksize) return 1; + if(o1.itemId < o2.itemId) return -1; if(o1.itemId > o2.itemId) return 1; + if(o1.meta < o2.meta) return -1; if(o1.meta > o2.meta) return 1; + if(o1.nbt == null && o2.nbt != null) return -1; if(o1.nbt != null && o2.nbt == null) return 1; + return 0; + } + }; @Override public boolean canInteractWith(EntityPlayer player) { @@ -70,22 +103,44 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa boolean client = player.worldObj.isRemote; SlotPneumo slot = (SlotPneumo) this.getSlot(index); ItemStack held = player.inventory.getItemStack(); + + boolean standardClick = button == 0 && mode == 0; + boolean shiftClick = button == 0 && mode == 1; - if(held == null && slot.getHasStack()) { - ItemStack stack = slot.getStack().copy(); + if(slot.getHasStack()) { - if(button == 0) { - int toGrab = (int) Math.min(stack.getMaxStackSize(), slot.amount); + // left click, can't hold an item and provides a full stack to the held item + if(standardClick && held == null) { + ItemStack stack = slot.getStack().copy(); - if(client) { - stack.stackSize = toGrab; - player.inventory.setItemStack(stack); - } else { - if(this.access.cache == null || this.access.cache.hasExpired) return stack; - StackCache cache = this.access.cache; - stack.stackSize = (int) cache.consumeItemsAndReturnQuantity(stack, toGrab); // this can't work because the stack got altered with the description NBT..... - player.inventory.setItemStack(stack); + if(standardClick) { + int toGrab = (int) Math.min(stack.getMaxStackSize(), slot.amount); + + if(client) { + stack.stackSize = toGrab; + player.inventory.setItemStack(stack); + //slot.amount -= toGrab; + //if(slot.amount <= 0) slot.putStack(null); + } else { + if(this.access.cache == null || this.access.cache.hasExpired) return stack; + StackCache cache = this.access.cache; + stack.stackSize = (int) cache.consumeItemsAndReturnQuantity(stack, toGrab); // this can't work because the stack got altered with the description NBT..... + player.inventory.setItemStack(stack); + } } + + // shift click, works even if there's a held stack, serverside only and the nwe just sync + } else if(shiftClick && !client) { + ItemStack stack = slot.getStack().copy(); + if(this.access.cache == null || this.access.cache.hasExpired) return stack; + StackCache cache = this.access.cache; + int originalStacksize = (int) Math.min(stack.getMaxStackSize(), slot.amount); + stack.stackSize = originalStacksize; + ItemStack ret = InventoryUtil.tryAddItemToInventory(player.inventory.mainInventory, stack); + int remainder = ret == null ? 0 : ret.stackSize; + int itemsUsed = originalStacksize - remainder; + cache.consumeItemsAndReturnQuantity(stack, itemsUsed); + detectAndSendChanges(); } } @@ -118,6 +173,7 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa */ @Override public void detectAndSendChanges() { + this.updateListing(); // skip the first 6*8 slots, i.e. all the ones visible in the access grid for(int i = GRID_SIZE; i < this.inventorySlots.size(); i++) { @@ -233,35 +289,6 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa this.slots = new ItemStack[getSizeInventory()]; this.cache = access.cache; } - - public void updateListing() { // DEMO - if(this.cache == null) return; - List cacheSlots = new ArrayList(cache.cacheSlots.size()); - cacheSlots.addAll(cache.cacheSlots.values()); - cacheSlots.removeIf(x -> { return x.stacksize <= 0; }); - Collections.sort(cacheSlots, SORT_BY_STACK_SIZE); - int size = cacheSlots.size(); - - for(int i = 0; i < slots.length; i++) { - if(i < size) { - CacheSlot cache = cacheSlots.get(i); - if(cache.displayStack != null) { - slots[i] = cache.displayStack.copy(); - } - } - } - } - - public static final Comparator SORT_BY_STACK_SIZE = new Comparator() { - @Override - public int compare(CacheSlot o1, CacheSlot o2) { - if(o1.stacksize > o2.stacksize) return -1; if(o1.stacksize < o2.stacksize) return 1; - if(o1.itemId < o2.itemId) return -1; if(o1.itemId > o2.itemId) return 1; - if(o1.meta < o2.meta) return -1; if(o1.meta > o2.meta) return 1; - if(o1.nbt == null && o2.nbt != null) return -1; if(o1.nbt != null && o2.nbt == null) return 1; - return 0; - } - }; @Override public int getSizeInventory() { return GRID_SIZE; } @Override public ItemStack getStackInSlot(int slot) { return slots[slot]; } diff --git a/src/main/java/com/hbm/uninos/networkproviders/PneumaticNetwork.java b/src/main/java/com/hbm/uninos/networkproviders/PneumaticNetwork.java index 00ac69f26..bbe0dc575 100644 --- a/src/main/java/com/hbm/uninos/networkproviders/PneumaticNetwork.java +++ b/src/main/java/com/hbm/uninos/networkproviders/PneumaticNetwork.java @@ -60,10 +60,15 @@ public class PneumaticNetwork extends NodeNet { super.joinNetworks(network); PneumaticNetwork net = (PneumaticNetwork) network; - for(StackCache cache : accessors) cache.dissolveCache(); + //for(StackCache cache : accessors) cache.dissolveCache(); - for(Object connector : net.accessors) this.accessors.add((StackCache) connector); - for(Object connector : net.storages) this.storages.add((ISlotMonitorProvider) connector); + for(Object acc : net.accessors) this.accessors.add((StackCache) acc); + + for(Object connector : net.storages) { + ISlotMonitorProvider monitor = (ISlotMonitorProvider) connector; + this.storages.add((ISlotMonitorProvider) connector); + for(Object acc : net.accessors) monitor.onNewCacheHasJoined((StackCache) acc, this); + } } public void addReceiver(IInventory inventory, ForgeDirection pipeDir, TileEntityPneumoTube endpoint) {