Don't markDirty() when inserting into a full slot (#177)

When inserting into a full slot, the inventory is not actually modified
but markDirty() is still called. This in turn sends a block update to
all neighbours. When a diamond chest is full, attempting to insert into
it will send 100+ block updates (one for each slot). This can cause mild
performance issues.
This commit is contained in:
SquidDev 2019-05-01 20:16:02 +01:00 committed by Alexander (alexbegt)
parent 6acfe334f1
commit a91739d57b
2 changed files with 6 additions and 4 deletions

View File

@ -79,10 +79,11 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
} }
else else
{ {
if (!ItemHandlerHelper.canItemStacksStack(stack, currentStack)) int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
return stack; return stack;
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted < stack.getCount()) if (accepted < stack.getCount())
{ {
if (!simulate) if (!simulate)

View File

@ -79,10 +79,11 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
} }
else else
{ {
if (!ItemHandlerHelper.canItemStacksStack(stack, currentStack)) int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
return stack; return stack;
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted < stack.getCount()) if (accepted < stack.getCount())
{ {
if (!simulate) if (!simulate)