Make mass storage process output instantly

Same deal as previously, this bypasses the bottleneck of tile entity ticking and network latency. This change is less relevant than the previous one, because there shift-dragging or shift-double-clicking were possible with mods, while here it only really affects autoclickers. Still, it can't hurt
This commit is contained in:
abel1502 2025-06-02 20:09:13 +03:00
parent a6740a35e9
commit 7ef016ccce
No known key found for this signature in database
GPG Key ID: 076926596A536338
2 changed files with 25 additions and 2 deletions

View File

@ -31,6 +31,11 @@ public class ContainerMassStorage extends ContainerBase {
ItemStack result = null;
Slot slot = (Slot) this.inventorySlots.get(index);
// Refill instantly if needed, then do regular slot behavior
if(index == 2 && slot != null && !slot.getHasStack()) {
slot.putStack(storage.quickExtract());
}
if(slot != null && slot.getHasStack()) {
ItemStack initial = slot.getStack();
result = initial.copy();
@ -41,7 +46,7 @@ public class ContainerMassStorage extends ContainerBase {
}
} else {
// Try to insert instantly, then fall back to regular slot behavior
if(!storage.insert(initial) && !this.mergeItemStack(initial, 0, 1, false)) {
if(!storage.quickInsert(initial) && !this.mergeItemStack(initial, 0, 1, false)) {
return null;
}
}

View File

@ -99,7 +99,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
return getType() != null && getStockpile() < getCapacity() && stack != null && stack.isItemEqual(getType()) && ItemStack.areItemStackTagsEqual(stack, getType());
}
public boolean insert(ItemStack stack) {
public boolean quickInsert(ItemStack stack) {
if (!canInsert(stack))
return false;
@ -115,6 +115,24 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
return true;
}
public ItemStack quickExtract() {
if (!output) {
return null;
}
int amount = getType().getMaxStackSize();
if (getStockpile() < amount)
return null;
ItemStack result = slots[1].copy();
result.stackSize = amount;
this.stack -= amount;
this.markDirty();
return result;
}
@Override
public void serialize(ByteBuf buf) {
buf.writeInt(this.stack);