mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-08-10 17:55:44 +00:00
mh yis
This commit is contained in:
parent
279a436639
commit
a673385697
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,10 +55,42 @@ 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<CacheSlot> 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<CacheSlot> SORT_BY_STACK_SIZE = new Comparator<CacheSlot>() {
|
||||
@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) {
|
||||
return access.getDistanceFrom(player.posX, player.posY, player.posZ) <= 15 * 15;
|
||||
@ -71,15 +104,23 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
|
||||
SlotPneumo slot = (SlotPneumo) this.getSlot(index);
|
||||
ItemStack held = player.inventory.getItemStack();
|
||||
|
||||
if(held == null && slot.getHasStack()) {
|
||||
boolean standardClick = button == 0 && mode == 0;
|
||||
boolean shiftClick = button == 0 && mode == 1;
|
||||
|
||||
if(slot.getHasStack()) {
|
||||
|
||||
// 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(button == 0) {
|
||||
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;
|
||||
@ -87,6 +128,20 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
return slot.getHasStack() ? slot.getStack().copy() : null;
|
||||
@ -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++) {
|
||||
@ -234,35 +290,6 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
|
||||
this.cache = access.cache;
|
||||
}
|
||||
|
||||
public void updateListing() { // DEMO
|
||||
if(this.cache == null) return;
|
||||
List<CacheSlot> 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<CacheSlot> SORT_BY_STACK_SIZE = new Comparator<CacheSlot>() {
|
||||
@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]; }
|
||||
@Override public int getInventoryStackLimit() { return 64; }
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user