From 6419ced007f6a413d6885239dc8ddd41cf0364bb Mon Sep 17 00:00:00 2001 From: Rseifert Date: Thu, 31 Jan 2013 04:20:04 -0500 Subject: [PATCH] Worked on Commands Tried to correct the place and break command. As well as created a Harvest commands that auto grabs the block after breaking it. However, there seem to be a few bugs left over that i will have to correct later. --- .../common/machine/command/Command.java | 1 + .../common/machine/command/CommandBreak.java | 51 +++++++++++++++++-- .../machine/command/CommandHarvest.java | 26 ++++++++++ .../common/machine/command/CommandPlace.java | 10 +++- 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/minecraft/assemblyline/common/machine/command/CommandHarvest.java diff --git a/src/minecraft/assemblyline/common/machine/command/Command.java b/src/minecraft/assemblyline/common/machine/command/Command.java index f76efe7ae..d3ac5fc8d 100644 --- a/src/minecraft/assemblyline/common/machine/command/Command.java +++ b/src/minecraft/assemblyline/common/machine/command/Command.java @@ -35,6 +35,7 @@ public abstract class Command registerCommand("fire", CommandFire.class); registerCommand("break", CommandBreak.class); registerCommand("place", CommandPlace.class); + registerCommand("harvest", CommandHarvest.class); } public static void registerCommand(String command, Class commandClass) diff --git a/src/minecraft/assemblyline/common/machine/command/CommandBreak.java b/src/minecraft/assemblyline/common/machine/command/CommandBreak.java index 52afc3381..d18127636 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandBreak.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandBreak.java @@ -1,7 +1,12 @@ package assemblyline.common.machine.command; +import java.util.ArrayList; + import net.minecraft.block.Block; import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; import universalelectricity.core.vector.Vector3; /** @@ -13,6 +18,9 @@ public class CommandBreak extends Command { private CommandRotateTo rotateToCommand; + int BREAK_TIME = 30; + boolean keep = false; + @Override protected boolean doTask() { @@ -22,14 +30,49 @@ public class CommandBreak extends Command Block block = Block.blocksList[serachPosition.getBlockID(this.world)]; - if (block != null) + if (block != null && BREAK_TIME <= this.ticks) { - block.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(this.world), 0); + ArrayList items = block.getBlockDropped(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata(world), 0); + if (!keep || items.size() > 1) + { + this.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); + } + else + { + this.tileEntity.grabbedEntities.add(new EntityItem(world, (double) serachPosition.intX() + 0.5D, (double) serachPosition.intY() + 0.5D, (double) serachPosition.intZ() + 0.5D, items.get(0))); + } serachPosition.setBlockWithNotify(this.world, 0); - return false; + return true; } + /** + * Notes on break command Beds Break Wrong Multi blocks don't work + */ + return false; + } - return true; + protected void dropBlockAsItem_do(World world, int x, int y, int z, ItemStack stack) + { + if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) + { + EntityItem entity = new EntityItem(world, (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, stack); + entity.delayBeforeCanPickup = 10; + world.spawnEntityInWorld(entity); + } + } + + public void dropBlockAsItem(World world, int x, int y, int z) + { + if (!world.isRemote) + { + int meta = world.getBlockMetadata(x, y, z); + int id = world.getBlockId(x, y, z); + ArrayList items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0); + + for (ItemStack item : items) + { + this.dropBlockAsItem_do(world, x, y, z, item); + } + } } @Override diff --git a/src/minecraft/assemblyline/common/machine/command/CommandHarvest.java b/src/minecraft/assemblyline/common/machine/command/CommandHarvest.java new file mode 100644 index 000000000..1f667a71f --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/command/CommandHarvest.java @@ -0,0 +1,26 @@ +package assemblyline.common.machine.command; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import universalelectricity.core.vector.Vector3; + +/** + * Used by arms to break a specific block in a position. + * + * @author Calclavia + */ +public class CommandHarvest extends CommandBreak +{ + private CommandRotateTo rotateToCommand; + @Override + public void onTaskStart() + { + this.keep = true; + } + + @Override + public String toString() + { + return "HARVEST"; + } +} diff --git a/src/minecraft/assemblyline/common/machine/command/CommandPlace.java b/src/minecraft/assemblyline/common/machine/command/CommandPlace.java index 601978ba4..04ae1c063 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandPlace.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandPlace.java @@ -16,6 +16,14 @@ import universalelectricity.core.vector.Vector3; */ public class CommandPlace extends Command { + int PLACE_TIME = 30; + + @Override + public void onTaskStart() + { + super.onTaskStart(); + } + @Override protected boolean doTask() { @@ -25,7 +33,7 @@ public class CommandPlace extends Command Block block = Block.blocksList[serachPosition.getBlockID(this.world)]; - if (block == null) + if (block == null && ticks >= this.PLACE_TIME) { for (Entity entity : this.tileEntity.grabbedEntities) {