connected builder robots to filler urbanist
This commit is contained in:
parent
880fc11c4f
commit
95cb00fe91
10 changed files with 255 additions and 48 deletions
|
@ -38,7 +38,7 @@ public class EntityRobotUrbanism extends EntityRobot {
|
||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
task.work(this);
|
task.update(this);
|
||||||
|
|
||||||
if (task.done()) {
|
if (task.done()) {
|
||||||
task = null;
|
task = null;
|
||||||
|
|
|
@ -9,36 +9,41 @@
|
||||||
package buildcraft.builders.urbanism;
|
package buildcraft.builders.urbanism;
|
||||||
|
|
||||||
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
||||||
|
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
|
||||||
import buildcraft.builders.urbanism.TileUrbanist.FrameTask;
|
import buildcraft.builders.urbanism.TileUrbanist.FrameTask;
|
||||||
|
import buildcraft.core.robots.AIMoveAround;
|
||||||
|
import buildcraft.core.robots.EntityRobot;
|
||||||
|
import buildcraft.core.robots.IRobotTask;
|
||||||
|
|
||||||
public class UrbanistTaskBuildSchematic extends UrbanistTask {
|
public class TaskBuildSchematic implements IRobotTask {
|
||||||
|
|
||||||
SchematicBuilder builder;
|
SchematicBuilder builder;
|
||||||
boolean inBuild = false;
|
boolean inBuild = false;
|
||||||
FrameTask task;
|
FrameTask task;
|
||||||
|
|
||||||
public UrbanistTaskBuildSchematic (TileUrbanist urbanist, SchematicBuilder builder, FrameTask task) {
|
public TaskBuildSchematic (SchematicBuilder builder, FrameTask task) {
|
||||||
super (urbanist);
|
|
||||||
|
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(EntityRobotUrbanism robot) {
|
public void setup(EntityRobot robot) {
|
||||||
//robot.setDestinationAround(builder.getX(), builder.getY(), builder.getZ());
|
robot.currentAI = new AIMoveAround(robot, builder.getX(), builder.getY(), builder.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void work(EntityRobotUrbanism robot) {
|
public void update(EntityRobot robot) {
|
||||||
if (!inBuild && robot.getDistance(builder.getX(), builder.getY(), builder.getZ()) <= 10) {
|
if (!inBuild && robot.getDistance(builder.getX(), builder.getY(), builder.getZ()) <= 15) {
|
||||||
inBuild = true;
|
inBuild = true;
|
||||||
|
robot.setLaserDestination(builder.getX(), builder.getY(), builder.getZ());
|
||||||
|
robot.showLaser();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBuild) {
|
if (inBuild) {
|
||||||
//if (builder.build(robot)) {
|
if (builder.build((IBlueprintBuilderAgent) robot)) {
|
||||||
// task.taskDone();
|
task.taskDone();
|
||||||
//}
|
robot.hideLaser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,12 @@ import buildcraft.core.network.NetworkData;
|
||||||
import buildcraft.core.network.RPC;
|
import buildcraft.core.network.RPC;
|
||||||
import buildcraft.core.network.RPCHandler;
|
import buildcraft.core.network.RPCHandler;
|
||||||
import buildcraft.core.network.RPCSide;
|
import buildcraft.core.network.RPCSide;
|
||||||
|
import buildcraft.core.robots.EntityRobot;
|
||||||
|
import buildcraft.core.robots.IRobotTask;
|
||||||
|
import buildcraft.core.robots.IRobotTaskProvider;
|
||||||
|
import buildcraft.core.robots.RobotTaskProviderRegistry;
|
||||||
|
|
||||||
public class TileUrbanist extends TileBuildCraft implements IInventory {
|
public class TileUrbanist extends TileBuildCraft implements IInventory, IRobotTaskProvider {
|
||||||
|
|
||||||
public EntityUrbanist urbanist;
|
public EntityUrbanist urbanist;
|
||||||
EntityLivingBase player;
|
EntityLivingBase player;
|
||||||
|
@ -45,7 +49,9 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
@NetworkData
|
@NetworkData
|
||||||
public ArrayList <AnchoredBox> frames = new ArrayList <AnchoredBox> ();
|
public ArrayList <AnchoredBox> frames = new ArrayList <AnchoredBox> ();
|
||||||
|
|
||||||
LinkedList <UrbanistTask> tasks = new LinkedList <UrbanistTask> ();
|
boolean isCreatingFrame = false;
|
||||||
|
|
||||||
|
LinkedList <IRobotTask> tasks = new LinkedList <IRobotTask> ();
|
||||||
|
|
||||||
public void createUrbanistEntity() {
|
public void createUrbanistEntity() {
|
||||||
if (worldObj.isRemote) {
|
if (worldObj.isRemote) {
|
||||||
|
@ -98,6 +104,7 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
@RPC (RPCSide.BOTH)
|
@RPC (RPCSide.BOTH)
|
||||||
public void createFrame (int x, int y, int z) {
|
public void createFrame (int x, int y, int z) {
|
||||||
|
isCreatingFrame = true;
|
||||||
AnchoredBox a = new AnchoredBox();
|
AnchoredBox a = new AnchoredBox();
|
||||||
a.box = new Box (x + 0.5F, y + 0.5F, z + 0.5F, x + 0.5F, y + 2.5F, z + 0.5F);
|
a.box = new Box (x + 0.5F, y + 0.5F, z + 0.5F, x + 0.5F, y + 2.5F, z + 0.5F);
|
||||||
a.x1 = x + 0.5F;
|
a.x1 = x + 0.5F;
|
||||||
|
@ -119,8 +126,11 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
@RPC (RPCSide.BOTH)
|
@RPC (RPCSide.BOTH)
|
||||||
public void moveFrame (int x, int y, int z) {
|
public void moveFrame (int x, int y, int z) {
|
||||||
if (frames.size() > 0) {
|
if (isCreatingFrame) {
|
||||||
frames.get(frames.size() - 1).setP2(x + 0.5F, y + 0.5F, z + 0.5F);
|
if (frames.size() > 0) {
|
||||||
|
frames.get(frames.size() - 1).setP2(x + 0.5F, y + 0.5F,
|
||||||
|
z + 0.5F);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +166,6 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
AnchoredBox b = frames.get(id);
|
AnchoredBox b = frames.get(id);
|
||||||
|
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
System.out.println ("SWITCH " + id + " TO " + kind);
|
|
||||||
b.kind = Kind.values()[kind];
|
b.kind = Kind.values()[kind];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,25 +177,17 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
List <SchematicBuilder> schematics = builder.getBuilders();
|
List <SchematicBuilder> schematics = builder.getBuilders();
|
||||||
|
|
||||||
/*if (frame != null) {
|
|
||||||
frame.setDead();
|
|
||||||
frame = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityFrame newFrame = new EntityFrame(worldObj, box);
|
|
||||||
newFrame.setKind(Kind.STRIPES);
|
|
||||||
worldObj.spawnEntityInWorld(newFrame);
|
|
||||||
*/
|
|
||||||
|
|
||||||
FrameTask task = new FrameTask();
|
FrameTask task = new FrameTask();
|
||||||
task.frame = frames.get(frames.size() - 1);
|
task.frame = frames.get(frames.size() - 1);
|
||||||
task.frame.kind = Kind.STRIPES;
|
task.frame.kind = Kind.STRIPES;
|
||||||
RPCHandler.rpcBroadcastPlayers(this, "setFrameKind", frames.size() - 1,
|
RPCHandler.rpcBroadcastPlayers(this, "setFrameKind", frames.size() - 1,
|
||||||
Kind.STRIPES.ordinal());
|
Kind.STRIPES.ordinal());
|
||||||
|
|
||||||
|
isCreatingFrame = false;
|
||||||
|
|
||||||
for (SchematicBuilder b : schematics) {
|
for (SchematicBuilder b : schematics) {
|
||||||
if (!b.isComplete()) {
|
if (!b.isComplete()) {
|
||||||
tasks.add(new UrbanistTaskBuildSchematic(this, b, task));
|
tasks.add(new TaskBuildSchematic(b, task));
|
||||||
task.nbOfTasks++;
|
task.nbOfTasks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,4 +327,46 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
||||||
frames.add(b);
|
frames.add(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getX() {
|
||||||
|
return xCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getY() {
|
||||||
|
return yCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getZ() {
|
||||||
|
return zCoord;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return !isInvalid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IRobotTask getNextTask(EntityRobot robot) {
|
||||||
|
if (tasks.size() > 0) {
|
||||||
|
return tasks.getFirst();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void popNextTask() {
|
||||||
|
tasks.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize () {
|
||||||
|
if (!worldObj.isRemote) {
|
||||||
|
RobotTaskProviderRegistry.registerProvider(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,10 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.builders.urbanism;
|
package buildcraft.builders.urbanism;
|
||||||
|
|
||||||
public class UrbanistTask {
|
import buildcraft.core.robots.EntityRobot;
|
||||||
|
import buildcraft.core.robots.IRobotTask;
|
||||||
|
|
||||||
|
public class UrbanistTask implements IRobotTask {
|
||||||
|
|
||||||
protected TileUrbanist urbanist;
|
protected TileUrbanist urbanist;
|
||||||
|
|
||||||
|
@ -16,14 +19,17 @@ public class UrbanistTask {
|
||||||
this.urbanist = urbanist;
|
this.urbanist = urbanist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(EntityRobotUrbanism robot) {
|
@Override
|
||||||
|
public void setup(EntityRobot robot) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void work(EntityRobotUrbanism robot) {
|
@Override
|
||||||
|
public void update(EntityRobot robot) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean done() {
|
public boolean done() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.builders.urbanism;
|
package buildcraft.builders.urbanism;
|
||||||
|
|
||||||
|
import buildcraft.core.robots.EntityRobot;
|
||||||
|
|
||||||
public class UrbanistTaskErase extends UrbanistTask {
|
public class UrbanistTaskErase extends UrbanistTask {
|
||||||
|
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
@ -23,12 +25,12 @@ public class UrbanistTaskErase extends UrbanistTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(EntityRobotUrbanism robot) {
|
public void setup(EntityRobot robot) {
|
||||||
//robot.setDestinationAround(x, y, z);
|
//robot.setDestinationAround(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void work(EntityRobotUrbanism robot) {
|
public void update(EntityRobot robot) {
|
||||||
if (!inBreak && robot.getDistance(x, y, z) <= 10) {
|
if (!inBreak && robot.getDistance(x, y, z) <= 10) {
|
||||||
inBreak = true;
|
inBreak = true;
|
||||||
robot.setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F);
|
robot.setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
import buildcraft.api.core.SafeTimeTracker;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.LaserData;
|
import buildcraft.core.LaserData;
|
||||||
import buildcraft.transport.TileGenericPipe;
|
import buildcraft.transport.TileGenericPipe;
|
||||||
|
@ -23,6 +24,8 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||||
public class EntityRobot extends EntityLivingBase implements
|
public class EntityRobot extends EntityLivingBase implements
|
||||||
IEntityAdditionalSpawnData {
|
IEntityAdditionalSpawnData {
|
||||||
|
|
||||||
|
public SafeTimeTracker scanForTasks = new SafeTimeTracker (40, 10);
|
||||||
|
|
||||||
public LaserData laser = new LaserData ();
|
public LaserData laser = new LaserData ();
|
||||||
private boolean needsUpdate = false;
|
private boolean needsUpdate = false;
|
||||||
|
|
||||||
|
@ -31,6 +34,7 @@ public class EntityRobot extends EntityLivingBase implements
|
||||||
+ "/robot_base.png");
|
+ "/robot_base.png");
|
||||||
|
|
||||||
public AIBase currentAI;
|
public AIBase currentAI;
|
||||||
|
public IRobotTask currentTask;
|
||||||
|
|
||||||
public class DockingStation {
|
public class DockingStation {
|
||||||
public int x, y, z;
|
public int x, y, z;
|
||||||
|
@ -100,14 +104,15 @@ public class EntityRobot extends EntityLivingBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showLaser () {
|
public void showLaser () {
|
||||||
if (laser != null && !laser.isVisible) {
|
if (!laser.isVisible) {
|
||||||
|
System.out.println ("SHOW LASER");
|
||||||
laser.isVisible = true;
|
laser.isVisible = true;
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideLaser () {
|
public void hideLaser () {
|
||||||
if (laser != null && laser.isVisible) {
|
if (laser.isVisible) {
|
||||||
laser.isVisible = false;
|
laser.isVisible = false;
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -128,6 +133,21 @@ public class EntityRobot extends EntityLivingBase implements
|
||||||
currentAI.update(this);
|
currentAI.update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!worldObj.isRemote) {
|
||||||
|
if (currentTask == null) {
|
||||||
|
if (scanForTasks.markTimeIfDelay(worldObj)) {
|
||||||
|
System.out.println ("SCAN");
|
||||||
|
RobotTaskProviderRegistry.scanForTask(this);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currentTask.done()) {
|
||||||
|
currentTask = null;
|
||||||
|
} else {
|
||||||
|
currentTask.update(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.onUpdate();
|
super.onUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,4 +304,8 @@ public class EntityRobot extends EntityLivingBase implements
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean acceptTask (IRobotTask task) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,19 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
|
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
|
||||||
|
import buildcraft.builders.urbanism.TaskBuildSchematic;
|
||||||
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||||
|
|
||||||
public class EntityRobotBuilder extends EntityRobot implements
|
public class EntityRobotBuilder extends EntityRobot implements
|
||||||
IEntityAdditionalSpawnData, IBlueprintBuilderAgent, IInventory {
|
IEntityAdditionalSpawnData, IBlueprintBuilderAgent, IInventory {
|
||||||
|
|
||||||
|
private static ResourceLocation texture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png");
|
||||||
|
|
||||||
ItemStack buildingStack = null;
|
ItemStack buildingStack = null;
|
||||||
float curBlockDamage = 0;
|
float curBlockDamage = 0;
|
||||||
float buildEnergy = 0;
|
float buildEnergy = 0;
|
||||||
|
@ -115,61 +120,57 @@ public class EntityRobotBuilder extends EntityRobot implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int i) {
|
public ItemStack getStackInSlotOnClosing(int i) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markDirty() {
|
public void markDirty() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory() {
|
||||||
// TODO Auto-generated method stub
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptTask (IRobotTask task) {
|
||||||
|
return task instanceof TaskBuildSchematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getTexture () {
|
||||||
|
return texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
common/buildcraft/core/robots/IRobotTask.java
Executable file
19
common/buildcraft/core/robots/IRobotTask.java
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.core.robots;
|
||||||
|
|
||||||
|
public interface IRobotTask {
|
||||||
|
|
||||||
|
public void setup(EntityRobot robot);
|
||||||
|
|
||||||
|
public void update(EntityRobot robot);
|
||||||
|
|
||||||
|
public boolean done();
|
||||||
|
|
||||||
|
}
|
47
common/buildcraft/core/robots/IRobotTaskProvider.java
Executable file
47
common/buildcraft/core/robots/IRobotTaskProvider.java
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.core.robots;
|
||||||
|
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Objects able to provide tasks to robots. They should be registered by
|
||||||
|
* #RobotTaskProviderRegistry
|
||||||
|
*/
|
||||||
|
public interface IRobotTaskProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Robots will pick up tasks that are provided within a certain range.
|
||||||
|
* These can be coming from e.g. tile entities or entities.
|
||||||
|
*/
|
||||||
|
public double getX ();
|
||||||
|
public double getY ();
|
||||||
|
public double getZ ();
|
||||||
|
public World getWorld ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the provider is not active, it will be eventually removed from the
|
||||||
|
* list of potential providers.
|
||||||
|
*/
|
||||||
|
public boolean isActive ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next task that can be given to the robot in parameter. This
|
||||||
|
* is a first level of filter. The robot may or may not decide to pick up
|
||||||
|
* the task.
|
||||||
|
*/
|
||||||
|
public IRobotTask getNextTask (EntityRobot robot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called once a task has been accepted, to be removed from the
|
||||||
|
* list of available tasks.
|
||||||
|
*/
|
||||||
|
public void popNextTask ();
|
||||||
|
|
||||||
|
}
|
60
common/buildcraft/core/robots/RobotTaskProviderRegistry.java
Executable file
60
common/buildcraft/core/robots/RobotTaskProviderRegistry.java
Executable file
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.core.robots;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class RobotTaskProviderRegistry {
|
||||||
|
|
||||||
|
private static ArrayList<IRobotTaskProvider> providers = new ArrayList<IRobotTaskProvider>();
|
||||||
|
|
||||||
|
public static void registerProvider (IRobotTaskProvider provider) {
|
||||||
|
providers.add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int callNb = 0;
|
||||||
|
|
||||||
|
public static void scanForTask (EntityRobot robot) {
|
||||||
|
callNb++;
|
||||||
|
|
||||||
|
if (callNb >= 31 /*prime number, could be bigger */) {
|
||||||
|
Collections.shuffle (providers);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = providers.size() - 1; i >= 0; --i) {
|
||||||
|
if (!providers.get(i).isActive()) {
|
||||||
|
providers.remove(i);
|
||||||
|
} else {
|
||||||
|
IRobotTaskProvider provider = providers.get(i);
|
||||||
|
|
||||||
|
if (provider.getWorld() == robot.worldObj) {
|
||||||
|
double dx = robot.posX - provider.getX();
|
||||||
|
double dy = robot.posY - provider.getY();
|
||||||
|
double dz = robot.posZ - provider.getZ();
|
||||||
|
|
||||||
|
// TODO: 30 blocks is the current magic constant for robot
|
||||||
|
// task scan. Could be variable instead.
|
||||||
|
if (dx * dx + dy * dy + dz * dz < 30 * 30) {
|
||||||
|
IRobotTask task = provider.getNextTask(robot);
|
||||||
|
|
||||||
|
if (task != null && robot.acceptTask(task)) {
|
||||||
|
robot.currentTask = task;
|
||||||
|
task.setup(robot);
|
||||||
|
provider.popNextTask();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue