From 990c58fef78a39eea1a8d355b6ddaf83529d82af Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 3 Nov 2012 11:18:44 +0800 Subject: [PATCH] More AI additions --- src/common/assemblyline/ALCommonProxy.java | 5 -- src/common/assemblyline/AssemblyLine.java | 31 +++++------ src/common/assemblyline/ai/Task.java | 36 +++++++------ src/common/assemblyline/ai/TileEntityAI.java | 51 +++++++++++++++++++ .../machines/crafter/ContainerCrafter.java | 2 +- 5 files changed, 83 insertions(+), 42 deletions(-) create mode 100644 src/common/assemblyline/ai/TileEntityAI.java diff --git a/src/common/assemblyline/ALCommonProxy.java b/src/common/assemblyline/ALCommonProxy.java index cc657b1be..d40feefa3 100644 --- a/src/common/assemblyline/ALCommonProxy.java +++ b/src/common/assemblyline/ALCommonProxy.java @@ -21,11 +21,6 @@ public class ALCommonProxy implements IGuiHandler } - public void postInit() - { - - } - @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { diff --git a/src/common/assemblyline/AssemblyLine.java b/src/common/assemblyline/AssemblyLine.java index dd78cd587..339e2035e 100644 --- a/src/common/assemblyline/AssemblyLine.java +++ b/src/common/assemblyline/AssemblyLine.java @@ -68,33 +68,30 @@ public class AssemblyLine @Init public void load(FMLInitializationEvent evt) { + proxy.init(); + GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ConveyorBelt"); GameRegistry.registerTileEntity(TileEntitySorter.class, "Sorter"); 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 - public void postInit(FMLPostInitializationEvent event) - { + // Add Names + 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 - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt), new Object[] - { "III", "MCM", 'I', Item.ingotIron, 'M', "motor", 'C', "basicCircuit" })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 2), new Object[] + { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" })); // 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" })); // 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" })); - proxy.postInit(); } - } \ No newline at end of file diff --git a/src/common/assemblyline/ai/Task.java b/src/common/assemblyline/ai/Task.java index 1ef4991d7..b1f5853e0 100644 --- a/src/common/assemblyline/ai/Task.java +++ b/src/common/assemblyline/ai/Task.java @@ -13,40 +13,38 @@ public abstract class Task { 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. * * @param ticks - * - The amount of ticks this task + * The amount of ticks this task * 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++; + return true; } - public void resetTask() + public void onTaskStart() + { + + } + + public void onTaskEnd() { } + + public abstract void setTileEntity(TileEntity tileEntity); /** - * @return Whether the task should keep - * executing. + * @return The tick interval of this task. + * Return 0 for no ticks. */ - public boolean shouldExecute() + public int getTickInterval() { - return this.shouldExecute; + return 1; } } diff --git a/src/common/assemblyline/ai/TileEntityAI.java b/src/common/assemblyline/ai/TileEntityAI.java new file mode 100644 index 000000000..d3d134255 --- /dev/null +++ b/src/common/assemblyline/ai/TileEntityAI.java @@ -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 tasks = new ArrayList(); + + 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); + } +} diff --git a/src/common/assemblyline/machines/crafter/ContainerCrafter.java b/src/common/assemblyline/machines/crafter/ContainerCrafter.java index e84a2ad83..57e6e95b3 100644 --- a/src/common/assemblyline/machines/crafter/ContainerCrafter.java +++ b/src/common/assemblyline/machines/crafter/ContainerCrafter.java @@ -46,7 +46,7 @@ public class ContainerCrafter extends Container @Override public boolean canInteractWith(EntityPlayer par1EntityPlayer) { - return this.tileEntity.isUseableByPlayer(par1EntityPlayer); + return true; } /**