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,47 +13,45 @@ 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;
}
@Override
public String toString()
{
return "USE " + Integer.toString(this.times);
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
{
@ -61,7 +59,7 @@ public class CommandUse extends Command
this.times = taskCompound.getInteger("useTimes");
this.curTimes = taskCompound.getInteger("useCurTimes");
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
{

View file

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