diff --git a/src/minecraft/assemblyline/common/armbot/command/Command.java b/src/minecraft/assemblyline/common/armbot/command/Command.java index 418831658..40f3f4e55 100644 --- a/src/minecraft/assemblyline/common/armbot/command/Command.java +++ b/src/minecraft/assemblyline/common/armbot/command/Command.java @@ -37,6 +37,7 @@ public abstract class Command registerCommand("break", CommandBreak.class); registerCommand("place", CommandPlace.class); registerCommand("harvest", CommandHarvest.class); + registerCommand("take", CommandTake.class); } public static void registerCommand(String command, Class commandClass) diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandTake.java b/src/minecraft/assemblyline/common/armbot/command/CommandTake.java new file mode 100644 index 000000000..bd1c34fad --- /dev/null +++ b/src/minecraft/assemblyline/common/armbot/command/CommandTake.java @@ -0,0 +1,99 @@ +package assemblyline.common.armbot.command; + +import net.minecraft.block.Block; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import dark.library.machine.crafting.AutoCraftingManager; + +public class CommandTake extends Command +{ + private ItemStack stack; + + @Override + public void onTaskStart() + { + int id = 0; + int meta = 32767; + int count = 1; + + if (this.getArgs().length > 0) + { + id = this.getIntArg(0); + } + if (this.getArgs().length > 1) + { + count = this.getIntArg(1); + } + if (this.getArgs().length > 2) + { + meta = this.getIntArg(2); + } + if (id == 0) + { + stack = null; + } + else + { + stack = new ItemStack(id, count, meta); + } + } + + @Override + protected boolean doTask() + { + TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world); + ForgeDirection direction = this.tileEntity.getFacingDirectionFromAngle(); + if (targetTile != null && this.tileEntity.getGrabbedItems().size() <= 0) + { + if (targetTile instanceof ISidedInventory) + { + ISidedInventory inventory = (ISidedInventory) targetTile; + int[] slots = inventory.getAccessibleSlotsFromSide(direction.getOpposite().ordinal()); + for (int i = 0; i < slots.length; i++) + { + ItemStack slotStack = inventory.getStackInSlot(slots[i]); + if (this.stack != null) + { + if (AutoCraftingManager.areStacksEqual(this.stack, slotStack) && inventory.canExtractItem(slots[i], this.stack, direction.getOpposite().ordinal())) + { + this.stack.stackSize = Math.min(this.stack.stackSize, slotStack.stackSize); + this.tileEntity.grabItem(this.stack); + inventory.setInventorySlotContents(slots[i], AutoCraftingManager.decrStackSize(slotStack, this.stack.stackSize)); + return false; + } + } + } + }//TODO add a way to steal items from players + + } + return true; + } + + @Override + public String toString() + { + return "Take " + (stack != null ? stack.toString() : "1x???@???"); + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) + { + super.readFromNBT(taskCompound); + this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item")); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) + { + super.writeToNBT(taskCompound); + if (stack != null) + { + NBTTagCompound tag = new NBTTagCompound(); + this.stack.writeToNBT(tag); + taskCompound.setTag("item", tag); + } + } +} diff --git a/src/minecraft/assemblyline/common/armbot/command/CommandUse.java b/src/minecraft/assemblyline/common/armbot/command/CommandUse.java index f819478d2..6ab7ae188 100644 --- a/src/minecraft/assemblyline/common/armbot/command/CommandUse.java +++ b/src/minecraft/assemblyline/common/armbot/command/CommandUse.java @@ -38,18 +38,6 @@ public class CommandUse extends Command { ((IArmbotUseable) targetTile).onUse(this.tileEntity, this.getArgs()); } - else if (targetTile instanceof ISidedInventory) - { - // TODO add IInventory side behavior for placing and taking items. - if (tileEntity.getGrabbedEntities().size() > 0) - { - // add items to inv - } - else - { - // remove items from inv - } - } } else if (block != null)