diff --git a/buildcraft_resources/changelog/7.1.23 b/buildcraft_resources/changelog/7.1.23 index 4a327b65..574c82d4 100644 --- a/buildcraft_resources/changelog/7.1.23 +++ b/buildcraft_resources/changelog/7.1.23 @@ -2,4 +2,5 @@ Bugs fixed: * [#3839] Attempt to work around potential world corruption? * [#3837] Oil spawn in mid-air on superflat -* Potential direction statement parameter crash in gate GUI \ No newline at end of file +* Delivery robots dropping requested item if occupies >1 slot +* Potential direction statement parameter crash in gate GUI diff --git a/common/buildcraft/core/lib/inventory/InvUtils.java b/common/buildcraft/core/lib/inventory/InvUtils.java index bc1e6679..9a66c4cd 100644 --- a/common/buildcraft/core/lib/inventory/InvUtils.java +++ b/common/buildcraft/core/lib/inventory/InvUtils.java @@ -8,6 +8,8 @@ */ package buildcraft.core.lib.inventory; +import java.util.Iterator; + import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryLargeChest; @@ -238,4 +240,55 @@ public final class InvUtils { return null; } + + public static Iterable getItems(final IInventory inv, final IStackFilter filter) { + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + private final Iterator parent = InventoryIterator.getIterable(inv).iterator(); + private boolean searched = false; + private IInvSlot next; + + private void find() { + next = null; + searched = true; + + while (parent.hasNext()) { + IInvSlot s = parent.next(); + if (s.getStackInSlot() != null && filter.matches(s.getStackInSlot())) { + next = s; + return; + } + } + } + + @Override + public boolean hasNext() { + if (!searched) { + find(); + } + + return next != null; + } + + @Override + public IInvSlot next() { + if (!searched) { + find(); + } + + IInvSlot current = next; + find(); + return current; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("Remove not supported."); + } + }; + } + }; + } } diff --git a/common/buildcraft/core/statements/StatementParameterItemStackExact.java b/common/buildcraft/core/statements/StatementParameterItemStackExact.java index 3a0d172d..051da91e 100644 --- a/common/buildcraft/core/statements/StatementParameterItemStackExact.java +++ b/common/buildcraft/core/statements/StatementParameterItemStackExact.java @@ -11,8 +11,16 @@ import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.StatementMouseClick; public class StatementParameterItemStackExact implements IStatementParameter { - protected ItemStack stack; + private int availableSlots; + + public StatementParameterItemStackExact() { + this(-1); + } + + public StatementParameterItemStackExact(int availableSlots) { + this.availableSlots = availableSlots; + } @Override public IIcon getIcon() { @@ -30,8 +38,10 @@ public class StatementParameterItemStackExact implements IStatementParameter { if (areItemsEqual(this.stack, stack)) { if (mouse.getButton() == 0) { this.stack.stackSize += (mouse.isShift()) ? 16 : 1; - if (this.stack.stackSize > this.stack.getMaxStackSize()) { - this.stack.stackSize = this.stack.getMaxStackSize(); + + int maxSize = availableSlots < 0 ? 64 : Math.min(64, this.stack.getMaxStackSize() * availableSlots); + if (this.stack.stackSize > maxSize) { + this.stack.stackSize = maxSize; } } else { this.stack.stackSize -= (mouse.isShift()) ? 16 : 1; @@ -46,8 +56,10 @@ public class StatementParameterItemStackExact implements IStatementParameter { if (this.stack != null) { if (mouse.getButton() == 0) { this.stack.stackSize += (mouse.isShift()) ? 16 : 1; - if (this.stack.stackSize > this.stack.getMaxStackSize()) { - this.stack.stackSize = this.stack.getMaxStackSize(); + + int maxSize = availableSlots < 0 ? 64 : Math.min(64, this.stack.getMaxStackSize() * availableSlots); + if (this.stack.stackSize > maxSize) { + this.stack.stackSize = maxSize; } } else { this.stack.stackSize -= (mouse.isShift()) ? 16 : 1; @@ -66,10 +78,15 @@ public class StatementParameterItemStackExact implements IStatementParameter { stack.writeToNBT(tagCompound); compound.setTag("stack", tagCompound); } + + compound.setInteger("availableSlots", availableSlots); } @Override public void readFromNBT(NBTTagCompound compound) { + if (compound.hasKey("availableSlots")) { + availableSlots = compound.getInteger("availableSlots"); + } stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack")); } diff --git a/common/buildcraft/robotics/EntityRobot.java b/common/buildcraft/robotics/EntityRobot.java index 1309968f..77439e6d 100644 --- a/common/buildcraft/robotics/EntityRobot.java +++ b/common/buildcraft/robotics/EntityRobot.java @@ -104,10 +104,11 @@ public class EntityRobot extends EntityRobotBase implements public static final ResourceLocation ROBOT_BASE = new ResourceLocation( DefaultProps.TEXTURE_PATH_ROBOTS + "/robot_base.png"); public static final int MAX_WEARABLES = 8; + public static final int TRANSFER_INV_SLOTS = 4; private static Set blacklistedItemsForUpdate = Sets.newHashSet(); - public LaserData laser = new LaserData(); + public LaserData laser = new LaserData(); public DockingStation linkedDockingStation; public BlockIndex linkedDockingStationIndex; public ForgeDirection linkedDockingStationSide; @@ -131,7 +132,7 @@ public class EntityRobot extends EntityRobotBase implements private List wearables = new ArrayList(); private boolean needsUpdate = false; - private ItemStack[] inv = new ItemStack[4]; + private ItemStack[] inv = new ItemStack[TRANSFER_INV_SLOTS]; private FluidStack tank; private int maxFluid = FluidContainerRegistry.BUCKET_VOLUME * 4; private ResourceLocation texture; diff --git a/common/buildcraft/robotics/ai/AIRobotDeliverRequested.java b/common/buildcraft/robotics/ai/AIRobotDeliverRequested.java index 992a8c52..0a770808 100755 --- a/common/buildcraft/robotics/ai/AIRobotDeliverRequested.java +++ b/common/buildcraft/robotics/ai/AIRobotDeliverRequested.java @@ -53,25 +53,32 @@ public class AIRobotDeliverRequested extends AIRobot { return; } - IInvSlot slot = InvUtils.getItem(robot, new ArrayStackOrListFilter(requested.getStack())); - - if (slot == null) { - setSuccess(false); - terminate(); - return; - } - IRequestProvider requester = requested.getRequester(robot.worldObj); if (requester == null) { setSuccess(false); terminate(); return; } - ItemStack newStack = requester.offerItem(requested.getSlot(), slot.getStackInSlot().copy()); - if (newStack == null || newStack.stackSize != slot.getStackInSlot().stackSize) { - slot.setStackInSlot(newStack); + // TODO: Make this not exceed the requested amount of items. + + int count = 0; + + for (IInvSlot slot : InvUtils.getItems(robot, new ArrayStackOrListFilter(requested.getStack()))) { + int difference = slot.getStackInSlot().stackSize; + ItemStack newStack = requester.offerItem(requested.getSlot(), slot.getStackInSlot().copy()); + + if (newStack == null) { + slot.setStackInSlot(newStack); + } else if (newStack.stackSize != slot.getStackInSlot().stackSize) { + slot.setStackInSlot(newStack); + difference = newStack.stackSize - difference; + } + + count += difference; } + + setSuccess(count > 0); terminate(); } } diff --git a/common/buildcraft/robotics/statements/ActionStationRequestItems.java b/common/buildcraft/robotics/statements/ActionStationRequestItems.java index 08669a2e..2242096c 100755 --- a/common/buildcraft/robotics/statements/ActionStationRequestItems.java +++ b/common/buildcraft/robotics/statements/ActionStationRequestItems.java @@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import buildcraft.api.statements.IStatementParameter; import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.statements.StatementParameterItemStackExact; +import buildcraft.robotics.EntityRobot; public class ActionStationRequestItems extends ActionStationInputItems { @@ -42,6 +43,6 @@ public class ActionStationRequestItems extends ActionStationInputItems { @Override public IStatementParameter createParameter(int index) { - return new StatementParameterItemStackExact(); + return new StatementParameterItemStackExact(EntityRobot.TRANSFER_INV_SLOTS); } }