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,100 +449,105 @@ 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 (heldEntity != null) if (armbotTile.getGrabbedEntities().size() > 0)
{ {
if (heldEntity instanceof EntityItem) Entity heldEntity = armbot.getGrabbedEntities().get(0);
if (heldEntity != null)
{ {
ItemStack stack = ((EntityItem) heldEntity).getEntityItem(); if (heldEntity instanceof EntityItem)
if (this.getStackInSlot(3) == null && stack != null && stack.itemID == AssemblyLine.itemImprint.itemID)
{ {
this.setInventorySlotContents(3, stack); ItemStack stack = ((EntityItem) heldEntity).getEntityItem();
this.onInventoryChanged(); if (this.getStackInSlot(3) == null && stack != null && stack.itemID == AssemblyLine.itemImprint.itemID)
tileEntity.grabbedEntities.remove(0);
return true;
}
else if (this.getStackInSlot(3) != null && stack != null)
{
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{ {
result = this.getStackInSlot(4); this.setInventorySlotContents(3, stack);
if (stack.isItemEqual(result)) this.onInventoryChanged();
armbotTile.grabbedEntities.remove(0);
return true;
}
else if (this.getStackInSlot(3) != null && stack != null)
{
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{ {
if (result != null) result = this.getStackInSlot(4);
if (stack.isItemEqual(result))
{ {
ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone(); if (result != null)
if (requiredItems != null)
{ {
for (ItemStack searchStack : requiredItems) ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone();
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null) if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{ {
if (searchStack.isItemEqual(checkStack)) ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{ {
this.decrStackSize(i, 1); if (searchStack.isItemEqual(checkStack))
break; {
this.decrStackSize(i, 1);
break;
}
} }
} }
} }
} }
} }
} if (stack.isStackable())
if (stack.isStackable())
{
stack.stackSize += result.stackSize;
this.onInventoryChanged();
tileEntity.grabbedEntities.remove(0);
tileEntity.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
return true;
}
}
}
}
}
}
else
{
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{
result = this.getStackInSlot(4);
if (result != null)
{
ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{ {
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0)) stack.stackSize += result.stackSize;
{ this.onInventoryChanged();
this.decrStackSize(i, 1); armbotTile.grabbedEntities.remove(0);
break; armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, stack));
} return true;
} }
} }
} }
} }
} }
this.onInventoryChanged(); }
tileEntity.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, result)); else
return true; {
ItemStack result = this.getStackInSlot(4); // crafting result
if (result != null)
{
result = this.getStackInSlot(4);
if (result != null)
{
ItemStack[] requiredItems = this.getIdealRecipe(result).getValue().clone();
if (requiredItems != null)
{
for (ItemStack searchStack : requiredItems)
{
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack checkStack = this.getStackInSlot(i);
if (checkStack != null)
{
if (searchStack.isItemEqual(checkStack) || (searchStack.itemID == checkStack.itemID && searchStack.getItemDamage() < 0))
{
this.decrStackSize(i, 1);
break;
}
}
}
}
}
}
this.onInventoryChanged();
armbotTile.grabbedEntities.add(new EntityItem(this.worldObj, this.xCoord, this.yCoord, this.zCoord, result));
return true;
}
} }
} }