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;
import java.util.List;
import net.minecraft.entity.Entity;
/**
* An interface applied to Armbots.
*
@ -7,5 +11,5 @@ package assemblyline.api;
*/
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.
*
* @param tileEntity the TileEntityArmbot that is using this IUseable
* @param heldEntity the Entity being held by the ArmBot, or null if there is none
* @return whether or not the "use" did anything
* @param armbot - The Armbot instance.
*/
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
public void onTaskStart()
{
times = 0;
curTimes = 0;
this.times = 0;
this.curTimes = 0;
if (this.getArgs().length > 0)
{
times = this.getIntArg(0);
this.times = this.getIntArg(0);
}
if (times <= 0)
times = 1;
if (this.times <= 0)
this.times = 1;
}
@Override
protected boolean doTask()
{
TileEntity handTile = this.tileEntity.getHandPosition().getTileEntity(this.world);
Entity handEntity = null;
if (this.tileEntity.grabbedEntities.size() > 0)
handEntity = this.tileEntity.grabbedEntities.get(0);
if (handTile != null)
TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity(this.world);
if (targetTile != 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 true;

View file

@ -449,9 +449,13 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
* @return
*/
@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)
{
@ -462,7 +466,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{
this.setInventorySlotContents(3, stack);
this.onInventoryChanged();
tileEntity.grabbedEntities.remove(0);
armbotTile.grabbedEntities.remove(0);
return true;
}
else if (this.getStackInSlot(3) != null && stack != null)
@ -501,8 +505,8 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
{
stack.stackSize += result.stackSize;
this.onInventoryChanged();
tileEntity.grabbedEntities.remove(0);
tileEntity.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
armbotTile.grabbedEntities.remove(0);
armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
return true;
}
}
@ -541,10 +545,11 @@ public class TileEntityImprinter extends TileEntityAdvanced implements ISidedInv
}
}
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 false;
}