diff --git a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainItemHandler.java b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainItemHandler.java index d69e16c55..44da916ea 100644 --- a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainItemHandler.java +++ b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainItemHandler.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.fluids.drain; import com.simibubi.create.content.fluids.transfer.GenericItemEmptying; import com.simibubi.create.content.kinetics.belt.transport.TransportedItemStack; +import com.simibubi.create.foundation.item.ItemHelper; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; @@ -38,7 +39,8 @@ public class ItemDrainItemHandler implements IItemHandler { if (stack.getCount() > 1 && GenericItemEmptying.canItemBeEmptied(blockEntity.getLevel(), stack)) { returned = ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1); stack = ItemHandlerHelper.copyStackWithSize(stack, 1); - } + } else + returned = ItemHelper.limitCountToMaxStackSize(stack, simulate); if (!simulate) { TransportedItemStack heldItem = new TransportedItemStack(stack); diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlock.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlock.java index 64c37cc2c..944e4a399 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlock.java @@ -218,6 +218,8 @@ public class BeltBlock extends HorizontalKineticBlock .copy(), false); if (remainder.isEmpty()) itemEntity.discard(); + else if (remainder.getCount() != itemEntity.getItem().getCount()) + itemEntity.setItem(remainder); }); return; } diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java index 0a5248c5f..15f20c86d 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/ItemHandlerBeltSegment.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.kinetics.belt.transport; +import com.simibubi.create.foundation.item.ItemHelper; + import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; @@ -29,6 +31,7 @@ public class ItemHandlerBeltSegment implements IItemHandler { @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (this.beltInventory.canInsertAt(offset)) { + ItemStack remainder = ItemHelper.limitCountToMaxStackSize(stack, simulate); if (!simulate) { TransportedItemStack newStack = new TransportedItemStack(stack); newStack.insertedAt = offset; @@ -38,7 +41,7 @@ public class ItemHandlerBeltSegment implements IItemHandler { this.beltInventory.belt.setChanged(); this.beltInventory.belt.sendData(); } - return ItemStack.EMPTY; + return remainder; } return stack; } diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerItemHandler.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerItemHandler.java index ecabcf2ed..ac106c825 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerItemHandler.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerItemHandler.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.kinetics.deployer; import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour; +import com.simibubi.create.foundation.item.ItemHelper; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; @@ -52,9 +53,10 @@ public class DeployerItemHandler implements IItemHandlerModifiable { ItemStack held = getHeld(); if (held.isEmpty()) { + ItemStack remainder = ItemHelper.limitCountToMaxStackSize(stack, simulate); if (!simulate) set(stack); - return ItemStack.EMPTY; + return remainder; } if (!ItemHandlerHelper.canItemStacksStack(held, stack)) diff --git a/src/main/java/com/simibubi/create/content/logistics/chute/ChuteItemHandler.java b/src/main/java/com/simibubi/create/content/logistics/chute/ChuteItemHandler.java index 72a77ff01..7179a1d26 100644 --- a/src/main/java/com/simibubi/create/content/logistics/chute/ChuteItemHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/chute/ChuteItemHandler.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.logistics.chute; +import com.simibubi.create.foundation.item.ItemHelper; + import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; @@ -25,9 +27,10 @@ public class ChuteItemHandler implements IItemHandler { public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (!blockEntity.canAcceptItem(stack)) return stack; + ItemStack remainder = ItemHelper.limitCountToMaxStackSize(stack, simulate); if (!simulate) blockEntity.setItem(stack); - return ItemStack.EMPTY; + return remainder; } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/funnel/FunnelBlock.java b/src/main/java/com/simibubi/create/content/logistics/funnel/FunnelBlock.java index d617c9e42..460819ad9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/funnel/FunnelBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/funnel/FunnelBlock.java @@ -93,7 +93,7 @@ public abstract class FunnelBlock extends AbstractDirectionalFunnelBlock { withBlockEntityDo(worldIn, pos, be -> { ItemStack toInsert = heldItem.copy(); ItemStack remainder = tryInsert(worldIn, pos, toInsert, false); - if (!ItemStack.matches(remainder, toInsert)) + if (!ItemStack.matches(remainder, toInsert) || remainder.getCount() != heldItem.getCount()) player.setItemInHand(handIn, remainder); }); return InteractionResult.SUCCESS; diff --git a/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelItemHandler.java b/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelItemHandler.java index 430755c50..0db27450a 100644 --- a/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelItemHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/tunnel/BrassTunnelItemHandler.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.logistics.tunnel; +import com.simibubi.create.foundation.item.ItemHelper; + import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; @@ -33,9 +35,11 @@ public class BrassTunnelItemHandler implements IItemHandler { if (!blockEntity.canTakeItems()) return stack; + + ItemStack remainder = ItemHelper.limitCountToMaxStackSize(stack, simulate); if (!simulate) blockEntity.setStackToDistribute(stack, null); - return ItemStack.EMPTY; + return remainder; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java index 1f4e09d18..9ea14a53c 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java @@ -276,4 +276,16 @@ public class ItemHelper { } return -1; } + + public static ItemStack limitCountToMaxStackSize(ItemStack stack, boolean simulate) { + int count = stack.getCount(); + int max = stack.getMaxStackSize(); + if (count <= max) + return ItemStack.EMPTY; + ItemStack remainder = ItemHandlerHelper.copyStackWithSize(stack, count - max); + if (!simulate) + stack.setCount(max); + return remainder; + } + }