Added more task related classes

This commit is contained in:
Calclavia 2012-11-03 12:15:29 +08:00
parent bd78faab1f
commit 57f8a12c6d
6 changed files with 143 additions and 12 deletions

View file

@ -0,0 +1,14 @@
package assemblyline.ai;
import net.minecraft.src.TileEntity;
public class TaskIdle extends Task
{
private TileEntity tileEntity;
@Override
public void setTileEntity(TileEntity tileEntity)
{
this.tileEntity = tileEntity;
}
}

View file

@ -10,6 +10,11 @@ public class TaskManager
{ {
private final List<Task> tasks = new ArrayList<Task>(); private final List<Task> tasks = new ArrayList<Task>();
private int ticks = 0;
/**
* Must be called every tick by a tileEntity.
*/
public void onUpdate() public void onUpdate()
{ {
/** /**
@ -37,8 +42,10 @@ public class TaskManager
FMLLog.severe("Failed to execute task in Assembly Line."); FMLLog.severe("Failed to execute task in Assembly Line.");
e.printStackTrace(); e.printStackTrace();
} }
this.ticks++;
} }
public void addTask(TileEntity tileEntity, Task task) public void addTask(TileEntity tileEntity, Task task)
{ {
task.setTileEntity(tileEntity); task.setTileEntity(tileEntity);

View file

@ -0,0 +1,49 @@
package assemblyline.machines.crafter;
import net.minecraft.src.EntityItem;
import net.minecraft.src.TileEntity;
import assemblyline.ai.Task;
/**
* Used by arms to collect items in a specific
* region.
*
* @author Calclavia
*/
public class TaskArmCollect extends Task
{
private TileEntityCraftingArm tileEntity;
/**
* The item to be collected.
*/
private EntityItem entityItem;
public TaskArmCollect(EntityItem entityItem)
{
this.entityItem = entityItem;
}
@Override
protected boolean doTask()
{
super.doTask();
if(entityItem == null)
{
return false;
}
/**
* Slowly stretch down the arm's model and grab the item
*/
return true;
}
@Override
public void setTileEntity(TileEntity tileEntity)
{
this.tileEntity = (TileEntityCraftingArm) tileEntity;
}
}

View file

@ -0,0 +1,66 @@
package assemblyline.machines.crafter;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Entity;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import assemblyline.ai.Task;
/**
* Used by arms to search for entities in a region
*
* @author Calclavia
*/
public class TaskArmSearch extends Task
{
private TileEntityCraftingArm tileEntity;
/**
* The item to be collected.
*/
private Class<? extends Entity> entityToInclude;
private float searchSpeed;
private World worldObj;
private double radius;
private Entity foundEntity;
public TaskArmSearch(Class<? extends Entity> entityToInclude, double radius, float searchSpeed)
{
this.entityToInclude = entityToInclude;
this.radius = radius;
this.searchSpeed = searchSpeed;
}
@Override
public void onTaskStart()
{
this.foundEntity = (Entity) this.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(this.tileEntity.xCoord - this.radius, this.tileEntity.yCoord - this.radius, this.tileEntity.zCoord - this.radius, this.tileEntity.xCoord + this.radius, this.tileEntity.yCoord + this.radius, this.tileEntity.zCoord + this.radius)).get(0);
}
@Override
protected boolean doTask()
{
super.doTask();
if (this.entityToInclude == null || this.foundEntity == null) { return false; }
/**
* Move the robotic arm around and emulate
* an item search. Then initiate a collect task.
*/
return true;
}
@Override
public void setTileEntity(TileEntity tileEntity)
{
this.tileEntity = (TileEntityCraftingArm) tileEntity;
this.worldObj = this.tileEntity.worldObj;
}
}

View file

@ -11,6 +11,7 @@ import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.TileEntityElectricityReceiver; import universalelectricity.prefab.TileEntityElectricityReceiver;
import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.IPacketReceiver;
import assemblyline.ai.TaskManager;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
@ -21,11 +22,8 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
*/ */
protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()]; protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()];
public enum armTasks private TaskManager taskManager = new TaskManager();
{
NONE, COLLECT, MINE, PLACE, SORT, CRAFT
}
/** /**
* Entity robotic arm to be used with this * Entity robotic arm to be used with this
* tileEntity * tileEntity
@ -41,10 +39,6 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
* does this arm have a task to do * does this arm have a task to do
*/ */
public boolean hasTask = true; public boolean hasTask = true;
/**
* what kind of task this arm should do
*/
public armTasks task = armTasks.NONE;
private int playerUsing = 0; private int playerUsing = 0;
@ -52,6 +46,8 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
{ {
super.updateEntity(); super.updateEntity();
taskManager.onUpdate();
if (this.ticks % 5 == 0 && !this.isDisabled() && this.hasTask && EntityArm != null) if (this.ticks % 5 == 0 && !this.isDisabled() && this.hasTask && EntityArm != null)
{ {
this.jouleReceived -= this.wattUsed; this.jouleReceived -= this.wattUsed;
@ -110,7 +106,6 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
@Override @Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{ {
// TODO Auto-generated method stub
} }

View file

@ -106,6 +106,6 @@ public class GuiSorter extends GuiContainer
{ {
this.drawTexturedModalRect(containerWidth + 17 + i * 18, containerHeight + 17, 176, +(tileEntity.guiButtons[i] ? 12 : 0), 12, 12); this.drawTexturedModalRect(containerWidth + 17 + i * 18, containerHeight + 17, 176, +(tileEntity.guiButtons[i] ? 12 : 0), 12, 12);
} }
this.fontRenderer.drawString("Reject: " + (tileEntity.guiButtons[0] ? "Inv" : "Other"), containerWidth + 108, containerHeight + 22, 4210752); this.fontRenderer.drawString((tileEntity.guiButtons[0] ? "Inv" : "Other"), containerWidth + 108, containerHeight + 22, 4210752);
} }
} }