From 512235af467afdc79657bc6c41398208fb48c809 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 19:36:03 +0100 Subject: [PATCH] Fix several item handling issues in turtle refueling - Adding more fuel than there are items - Potentially consuming fuel from other slots too. - Not returning the container if the inventory is full. Fixes #157 --- .../cctweaks/core/turtle/DefaultTurtleProviders.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/squiddev/cctweaks/core/turtle/DefaultTurtleProviders.java b/src/main/java/org/squiddev/cctweaks/core/turtle/DefaultTurtleProviders.java index 719af851..6bf00fb7 100644 --- a/src/main/java/org/squiddev/cctweaks/core/turtle/DefaultTurtleProviders.java +++ b/src/main/java/org/squiddev/cctweaks/core/turtle/DefaultTurtleProviders.java @@ -7,6 +7,7 @@ import dan200.computercraft.shared.turtle.blocks.ITurtleTile; import dan200.computercraft.shared.turtle.core.TurtlePlayer; import dan200.computercraft.shared.util.InventoryUtil; +import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.item.ItemStack; @@ -51,14 +52,20 @@ public boolean canRefuel(@Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack @Override public int refuel(@Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, int limit) { + if (limit > stack.stackSize) limit = stack.stackSize; + int fuelToGive = TileEntityFurnace.getItemBurnTime(stack) * 5 / 100 * limit; ItemStack replacementStack = stack.getItem().getContainerItem(stack); // Remove 'n' items from the stack. - InventoryUtil.takeItems(limit, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), turtle.getSelectedSlot()); + int slot = turtle.getSelectedSlot(); + InventoryUtil.takeItems(limit, turtle.getInventory(), slot, 1, slot); if (replacementStack != null) { // If item is empty (bucket) then add it back - InventoryUtil.storeItems(replacementStack, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), turtle.getSelectedSlot()); + replacementStack = InventoryUtil.storeItems(replacementStack, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), slot); + if (replacementStack != null) { + WorldUtil.dropItemStack(replacementStack, turtle.getWorld(), turtle.getPosition(), turtle.getDirection().getOpposite()); + } } return fuelToGive;