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.
This commit is contained in:
Rseifert 2013-01-31 04:20:04 -05:00
parent 8861f49c01
commit 6419ced007
4 changed files with 83 additions and 5 deletions

View file

@ -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<? extends Command> commandClass)

View file

@ -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<ItemStack> 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 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<ItemStack> items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0);
for (ItemStack item : items)
{
this.dropBlockAsItem_do(world, x, y, z, item);
}
}
}
@Override

View file

@ -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";
}
}

View file

@ -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)
{