More AI additions

This commit is contained in:
Calclavia 2012-11-03 11:18:44 +08:00
parent 38a391c496
commit 990c58fef7
5 changed files with 83 additions and 42 deletions

View file

@ -21,11 +21,6 @@ public class ALCommonProxy implements IGuiHandler
} }
public void postInit()
{
}
@Override @Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{ {

View file

@ -68,33 +68,30 @@ public class AssemblyLine
@Init @Init
public void load(FMLInitializationEvent evt) public void load(FMLInitializationEvent evt)
{ {
proxy.init();
GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ConveyorBelt"); GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ConveyorBelt");
GameRegistry.registerTileEntity(TileEntitySorter.class, "Sorter"); GameRegistry.registerTileEntity(TileEntitySorter.class, "Sorter");
GameRegistry.registerTileEntity(TileEntityManipulator.class, "Manipulator"); GameRegistry.registerTileEntity(TileEntityManipulator.class, "Manipulator");
proxy.init();
// Names
LanguageRegistry.addName(new ItemStack(blockConveyorBelt, 1), "Conveyor Belt");
LanguageRegistry.addName(new ItemStack(blockInteraction, 1, MachineType.SORTER.metadata), MachineType.SORTER.name);
LanguageRegistry.addName(new ItemStack(blockInteraction, 1, MachineType.MANIPULATOR.metadata), MachineType.MANIPULATOR.name);
LanguageRegistry.addName(new ItemStack(blockInteraction, 1, 8), "FutureBlock");
LanguageRegistry.addName(new ItemStack(blockInteraction, 1, 12), "FutureBlock");
}
@PostInit // Add Names
public void postInit(FMLPostInitializationEvent event) LanguageRegistry.addName(new ItemStack(blockConveyorBelt, 1), "Conveyor Belt");
{
for(MachineType type : MachineType.values())
{
LanguageRegistry.addName(new ItemStack(blockInteraction, 1, type.metadata), type.name);
}
// Conveyor Belt // Conveyor Belt
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt), new Object[] GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 2), new Object[]
{ "III", "MCM", 'I', Item.ingotIron, 'M', "motor", 'C', "basicCircuit" })); { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" }));
// Rejector // Rejector
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockInteraction, 1, 0), new Object[] GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockInteraction, 1, MachineType.SORTER.metadata), new Object[]
{ "WPW", "@R@", '@', "plateSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" })); { "WPW", "@R@", '@', "plateSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" }));
// Retriever // Retriever
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockInteraction, 1, 4), new Object[] GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockInteraction, 1, MachineType.MANIPULATOR.metadata), new Object[]
{ Block.dispenser, "basicCircuit" })); { Block.dispenser, "basicCircuit" }));
proxy.postInit();
} }
} }

View file

@ -13,40 +13,38 @@ public abstract class Task
{ {
protected int ticks; protected int ticks;
/**
* The TileEntity that is doing this task.
*/
public TileEntity handler;
private boolean shouldExecute = true;
public Task(TileEntity handler)
{
this.handler = handler;
}
/** /**
* Called when a task is being done. * Called when a task is being done.
* *
* @param ticks * @param ticks
* - The amount of ticks this task * The amount of ticks this task
* has been elapsed for. * has been elapsed for.
* @return Return true if the task is not
* finished and false if it is.
*/ */
protected void doTask() protected boolean doTask()
{ {
this.ticks++; this.ticks++;
return true;
} }
public void resetTask() public void onTaskStart()
{
}
public void onTaskEnd()
{ {
} }
public abstract void setTileEntity(TileEntity tileEntity);
/** /**
* @return Whether the task should keep * @return The tick interval of this task.
* executing. * Return 0 for no ticks.
*/ */
public boolean shouldExecute() public int getTickInterval()
{ {
return this.shouldExecute; return 1;
} }
} }

View file

@ -0,0 +1,51 @@
package assemblyline.ai;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.common.FMLLog;
import universalelectricity.prefab.TileEntityAdvanced;
public class TileEntityAI extends TileEntityAdvanced
{
private final List<Task> tasks = new ArrayList<Task>();
public void updateEntity()
{
super.updateEntity();
/**
* Loop through each task and do them.
*/
try
{
for (Task task : this.tasks)
{
if (task.getTickInterval() > 0)
{
if (this.ticks % task.getTickInterval() == 0)
{
if (!task.doTask())
{
task.onTaskEnd();
tasks.remove(task);
}
}
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to execute task in Assembly Line.");
e.printStackTrace();
}
}
public void addTask(Task task)
{
task.setTileEntity(this);
task.onTaskStart();
tasks.add(task);
}
}

View file

@ -46,7 +46,7 @@ public class ContainerCrafter extends Container
@Override @Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer) public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{ {
return this.tileEntity.isUseableByPlayer(par1EntityPlayer); return true;
} }
/** /**