Armbot API Improvements

This commit is contained in:
Henry Mao 2013-02-02 16:07:37 +08:00
parent cc12121975
commit 39aa469436
5 changed files with 104 additions and 93 deletions

View file

@ -1,5 +1,9 @@
package assemblyline.api; package assemblyline.api;
import java.util.List;
import net.minecraft.entity.Entity;
/** /**
* An interface applied to Armbots. * An interface applied to Armbots.
* *
@ -7,5 +11,5 @@ package assemblyline.api;
*/ */
public interface IArmbot public interface IArmbot
{ {
public List<Entity> getGrabbedEntities();
} }

View file

@ -14,10 +14,8 @@ public interface IArmbotUseable
/** /**
* Called when the ArmBot command "USE" is run. This is called on any IUseable the ArmBot is touching. * Called when the ArmBot command "USE" is run. This is called on any IUseable the ArmBot is touching.
* *
* @param tileEntity the TileEntityArmbot that is using this IUseable * @param armbot - The Armbot instance.
* @param heldEntity the Entity being held by the ArmBot, or null if there is none
* @return whether or not the "use" did anything
*/ */
public boolean onUse(IArmbot tileEntity, Entity heldEntity); public boolean onUse(IArmbot armbot);
} }

View file

@ -866,4 +866,10 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
} }
} }
@Override
public List<Entity> getGrabbedEntities()
{
return this.grabbedEntities;
}
} }

View file

@ -13,36 +13,34 @@ public class CommandUse extends Command
@Override @Override
public void onTaskStart() public void onTaskStart()
{ {
times = 0; this.times = 0;
curTimes = 0; this.curTimes = 0;
if (this.getArgs().length > 0) if (this.getArgs().length > 0)
{ {
times = this.getIntArg(0); this.times = this.getIntArg(0);
} }
if (times <= 0) if (this.times <= 0)
times = 1; this.times = 1;
} }
@Override @Override
protected boolean doTask() protected boolean doTask()
{ {
TileEntity handTile = this.tileEntity.getHandPosition().getTileEntity(this.world); TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world);
Entity handEntity = null;
if (this.tileEntity.grabbedEntities.size() > 0) if (targetTile != null)
handEntity = this.tileEntity.grabbedEntities.get(0);
if (handTile != null)
{ {
if (handTile instanceof IArmbotUseable) if (targetTile instanceof IArmbotUseable)
{ {
((IArmbotUseable) handTile).onUse(this.tileEntity, handEntity); ((IArmbotUseable) targetTile).onUse(this.tileEntity);
} }
} }
curTimes++; this.curTimes++;
if (curTimes >= times) if (this.curTimes >= this.times)
return false; return false;
return true; return true;

View file

@ -449,9 +449,13 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
* @return * @return
*/ */
@Override @Override
public boolean onUse(IArmbot iArmbot, Entity heldEntity) public boolean onUse(IArmbot armbot)
{ {
TileEntityArmbot tileEntity = (TileEntityArmbot) iArmbot; TileEntityArmbot armbotTile = (TileEntityArmbot) armbot;
if (armbotTile.getGrabbedEntities().size() > 0)
{
Entity heldEntity = armbot.getGrabbedEntities().get(0);
if (heldEntity != null) if (heldEntity != null)
{ {
@ -462,7 +466,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{ {
this.setInventorySlotContents(3, stack); this.setInventorySlotContents(3, stack);
this.onInventoryChanged(); this.onInventoryChanged();
tileEntity.grabbedEntities.remove(0); armbotTile.grabbedEntities.remove(0);
return true; return true;
} }
else if (this.getStackInSlot(3) != null && stack != null) else if (this.getStackInSlot(3) != null && stack != null)
@ -501,8 +505,8 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{ {
stack.stackSize += result.stackSize; stack.stackSize += result.stackSize;
this.onInventoryChanged(); this.onInventoryChanged();
tileEntity.grabbedEntities.remove(0); armbotTile.grabbedEntities.remove(0);
tileEntity.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack)); armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
return true; return true;
} }
} }
@ -541,10 +545,11 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
} }
} }
this.onInventoryChanged(); this.onInventoryChanged();
tileEntity.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, result)); armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, result));
return true; return true;
} }
} }
}
return false; return false;
} }