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 (task != null) {
|
||||
task.work(this);
|
||||
task.update(this);
|
||||
|
||||
if (task.done()) {
|
||||
task = null;
|
||||
|
|
|
@ -9,36 +9,41 @@
|
|||
package buildcraft.builders.urbanism;
|
||||
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
|
||||
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;
|
||||
boolean inBuild = false;
|
||||
FrameTask task;
|
||||
|
||||
public UrbanistTaskBuildSchematic (TileUrbanist urbanist, SchematicBuilder builder, FrameTask task) {
|
||||
super (urbanist);
|
||||
|
||||
public TaskBuildSchematic (SchematicBuilder builder, FrameTask task) {
|
||||
this.builder = builder;
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup(EntityRobotUrbanism robot) {
|
||||
//robot.setDestinationAround(builder.getX(), builder.getY(), builder.getZ());
|
||||
public void setup(EntityRobot robot) {
|
||||
robot.currentAI = new AIMoveAround(robot, builder.getX(), builder.getY(), builder.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void work(EntityRobotUrbanism robot) {
|
||||
if (!inBuild && robot.getDistance(builder.getX(), builder.getY(), builder.getZ()) <= 10) {
|
||||
public void update(EntityRobot robot) {
|
||||
if (!inBuild && robot.getDistance(builder.getX(), builder.getY(), builder.getZ()) <= 15) {
|
||||
inBuild = true;
|
||||
robot.setLaserDestination(builder.getX(), builder.getY(), builder.getZ());
|
||||
robot.showLaser();
|
||||
}
|
||||
|
||||
if (inBuild) {
|
||||
//if (builder.build(robot)) {
|
||||
// task.taskDone();
|
||||
//}
|
||||
if (builder.build((IBlueprintBuilderAgent) robot)) {
|
||||
task.taskDone();
|
||||
robot.hideLaser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,12 @@ import buildcraft.core.network.NetworkData;
|
|||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
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;
|
||||
EntityLivingBase player;
|
||||
|
@ -45,7 +49,9 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
@NetworkData
|
||||
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() {
|
||||
if (worldObj.isRemote) {
|
||||
|
@ -98,6 +104,7 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
|
||||
@RPC (RPCSide.BOTH)
|
||||
public void createFrame (int x, int y, int z) {
|
||||
isCreatingFrame = true;
|
||||
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.x1 = x + 0.5F;
|
||||
|
@ -119,8 +126,11 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
|
||||
@RPC (RPCSide.BOTH)
|
||||
public void moveFrame (int x, int y, int z) {
|
||||
if (frames.size() > 0) {
|
||||
frames.get(frames.size() - 1).setP2(x + 0.5F, y + 0.5F, z + 0.5F);
|
||||
if (isCreatingFrame) {
|
||||
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);
|
||||
|
||||
if (b != null) {
|
||||
System.out.println ("SWITCH " + id + " TO " + kind);
|
||||
b.kind = Kind.values()[kind];
|
||||
}
|
||||
}
|
||||
|
@ -168,25 +177,17 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
|
||||
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();
|
||||
task.frame = frames.get(frames.size() - 1);
|
||||
task.frame.kind = Kind.STRIPES;
|
||||
RPCHandler.rpcBroadcastPlayers(this, "setFrameKind", frames.size() - 1,
|
||||
Kind.STRIPES.ordinal());
|
||||
|
||||
isCreatingFrame = false;
|
||||
|
||||
for (SchematicBuilder b : schematics) {
|
||||
if (!b.isComplete()) {
|
||||
tasks.add(new UrbanistTaskBuildSchematic(this, b, task));
|
||||
tasks.add(new TaskBuildSchematic(b, task));
|
||||
task.nbOfTasks++;
|
||||
}
|
||||
}
|
||||
|
@ -326,4 +327,46 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
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;
|
||||
|
||||
public class UrbanistTask {
|
||||
import buildcraft.core.robots.EntityRobot;
|
||||
import buildcraft.core.robots.IRobotTask;
|
||||
|
||||
public class UrbanistTask implements IRobotTask {
|
||||
|
||||
protected TileUrbanist urbanist;
|
||||
|
||||
|
@ -16,14 +19,17 @@ public class UrbanistTask {
|
|||
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() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
*/
|
||||
package buildcraft.builders.urbanism;
|
||||
|
||||
import buildcraft.core.robots.EntityRobot;
|
||||
|
||||
public class UrbanistTaskErase extends UrbanistTask {
|
||||
|
||||
int x, y, z;
|
||||
|
@ -23,12 +25,12 @@ public class UrbanistTaskErase extends UrbanistTask {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setup(EntityRobotUrbanism robot) {
|
||||
public void setup(EntityRobot robot) {
|
||||
//robot.setDestinationAround(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void work(EntityRobotUrbanism robot) {
|
||||
public void update(EntityRobot robot) {
|
||||
if (!inBreak && robot.getDistance(x, y, z) <= 10) {
|
||||
inBreak = true;
|
||||
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.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.LaserData;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
|
@ -23,6 +24,8 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
|||
public class EntityRobot extends EntityLivingBase implements
|
||||
IEntityAdditionalSpawnData {
|
||||
|
||||
public SafeTimeTracker scanForTasks = new SafeTimeTracker (40, 10);
|
||||
|
||||
public LaserData laser = new LaserData ();
|
||||
private boolean needsUpdate = false;
|
||||
|
||||
|
@ -31,6 +34,7 @@ public class EntityRobot extends EntityLivingBase implements
|
|||
+ "/robot_base.png");
|
||||
|
||||
public AIBase currentAI;
|
||||
public IRobotTask currentTask;
|
||||
|
||||
public class DockingStation {
|
||||
public int x, y, z;
|
||||
|
@ -100,14 +104,15 @@ public class EntityRobot extends EntityLivingBase implements
|
|||
}
|
||||
|
||||
public void showLaser () {
|
||||
if (laser != null && !laser.isVisible) {
|
||||
if (!laser.isVisible) {
|
||||
System.out.println ("SHOW LASER");
|
||||
laser.isVisible = true;
|
||||
needsUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void hideLaser () {
|
||||
if (laser != null && laser.isVisible) {
|
||||
if (laser.isVisible) {
|
||||
laser.isVisible = false;
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
@ -128,6 +133,21 @@ public class EntityRobot extends EntityLivingBase implements
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -284,4 +304,8 @@ public class EntityRobot extends EntityLivingBase implements
|
|||
// TODO Auto-generated method stub
|
||||
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.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.builders.blueprints.IBlueprintBuilderAgent;
|
||||
import buildcraft.builders.urbanism.TaskBuildSchematic;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
|
||||
public class EntityRobotBuilder extends EntityRobot implements
|
||||
IEntityAdditionalSpawnData, IBlueprintBuilderAgent, IInventory {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png");
|
||||
|
||||
ItemStack buildingStack = null;
|
||||
float curBlockDamage = 0;
|
||||
float buildEnergy = 0;
|
||||
|
@ -115,61 +120,57 @@ public class EntityRobotBuilder extends EntityRobot implements
|
|||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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…
Add table
Reference in a new issue