diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerItemHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerItemHandler.java index ebd925df2..5d8b00047 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerItemHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerItemHandler.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.contraptions.components.deployer; -import java.util.Iterator; - import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; import net.minecraft.world.InteractionHand; @@ -21,12 +19,12 @@ public class DeployerItemHandler implements IItemHandlerModifiable { @Override public int getSlots() { - return 1; + return 1 + te.overflowItems.size(); } @Override public ItemStack getStackInSlot(int slot) { - return getHeld(); + return slot >= te.overflowItems.size() ? getHeld() : te.overflowItems.get(slot); } public ItemStack getHeld() { @@ -47,14 +45,18 @@ public class DeployerItemHandler implements IItemHandlerModifiable { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - ItemStack held = getHeld(); + if (slot < te.overflowItems.size()) + return stack; if (!isItemValid(slot, stack)) return stack; + + ItemStack held = getHeld(); if (held.isEmpty()) { if (!simulate) set(stack); return ItemStack.EMPTY; } + if (!ItemHandlerHelper.canItemStacksStack(held, stack)) return stack; @@ -78,36 +80,18 @@ public class DeployerItemHandler implements IItemHandlerModifiable { if (amount == 0) return ItemStack.EMPTY; - ItemStack extractedFromOverflow = ItemStack.EMPTY; - ItemStack returnToOverflow = ItemStack.EMPTY; - - for (Iterator iterator = te.overflowItems.iterator(); iterator.hasNext();) { - ItemStack existing = iterator.next(); - if (existing.isEmpty()) { - iterator.remove(); - continue; - } - - int toExtract = Math.min(amount, existing.getMaxStackSize()); - if (existing.getCount() <= toExtract) { - if (!simulate) - iterator.remove(); - extractedFromOverflow = existing; - break; - } - if (!simulate) { - iterator.remove(); - returnToOverflow = ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract); - } - extractedFromOverflow = ItemHandlerHelper.copyStackWithSize(existing, toExtract); - break; + if (slot < te.overflowItems.size()) { + ItemStack itemStack = te.overflowItems.get(slot); + int toExtract = Math.min(amount, itemStack.getCount()); + ItemStack extracted = simulate ? itemStack.copy() : itemStack.split(toExtract); + extracted.setCount(toExtract); + if (!simulate && itemStack.isEmpty()) + te.overflowItems.remove(slot); + if (!simulate && !extracted.isEmpty()) + te.setChanged(); + return extracted; } - if (!returnToOverflow.isEmpty()) - te.overflowItems.add(returnToOverflow); - if (!extractedFromOverflow.isEmpty()) - return extractedFromOverflow; - ItemStack held = getHeld(); if (amount == 0 || held.isEmpty()) return ItemStack.EMPTY; @@ -126,7 +110,7 @@ public class DeployerItemHandler implements IItemHandlerModifiable { @Override public int getSlotLimit(int slot) { - return Math.min(getHeld().getMaxStackSize(), 64); + return Math.min(getStackInSlot(slot).getMaxStackSize(), 64); } @Override @@ -137,6 +121,10 @@ public class DeployerItemHandler implements IItemHandlerModifiable { @Override public void setStackInSlot(int slot, ItemStack stack) { + if (slot < te.overflowItems.size()) { + te.overflowItems.set(slot, stack); + return; + } set(stack); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltInventory.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltInventory.java index 6ba231609..adf8811fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltInventory.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltInventory.java @@ -150,7 +150,6 @@ public class BeltInventory { continue; } - // Belt Funnels if (BeltFunnelInteractionHandler.checkForFunnels(this, currentItem, nextOffset)) continue; @@ -217,7 +216,8 @@ public class BeltInventory { } } - protected boolean handleBeltProcessingAndCheckIfRemoved(TransportedItemStack currentItem, float nextOffset, boolean noMovement) { + protected boolean handleBeltProcessingAndCheckIfRemoved(TransportedItemStack currentItem, float nextOffset, + boolean noMovement) { int currentSegment = (int) currentItem.beltPosition; // Continue processing if held @@ -315,8 +315,9 @@ public class BeltInventory { if (inputBehaviour != null) return Ending.INSERT; - if (BlockHelper.hasBlockSolidSide(world.getBlockState(nextPosition), world, nextPosition, belt.getMovementFacing() - .getOpposite())) + if (BlockHelper.hasBlockSolidSide(world.getBlockState(nextPosition), world, nextPosition, + belt.getMovementFacing() + .getOpposite())) return Ending.BLOCKED; return Ending.EJECT; @@ -405,9 +406,11 @@ public class BeltInventory { ItemStack ejected = stack.stack; Vec3 outPos = BeltHelper.getVectorForOffset(belt, stack.beltPosition); float movementSpeed = Math.max(Math.abs(belt.getBeltMovementSpeed()), 1 / 8f); - Vec3 outMotion = Vec3.atLowerCornerOf(belt.getBeltChainDirection()).scale(movementSpeed) + Vec3 outMotion = Vec3.atLowerCornerOf(belt.getBeltChainDirection()) + .scale(movementSpeed) .add(0, 1 / 8f, 0); - outPos = outPos.add(outMotion.normalize().scale(0.001)); + outPos = outPos.add(outMotion.normalize() + .scale(0.001)); ItemEntity entity = new ItemEntity(belt.getLevel(), outPos.x, outPos.y + 6 / 16f, outPos.z, ejected); entity.setDeltaMovement(outMotion); entity.setDefaultPickUpDelay(); @@ -429,7 +432,7 @@ public class BeltInventory { if (Math.abs(position - transported.beltPosition) >= maxDistanceToPosition) continue; TransportedResult result = processFunction.apply(transported); - if (result == null|| result.didntChangeFrom(stackBefore)) + if (result == null || result.didntChangeFrom(stackBefore)) continue; dirty = true;