Make mass storage process input instantly

This allows to shift-click an entire inventory-load into a mass storage. Previously this was bottlenecked by the network latency and the tile entity tickrate.

Taking stuff out is unaffected for now, I'll see what I can do
This commit is contained in:
abel1502 2025-06-02 19:35:06 +03:00
parent 4b3430f9b1
commit a6740a35e9
No known key found for this signature in database
GPG Key ID: 076926596A536338
2 changed files with 42 additions and 19 deletions

View File

@ -27,32 +27,35 @@ public class ContainerMassStorage extends ContainerBase {
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int par2) {
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack result = null;
Slot slot = (Slot) this.inventorySlots.get(index);
if(var4 != null && var4.getHasStack()) {
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if(slot != null && slot.getHasStack()) {
ItemStack initial = slot.getStack();
result = initial.copy();
if(par2 == 0 || par2 == 2) {
if(!this.mergeItemStack(var5, storage.getSizeInventory(), this.inventorySlots.size(), true)) {
if(index == 0 || index == 2) {
if(!this.mergeItemStack(initial, storage.getSizeInventory(), this.inventorySlots.size(), true)) {
return null;
}
} else if(!this.mergeItemStack(var5, 0, 1, false)) {
return null;
}
if(var5.stackSize == 0) {
var4.putStack((ItemStack) null);
} else {
var4.onSlotChanged();
// Try to insert instantly, then fall back to regular slot behavior
if(!storage.insert(initial) && !this.mergeItemStack(initial, 0, 1, false)) {
return null;
}
}
var4.onPickupFromSlot(player, var5);
if(initial.stackSize == 0) {
slot.putStack((ItemStack) null);
} else {
slot.onSlotChanged();
}
slot.onPickupFromSlot(player, initial);
}
return var3;
return result;
}
@Override

View File

@ -62,7 +62,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
if(this.getType() == null)
this.stack = 0;
if(getType() != null && getStockpile() < getCapacity() && slots[0] != null && slots[0].isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(slots[0], getType())) {
if(canInsert(slots[0])) {
int remaining = getCapacity() - getStockpile();
int toRemove = Math.min(remaining, slots[0].stackSize);
@ -95,6 +95,26 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
}
}
public boolean canInsert(ItemStack stack) {
return getType() != null && getStockpile() < getCapacity() && stack != null && stack.isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(stack, getType());
}
public boolean insert(ItemStack stack) {
if (!canInsert(stack))
return false;
int remaining = getCapacity() - getStockpile();
if (remaining < stack.stackSize)
return false;
this.stack += stack.stackSize;
stack.stackSize = 0;
this.markDirty();
return true;
}
@Override
public void serialize(ByteBuf buf) {
buf.writeInt(this.stack);
@ -196,9 +216,9 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
if(data.hasKey("toggle")) {
this.output = !output;
}
if(data.hasKey("slot") && this.getStockpile() <= 0){
setFilterContents(data);
if(slots[1] != null) slots[1].stackSize = 1;
}
}