From bdda0fb4762bab0ce04ddfd3e77fd821b6a3d4f0 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Tue, 10 Jun 2014 00:22:22 +0200 Subject: [PATCH] Refactored Robot AI system into smaller units. --- .../api/boards/IRedstoneBoardRobot.java | 16 -- .../api/boards/RedstoneBoardNBT.java | 4 +- .../api/boards/RedstoneBoardRobot.java | 29 +++ .../api/boards/RedstoneBoardRobotNBT.java | 6 +- api/buildcraft/robots/AIRobot.java | 65 +++++ api/buildcraft/robots/EntityRobotBase.java | 42 ++++ .../builders/urbanism/TaskBuildSchematic.java | 4 +- common/buildcraft/core/ItemRobot.java | 16 +- .../core/robots/AIRobotGoToDock.java | 49 ++++ ...otAIReturnToDock.java => AIRobotMain.java} | 15 +- .../buildcraft/core/robots/AIRobotMove.java | 49 ++++ .../core/robots/AIRobotMoveToBlock.java | 97 ++++++++ ...MoveTo.java => AIRobotStraightMoveTo.java} | 33 ++- .../buildcraft/core/robots/EntityRobot.java | 84 +++++-- .../buildcraft/core/robots/RobotAIBase.java | 91 ------- .../core/robots/RobotAIComposite.java | 49 ---- .../buildcraft/core/robots/RobotAIDocked.java | 36 --- .../core/robots/RobotAIGoToDock.java | 27 -- .../core/robots/RobotAIMoveAround.java | 87 ------- .../buildcraft/core/robots/RobotAIMoveTo.java | 99 -------- .../core/robots/boards/AIRobotCutWood.java | 114 +++++++++ .../core/robots/boards/AIRobotFetchAxe.java | 83 +++++++ .../core/robots/boards/AIRobotFetchItem.java | 108 ++++++++ .../core/robots/boards/AIRobotGoToWood.java | 60 +++++ .../robots/boards/BoardRobotLumberjack.java | 233 ++---------------- .../boards/BoardRobotLumberjackNBT.java | 7 +- .../core/robots/boards/BoardRobotPicker.java | 185 +++++--------- .../robots/boards/BoardRobotPickerNBT.java | 7 +- .../transport/BlockGenericPipe.java | 3 +- 29 files changed, 882 insertions(+), 816 deletions(-) delete mode 100755 api/buildcraft/api/boards/IRedstoneBoardRobot.java create mode 100755 api/buildcraft/api/boards/RedstoneBoardRobot.java create mode 100755 api/buildcraft/robots/AIRobot.java create mode 100755 api/buildcraft/robots/EntityRobotBase.java create mode 100755 common/buildcraft/core/robots/AIRobotGoToDock.java rename common/buildcraft/core/robots/{RobotAIReturnToDock.java => AIRobotMain.java} (56%) create mode 100755 common/buildcraft/core/robots/AIRobotMove.java create mode 100755 common/buildcraft/core/robots/AIRobotMoveToBlock.java rename common/buildcraft/core/robots/{RobotAIDirectMoveTo.java => AIRobotStraightMoveTo.java} (58%) delete mode 100755 common/buildcraft/core/robots/RobotAIBase.java delete mode 100755 common/buildcraft/core/robots/RobotAIComposite.java delete mode 100755 common/buildcraft/core/robots/RobotAIDocked.java delete mode 100755 common/buildcraft/core/robots/RobotAIGoToDock.java delete mode 100755 common/buildcraft/core/robots/RobotAIMoveAround.java delete mode 100755 common/buildcraft/core/robots/RobotAIMoveTo.java create mode 100755 common/buildcraft/core/robots/boards/AIRobotCutWood.java create mode 100755 common/buildcraft/core/robots/boards/AIRobotFetchAxe.java create mode 100755 common/buildcraft/core/robots/boards/AIRobotFetchItem.java create mode 100755 common/buildcraft/core/robots/boards/AIRobotGoToWood.java diff --git a/api/buildcraft/api/boards/IRedstoneBoardRobot.java b/api/buildcraft/api/boards/IRedstoneBoardRobot.java deleted file mode 100755 index 05ba0e44..00000000 --- a/api/buildcraft/api/boards/IRedstoneBoardRobot.java +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 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.api.boards; - -public interface IRedstoneBoardRobot extends IRedstoneBoard { - - @Override - RedstoneBoardRobotNBT getNBTHandler(); - -} diff --git a/api/buildcraft/api/boards/RedstoneBoardNBT.java b/api/buildcraft/api/boards/RedstoneBoardNBT.java index cfbcdd60..3caa597a 100755 --- a/api/buildcraft/api/boards/RedstoneBoardNBT.java +++ b/api/buildcraft/api/boards/RedstoneBoardNBT.java @@ -23,7 +23,7 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.common.util.Constants; -public abstract class RedstoneBoardNBT { +public abstract class RedstoneBoardNBT { private static Random rand = new Random(); @@ -31,7 +31,7 @@ public abstract class RedstoneBoardNBT { public abstract void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced); - public abstract IRedstoneBoard create(NBTTagCompound nbt); + public abstract IRedstoneBoard create(NBTTagCompound nbt, T object); @SideOnly(Side.CLIENT) public abstract void registerIcons(IIconRegister iconRegister); diff --git a/api/buildcraft/api/boards/RedstoneBoardRobot.java b/api/buildcraft/api/boards/RedstoneBoardRobot.java new file mode 100755 index 00000000..97e4fc5c --- /dev/null +++ b/api/buildcraft/api/boards/RedstoneBoardRobot.java @@ -0,0 +1,29 @@ +/** + * 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.api.boards; + +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; + +public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoard { + + public RedstoneBoardRobot(EntityRobotBase iRobot) { + super(iRobot); + } + + @Override + public abstract RedstoneBoardRobotNBT getNBTHandler(); + + @Override + public final void updateBoard(EntityRobotBase container) { + // TODO Auto-generated method stub + + } + +} diff --git a/api/buildcraft/api/boards/RedstoneBoardRobotNBT.java b/api/buildcraft/api/boards/RedstoneBoardRobotNBT.java index 45bdff99..234a30e7 100755 --- a/api/buildcraft/api/boards/RedstoneBoardRobotNBT.java +++ b/api/buildcraft/api/boards/RedstoneBoardRobotNBT.java @@ -11,10 +11,12 @@ package buildcraft.api.boards; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; -public abstract class RedstoneBoardRobotNBT extends RedstoneBoardNBT { +import buildcraft.robots.EntityRobotBase; + +public abstract class RedstoneBoardRobotNBT extends RedstoneBoardNBT { @Override - public abstract IRedstoneBoardRobot create(NBTTagCompound nbt); + public abstract RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase object); public abstract ResourceLocation getRobotTexture(); diff --git a/api/buildcraft/robots/AIRobot.java b/api/buildcraft/robots/AIRobot.java new file mode 100755 index 00000000..eae5140d --- /dev/null +++ b/api/buildcraft/robots/AIRobot.java @@ -0,0 +1,65 @@ + +package buildcraft.robots; + +public class AIRobot { + public EntityRobotBase robot; + + private AIRobot delegateAI; + private AIRobot parentAI; + + public AIRobot(EntityRobotBase iRobot) { + robot = iRobot; + } + + public void start() { + + } + + public void preempt() { + + } + + public void update() { + + } + + public void end() { + + } + + public void delegateAIEnded(AIRobot ai) { + + } + + public final void terminate() { + abortDelegateAI(); + end(); + + if (parentAI != null) { + parentAI.delegateAI = null; + parentAI.delegateAIEnded(this); + } + } + + public final void cycle() { + preempt(); + + if (delegateAI != null) { + delegateAI.cycle(); + } else { + update(); + } + } + + public final void startDelegateAI(AIRobot ai) { + delegateAI = ai; + ai.parentAI = this; + delegateAI.start(); + } + + public final void abortDelegateAI() { + if (delegateAI != null) { + delegateAI.terminate(); + } + } +} diff --git a/api/buildcraft/robots/EntityRobotBase.java b/api/buildcraft/robots/EntityRobotBase.java new file mode 100755 index 00000000..c1bd262d --- /dev/null +++ b/api/buildcraft/robots/EntityRobotBase.java @@ -0,0 +1,42 @@ +/** + * 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.robots; + +import net.minecraft.entity.EntityLiving; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import buildcraft.api.boards.RedstoneBoardRobot; + +public abstract class EntityRobotBase extends EntityLiving implements IInventory { + + public EntityRobotBase(World par1World) { + super(par1World); + } + + public abstract void setItemInUse(ItemStack stack); + + public abstract ItemStack getItemInUse(); + + public abstract void setItemActive(boolean b); + + public abstract boolean isMoving(); + + public abstract void setCurrentDockingStation(DockingStation station); + + public abstract DockingStation getCurrentDockingStation(); + + public abstract DockingStation getMainDockingStation(); + + public abstract RedstoneBoardRobot getBoard(); + + public abstract void setItemAngles(float a1, float a2); + +} diff --git a/common/buildcraft/builders/urbanism/TaskBuildSchematic.java b/common/buildcraft/builders/urbanism/TaskBuildSchematic.java index 3eb743ca..b1113652 100755 --- a/common/buildcraft/builders/urbanism/TaskBuildSchematic.java +++ b/common/buildcraft/builders/urbanism/TaskBuildSchematic.java @@ -12,7 +12,6 @@ import buildcraft.builders.urbanism.TileUrbanist.FrameTask; import buildcraft.core.blueprints.BuildingSlotBlock; import buildcraft.core.robots.EntityRobot; import buildcraft.core.robots.IRobotTask; -import buildcraft.core.robots.RobotAIMoveAround; public class TaskBuildSchematic implements IRobotTask { @@ -27,7 +26,8 @@ public class TaskBuildSchematic implements IRobotTask { @Override public void setup(EntityRobot robot) { - robot.setMainAI(new RobotAIMoveAround(robot, builder.x, builder.y, builder.z)); + // robot.setMainAI(new RobotAIMoveAround(robot, builder.x, builder.y, + // builder.z)); } @Override diff --git a/common/buildcraft/core/ItemRobot.java b/common/buildcraft/core/ItemRobot.java index 14882550..d311506a 100755 --- a/common/buildcraft/core/ItemRobot.java +++ b/common/buildcraft/core/ItemRobot.java @@ -17,9 +17,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import buildcraft.api.boards.IRedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardNBT; import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.core.robots.EntityRobot; import buildcraft.core.utils.NBTUtils; @@ -32,19 +32,11 @@ public class ItemRobot extends ItemBuildCraft { public EntityRobot createRobot(ItemStack stack, World world) { try { - IRedstoneBoardRobot board = null; + RedstoneBoardRobot board = null; NBTTagCompound nbt = NBTUtils.getItemData(stack); - if (nbt.hasKey("board")) { - NBTTagCompound boardCpt = nbt.getCompoundTag("board"); - RedstoneBoardNBT boardNBT = RedstoneBoardRegistry.instance.getRedstoneBoard(boardCpt); - - if (boardNBT instanceof RedstoneBoardRobotNBT) { - board = ((RedstoneBoardRobotNBT) boardNBT).create(boardCpt); - } - } - - EntityRobot robot = new EntityRobot(world, board); + NBTTagCompound boardCpt = nbt.getCompoundTag("board"); + EntityRobot robot = new EntityRobot(world, boardCpt); return robot; } catch (Throwable e) { diff --git a/common/buildcraft/core/robots/AIRobotGoToDock.java b/common/buildcraft/core/robots/AIRobotGoToDock.java new file mode 100755 index 00000000..4a74364d --- /dev/null +++ b/common/buildcraft/core/robots/AIRobotGoToDock.java @@ -0,0 +1,49 @@ +/** + * 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 buildcraft.robots.AIRobot; +import buildcraft.robots.DockingStation; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotGoToDock extends AIRobot { + + private DockingStation station; + + public AIRobotGoToDock(EntityRobotBase iRobot, DockingStation iStation) { + super(iRobot); + + station = iStation; + } + + @Override + public void start() { + if (station == robot.getCurrentDockingStation()) { + terminate(); + } else { + startDelegateAI(new AIRobotMoveToBlock(robot, + station.pipe.xCoord + station.side.offsetX * 2, + station.pipe.yCoord + station.side.offsetY * 2, + station.pipe.zCoord + station.side.offsetZ * 2)); + } + } + + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotMoveToBlock) { + startDelegateAI(new AIRobotStraightMoveTo(robot, + station.pipe.xCoord + 0.5F + station.side.offsetX * 0.5F, + station.pipe.yCoord + 0.5F + station.side.offsetY * 0.5F, + station.pipe.zCoord + 0.5F + station.side.offsetZ * 0.5F)); + } else { + robot.setCurrentDockingStation(station); + terminate(); + } + } +} diff --git a/common/buildcraft/core/robots/RobotAIReturnToDock.java b/common/buildcraft/core/robots/AIRobotMain.java similarity index 56% rename from common/buildcraft/core/robots/RobotAIReturnToDock.java rename to common/buildcraft/core/robots/AIRobotMain.java index 5eff8bb2..f3d49284 100755 --- a/common/buildcraft/core/robots/RobotAIReturnToDock.java +++ b/common/buildcraft/core/robots/AIRobotMain.java @@ -8,9 +8,18 @@ */ package buildcraft.core.robots; -public class RobotAIReturnToDock extends RobotAIGoToDock { +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; - public RobotAIReturnToDock(EntityRobot iRobot) { - super(iRobot, iRobot.mainDockingStation); +public class AIRobotMain extends AIRobot { + + public AIRobotMain(EntityRobotBase iRobot) { + super(iRobot); } + + @Override + public void start() { + startDelegateAI(robot.getBoard()); + } + } diff --git a/common/buildcraft/core/robots/AIRobotMove.java b/common/buildcraft/core/robots/AIRobotMove.java new file mode 100755 index 00000000..429ad7e8 --- /dev/null +++ b/common/buildcraft/core/robots/AIRobotMove.java @@ -0,0 +1,49 @@ +/** + * 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 buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; + +public abstract class AIRobotMove extends AIRobot { + + protected float nextX, nextY, nextZ; + protected double dirX, dirY, dirZ; + + public AIRobotMove(EntityRobotBase iRobot) { + super(iRobot); + } + + protected void setDestination(EntityRobotBase robot, float x, float y, float z) { + nextX = x; + nextY = y; + nextZ = z; + + dirX = nextX - robot.posX; + dirY = nextY - robot.posY; + dirZ = nextZ - robot.posZ; + + double magnitude = Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ); + + if (magnitude != 0) { + dirX /= magnitude; + dirY /= magnitude; + dirZ /= magnitude; + } else { + dirX = 0; + dirY = 0; + dirZ = 0; + } + + robot.motionX = dirX / 10F; + robot.motionY = dirY / 10F; + robot.motionZ = dirZ / 10F; + } + +} diff --git a/common/buildcraft/core/robots/AIRobotMoveToBlock.java b/common/buildcraft/core/robots/AIRobotMoveToBlock.java new file mode 100755 index 00000000..6c31e06c --- /dev/null +++ b/common/buildcraft/core/robots/AIRobotMoveToBlock.java @@ -0,0 +1,97 @@ +/** + * 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.LinkedList; + +import buildcraft.core.BlockIndex; +import buildcraft.core.utils.PathFinding; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotMoveToBlock extends AIRobotMove { + + private PathFinding pathSearch; + private LinkedList path; + private double prevDistance = Double.MAX_VALUE; + + private float finalX, finalY, finalZ; + + public AIRobotMoveToBlock(EntityRobotBase robot, int x, int y, int z) { + super(robot); + finalX = x; + finalY = y; + finalZ = z; + } + + public AIRobotMoveToBlock(EntityRobotBase robot, LinkedList iPath) { + super(robot); + path = iPath; + finalX = path.getLast().x; + finalY = path.getLast().y; + finalZ = path.getLast().z; + setNextInPath(); + } + + @Override + public void start() { + robot.setCurrentDockingStation(null); + + if (path == null) { + pathSearch = new PathFinding(robot.worldObj, new BlockIndex((int) Math.floor(robot.posX), + (int) Math.floor(robot.posY), (int) Math.floor(robot.posZ)), new BlockIndex( + (int) Math.floor(finalX), (int) Math.floor(finalY), (int) Math.floor(finalZ))); + } + } + + @Override + public void update() { + if (path != null) { + double distance = robot.getDistance(nextX, nextY, nextZ); + + if (!robot.isMoving() || distance > prevDistance) { + if (path.size() > 0) { + path.removeFirst(); + } + + setNextInPath(); + } else { + prevDistance = robot.getDistance(nextX, nextY, nextZ); + } + } else { + pathSearch.iterate(PathFinding.PATH_ITERATIONS); + + if (pathSearch.isDone()) { + path = pathSearch.getResult(); + setNextInPath(); + } + } + + if (path != null && path.size() == 0) { + terminate(); + } + } + + private void setNextInPath() { + if (path.size() > 0) { + BlockIndex next = path.getFirst(); + setDestination(robot, next.x + 0.5F, next.y + 0.5F, next.z + 0.5F); + prevDistance = Double.MAX_VALUE; + } + } + + @Override + public void end() { + robot.motionX = 0; + robot.motionY = 0; + robot.motionZ = 0; + robot.posX = finalX + 0.5F; + robot.posY = finalY + 0.5F; + robot.posZ = finalZ + 0.5F; + } +} diff --git a/common/buildcraft/core/robots/RobotAIDirectMoveTo.java b/common/buildcraft/core/robots/AIRobotStraightMoveTo.java similarity index 58% rename from common/buildcraft/core/robots/RobotAIDirectMoveTo.java rename to common/buildcraft/core/robots/AIRobotStraightMoveTo.java index 966b9b0e..7c771a53 100755 --- a/common/buildcraft/core/robots/RobotAIDirectMoveTo.java +++ b/common/buildcraft/core/robots/AIRobotStraightMoveTo.java @@ -8,15 +8,15 @@ */ package buildcraft.core.robots; +import buildcraft.robots.EntityRobotBase; -public class RobotAIDirectMoveTo extends RobotAIBase { +public class AIRobotStraightMoveTo extends AIRobotMove { private double prevDistance = Double.MAX_VALUE; - private boolean done = false; private float x, y, z; - public RobotAIDirectMoveTo(EntityRobot iRobot, float ix, float iy, float iz) { + public AIRobotStraightMoveTo(EntityRobotBase iRobot, float ix, float iy, float iz) { super(iRobot); robot = iRobot; x = ix; @@ -26,32 +26,29 @@ public class RobotAIDirectMoveTo extends RobotAIBase { @Override public void start() { + robot.setCurrentDockingStation(null); setDestination(robot, x, y, z); } @Override - public void updateTask() { - super.updateTask(); - - double distance = robot.getDistance(destX, destY, destZ); + public void update() { + double distance = robot.getDistance(nextX, nextY, nextZ); if (distance < prevDistance) { prevDistance = distance; } else { - robot.motionX = 0; - robot.motionY = 0; - robot.motionZ = 0; - - robot.posX = x; - robot.posY = y; - robot.posZ = z; - - done = true; + terminate(); } } @Override - public boolean isDone() { - return done; + public void end() { + robot.motionX = 0; + robot.motionY = 0; + robot.motionZ = 0; + + robot.posX = x; + robot.posY = y; + robot.posZ = z; } } diff --git a/common/buildcraft/core/robots/EntityRobot.java b/common/buildcraft/core/robots/EntityRobot.java index 859f14e8..085f7613 100755 --- a/common/buildcraft/core/robots/EntityRobot.java +++ b/common/buildcraft/core/robots/EntityRobot.java @@ -12,7 +12,6 @@ import java.util.Date; import io.netty.buffer.ByteBuf; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -21,12 +20,14 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.boards.IRedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardNBT; import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.core.SafeTimeTracker; import buildcraft.core.DefaultProps; @@ -37,8 +38,9 @@ import buildcraft.core.network.RPCMessageInfo; import buildcraft.core.network.RPCSide; import buildcraft.robots.DockingStation; import buildcraft.robots.DockingStationRegistry; +import buildcraft.robots.EntityRobotBase; -public class EntityRobot extends EntityLiving implements +public class EntityRobot extends EntityRobotBase implements IEntityAdditionalSpawnData, IInventory { public static final ResourceLocation ROBOT_BASE = new ResourceLocation("buildcraft", @@ -60,9 +62,9 @@ public class EntityRobot extends EntityLiving implements public DockingStation mainDockingStation; public boolean isDocked = false; - public IRedstoneBoardRobot board; + public RedstoneBoardRobot board; + public AIRobotMain mainAI; - public RobotAIBase currentAI; public ItemStack itemInUse; public float itemAngle1 = 0; public float itemAngle2 = 0; @@ -70,21 +72,22 @@ public class EntityRobot extends EntityLiving implements public float itemActiveStage = 0; public long lastUpdateTime = 0; - protected RobotAIBase nextAI; - private boolean needsUpdate = false; private ItemStack[] inv = new ItemStack[6]; private String boardID; private ResourceLocation texture; - public EntityRobot(World world, IRedstoneBoardRobot iBoard) { + public EntityRobot(World world, NBTTagCompound boardNBT) { this(world); - board = iBoard; + board = (RedstoneBoardRobot) RedstoneBoardRegistry.instance.getRedstoneBoard(boardNBT).create(boardNBT, this); dataWatcher.updateObject(16, board.getNBTHandler().getID()); if (world.isRemote) { RPCHandler.rpcServer(this, "requestInitialization", itemInUse); + } else { + mainAI = new AIRobotMain(this); + mainAI.start(); } } @@ -187,18 +190,17 @@ public class EntityRobot extends EntityLiving implements updateDataClient(); } - if (nextAI != null) { - if (currentAI != null) { - tasks.removeTask(currentAI); - } - - currentAI = nextAI; - nextAI = null; - tasks.addTask(0, currentAI); + if (currentDockingStation != null) { + motionX = 0; + motionY = 0; + motionZ = 0; + posX = currentDockingStation.pipe.xCoord + 0.5F + currentDockingStation.side.offsetX * 0.5F; + posY = currentDockingStation.pipe.yCoord + 0.5F + currentDockingStation.side.offsetY * 0.5F; + posZ = currentDockingStation.pipe.zCoord + 0.5F + currentDockingStation.side.offsetZ * 0.5F; } if (!worldObj.isRemote) { - board.updateBoard(this); + mainAI.cycle(); if (currentTask == null) { if (scanForTasks.markTimeIfDelay(worldObj)) { @@ -330,10 +332,6 @@ public class EntityRobot extends EntityLiving implements nbt.setInteger("dockSide", mainDockingStation.side.ordinal()); } - if (currentAI != null) { - nbt.setString("ai", currentAI.getClass().getCanonicalName()); - } - NBTTagCompound nbtLaser = new NBTTagCompound(); laser.writeToNBT(nbtLaser); nbt.setTag("laser", nbtLaser); @@ -390,10 +388,6 @@ public class EntityRobot extends EntityLiving implements return true; } - public void setMainAI (RobotAIBase ai) { - nextAI = ai; - } - @Override public int getSizeInventory() { return inv.length; @@ -465,10 +459,12 @@ public class EntityRobot extends EntityLiving implements .getItemStackLimit()); } + @Override public boolean isMoving() { return motionX != 0 || motionY != 0 || motionZ != 0; } + @Override public void setItemInUse(ItemStack stack) { itemInUse = stack; RPCHandler.rpcBroadcastPlayers(worldObj, this, "clientSetItemInUse", stack); @@ -489,12 +485,14 @@ public class EntityRobot extends EntityLiving implements // deactivate healh management } - public void setItemAngle(float a1, float a2) { + @Override + public void setItemAngles(float a1, float a2) { itemAngle1 = a1; itemAngle2 = a2; updateDataServer(); } + @Override public void setItemActive(boolean isActive) { RPCHandler.rpcBroadcastPlayers(worldObj, this, "rpcSetItemActive", isActive); } @@ -505,4 +503,36 @@ public class EntityRobot extends EntityLiving implements itemActiveStage = 0; lastUpdateTime = new Date().getTime(); } + + @Override + public void setCurrentDockingStation(DockingStation station) { + currentDockingStation = station; + } + + @Override + public ItemStack getItemInUse() { + return itemInUse; + } + + @Override + public RedstoneBoardRobot getBoard() { + return board; + } + + @Override + public DockingStation getCurrentDockingStation() { + return currentDockingStation; + } + + @Override + public DockingStation getMainDockingStation() { + return mainDockingStation; + } + + @SideOnly(Side.CLIENT) + @Override + public boolean isInRangeToRenderDist(double par1) { + return true; + } + } diff --git a/common/buildcraft/core/robots/RobotAIBase.java b/common/buildcraft/core/robots/RobotAIBase.java deleted file mode 100755 index 1a43e85b..00000000 --- a/common/buildcraft/core/robots/RobotAIBase.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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.entity.ai.EntityAIBase; -import net.minecraft.nbt.NBTTagCompound; - -public class RobotAIBase extends EntityAIBase { - - protected float destX, destY, destZ; - protected double dirX, dirY, dirZ; - protected EntityRobot robot; - - private boolean isStarted = false; - - public RobotAIBase(EntityRobot iRobot) { - robot = iRobot; - } - - public void setDestination(EntityRobot robot, float x, float y, float z) { - robot.isDocked = false; - robot.currentDockingStation = null; - - destX = x; - destY = y; - destZ = z; - - dirX = destX - robot.posX; - dirY = destY - robot.posY; - dirZ = destZ - robot.posZ; - - double magnitude = Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ); - - dirX /= magnitude; - dirY /= magnitude; - dirZ /= magnitude; - - robot.motionX = dirX / 10F; - robot.motionY = dirY / 10F; - robot.motionZ = dirZ / 10F; - } - - @Override - public void updateTask() { - super.updateTask(); - - if (!isStarted) { - start(); - isStarted = true; - } - } - - public void writeToNBT(NBTTagCompound nbt) { - nbt.setFloat("destX", destX); - nbt.setFloat("destY", destY); - nbt.setFloat("destZ", destZ); - - nbt.setDouble("dirX", dirX); - nbt.setDouble("dirY", dirY); - nbt.setDouble("dirZ", dirZ); - } - - public void readFromNBT(NBTTagCompound nbt) { - destX = nbt.getFloat("destX"); - destY = nbt.getFloat("destY"); - destZ = nbt.getFloat("destZ"); - - dirX = nbt.getDouble("dirX"); - dirY = nbt.getDouble("dirY"); - dirZ = nbt.getDouble("dirZ"); - } - - @Override - public boolean shouldExecute() { - return true; - } - - public boolean isDone() { - return false; - } - - public void start() { - - } -} diff --git a/common/buildcraft/core/robots/RobotAIComposite.java b/common/buildcraft/core/robots/RobotAIComposite.java deleted file mode 100755 index 51ab1e62..00000000 --- a/common/buildcraft/core/robots/RobotAIComposite.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.LinkedList; - -public class RobotAIComposite extends RobotAIBase { - - LinkedList cpts = new LinkedList(); - - public RobotAIComposite(EntityRobot iRobot, RobotAIBase... icpts) { - super(iRobot); - - for (RobotAIBase ai : icpts) { - cpts.add(ai); - } - } - - @Override - public void updateTask() { - if (cpts.size() > 0) { - if (cpts.getFirst().isDone()) { - cpts.removeFirst(); - } else { - cpts.getFirst().updateTask(); - } - } - } - - @Override - public boolean shouldExecute() { - if (cpts.size() > 0) { - return cpts.getFirst().shouldExecute(); - } else { - return true; - } - } - - @Override - public boolean isDone() { - return cpts.size() == 0; - } -} diff --git a/common/buildcraft/core/robots/RobotAIDocked.java b/common/buildcraft/core/robots/RobotAIDocked.java deleted file mode 100755 index 4528cfb0..00000000 --- a/common/buildcraft/core/robots/RobotAIDocked.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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 buildcraft.robots.DockingStation; - -public class RobotAIDocked extends RobotAIBase { - - private DockingStation station; - - public RobotAIDocked(EntityRobot iRobot, DockingStation iStation) { - super(iRobot); - - station = iStation; - } - - @Override - public void updateTask() { - super.updateTask(); - - robot.isDocked = true; - robot.motionX = 0; - robot.motionY = 0; - robot.motionZ = 0; - robot.posX = station.pipe.xCoord + 0.5F + station.side.offsetX * 0.5F; - robot.posY = station.pipe.yCoord + 0.5F + station.side.offsetY * 0.5F; - robot.posZ = station.pipe.zCoord + 0.5F + station.side.offsetZ * 0.5F; - robot.currentDockingStation = station; - } -} diff --git a/common/buildcraft/core/robots/RobotAIGoToDock.java b/common/buildcraft/core/robots/RobotAIGoToDock.java deleted file mode 100755 index bd81502f..00000000 --- a/common/buildcraft/core/robots/RobotAIGoToDock.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * 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 buildcraft.robots.DockingStation; - -public class RobotAIGoToDock extends RobotAIComposite { - - public RobotAIGoToDock(EntityRobot iRobot, DockingStation station) { - super(iRobot, - new RobotAIMoveTo(iRobot, - station.pipe.xCoord + 0.5F + station.side.offsetX * 1.5F, - station.pipe.yCoord + 0.5F + station.side.offsetY * 1.5F, - station.pipe.zCoord + 0.5F + station.side.offsetZ * 1.5F), - new RobotAIDirectMoveTo(iRobot, - station.pipe.xCoord + 0.5F + station.side.offsetX * 0.5F, - station.pipe.yCoord + 0.5F + station.side.offsetY * 0.5F, - station.pipe.zCoord + 0.5F + station.side.offsetZ * 0.5F), - new RobotAIDocked(iRobot, station)); - } -} diff --git a/common/buildcraft/core/robots/RobotAIMoveAround.java b/common/buildcraft/core/robots/RobotAIMoveAround.java deleted file mode 100755 index 5e55e763..00000000 --- a/common/buildcraft/core/robots/RobotAIMoveAround.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.nbt.NBTTagCompound; - -public class RobotAIMoveAround extends RobotAIBase { - - protected float aroundX, aroundY, aroundZ; - - double prevDistance = Double.MAX_VALUE; - - public RobotAIMoveAround(EntityRobot robot) { - super(robot); - } - - public RobotAIMoveAround (EntityRobot robot, float x, float y, float z) { - super(robot); - - aroundX = x; - aroundY = y; - aroundZ = z; - - randomDestination(robot); - } - - @Override - public void updateTask() { - super.updateTask(); - - double distance = robot.getDistance(destX, destY, destZ); - - if (distance >= prevDistance) { - randomDestination(robot); - prevDistance = Double.MAX_VALUE; - } else { - prevDistance = robot.getDistance(destX, destY, destZ); - } - } - - public void randomDestination(EntityRobot robot) { - for (int i = 0; i < 5; ++i) { - float testX = aroundX + robot.worldObj.rand.nextFloat() * 10F - 5F; - float testY = aroundY + robot.worldObj.rand.nextFloat() * 5F; - float testZ = aroundZ + robot.worldObj.rand.nextFloat() * 10F - 5F; - - Block block = robot.worldObj.getBlock((int) testX, (int) testY, - (int) testZ); - - // We set a destination. If it's wrong, we try a new one. - // Eventually, we'll accept even a wrong one if none can be easily - // found. - - setDestination(robot, testX, testY, testZ); - - if (block == Blocks.air) { - return; - } - } - } - - @Override - public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - - nbt.setFloat("aroundX", aroundX); - nbt.setFloat("aroundY", aroundY); - nbt.setFloat("aroundZ", aroundZ); - } - - @Override - public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - - aroundX = nbt.getFloat("aroundX"); - aroundY = nbt.getFloat("aroundY"); - aroundZ = nbt.getFloat("aroundZ"); - } -} diff --git a/common/buildcraft/core/robots/RobotAIMoveTo.java b/common/buildcraft/core/robots/RobotAIMoveTo.java deleted file mode 100755 index 6d311857..00000000 --- a/common/buildcraft/core/robots/RobotAIMoveTo.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.LinkedList; - -import net.minecraft.nbt.NBTTagCompound; - -import buildcraft.core.BlockIndex; -import buildcraft.core.utils.PathFinding; - -public class RobotAIMoveTo extends RobotAIBase { - - private PathFinding pathSearch; - private LinkedList path; - private double prevDistance = Double.MAX_VALUE; - private float dx, dy, dz; - - public RobotAIMoveTo (EntityRobot robot, float x, float y, float z) { - super(robot); - dx = x; - dy = y; - dz = z; - } - - public RobotAIMoveTo(EntityRobot robot, LinkedList iPath) { - super(robot); - path = iPath; - dx = path.getLast().x; - dy = path.getLast().y; - dz = path.getLast().z; - setNextInPath(); - } - - @Override - public void updateTask() { - super.updateTask(); - - if (path != null) { - double distance = robot.getDistance(destX, destY, destZ); - - if (!robot.isMoving() || distance > prevDistance) { - if (path.size() > 0) { - path.removeFirst(); - } - - setNextInPath(); - } else { - prevDistance = robot.getDistance(destX, destY, destZ); - } - - if (path.size() == 0) { - robot.motionX = 0; - robot.motionY = 0; - robot.motionZ = 0; - } - } else if (pathSearch == null) { - pathSearch = new PathFinding - (robot.worldObj, - new BlockIndex((int) Math.floor(robot.posX), (int) Math.floor(robot.posY), - (int) Math.floor(robot.posZ)), - new BlockIndex((int) Math.floor(dx), (int) Math.floor(dy), (int) Math.floor(dz))); - } else if (pathSearch.isDone()) { - path = pathSearch.getResult(); - setNextInPath(); - } else { - pathSearch.iterate(PathFinding.PATH_ITERATIONS); - } - } - - private void setNextInPath() { - if (path.size() > 0) { - BlockIndex next = path.getFirst(); - setDestination(robot, next.x + 0.5F, next.y + 0.5F, next.z + 0.5F); - prevDistance = Double.MAX_VALUE; - } - } - - @Override - public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - } - - @Override - public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - } - - @Override - public boolean isDone() { - return path != null && path.size() == 0; - } -} diff --git a/common/buildcraft/core/robots/boards/AIRobotCutWood.java b/common/buildcraft/core/robots/boards/AIRobotCutWood.java new file mode 100755 index 00000000..f9af37ee --- /dev/null +++ b/common/buildcraft/core/robots/boards/AIRobotCutWood.java @@ -0,0 +1,114 @@ +/** + * 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.boards; + +import net.minecraft.block.Block; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.world.WorldServer; + +import net.minecraftforge.common.ForgeHooks; + +import buildcraft.core.BlockIndex; +import buildcraft.core.utils.BlockUtil; +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotCutWood extends AIRobot { + + private float blockDamage = 0; + private BlockIndex woodToChop; + + private Block block; + private int meta; + private float hardness; + private float speed; + + public AIRobotCutWood(EntityRobotBase iRobot, BlockIndex iWoodToChop) { + super(iRobot); + + woodToChop = iWoodToChop; + + float a1 = (float) Math.atan2(woodToChop.z - Math.floor(robot.posZ), + woodToChop.x - Math.floor(robot.posX)); + + float a2 = 0; + + if (Math.floor(robot.posY) < woodToChop.y) { + a2 = (float) -Math.PI / 4; + + if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) { + a2 -= (float) Math.PI / 4; + } + } else if (Math.floor(robot.posY) > woodToChop.y) { + a2 = (float) Math.PI / 2; + + if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) { + a2 += (float) Math.PI / 4; + } + } + + robot.setItemAngles(a1, a2); + + robot.setItemActive(true); + block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z); + meta = robot.worldObj.getBlockMetadata(woodToChop.x, woodToChop.y, woodToChop.z); + hardness = block.getBlockHardness(robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z); + speed = getBreakSpeed(robot, robot.getItemInUse(), block, meta); + } + + @Override + public void update() { + blockDamage += speed / hardness / 30F; + + if (blockDamage > 1.0F) { + robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x, + woodToChop.y, woodToChop.z, -1); + blockDamage = 0; + BlockUtil.breakBlock((WorldServer) robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z, 6000); + robot.worldObj.setBlockToAir(woodToChop.x, woodToChop.y, woodToChop.z); + robot.setItemActive(false); + robot.getItemInUse().getItem().onBlockDestroyed(robot.getItemInUse(), robot.worldObj, block, woodToChop.x, + woodToChop.y, woodToChop.z, robot); + + if (robot.getItemInUse().getItemDamage() >= robot.getItemInUse().getMaxDamage()) { + robot.setItemInUse(null); + } + + terminate(); + } else { + robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x, + woodToChop.y, woodToChop.z, (int) (blockDamage * 10.0F) - 1); + } + } + + private float getBreakSpeed(EntityRobotBase robot, ItemStack usingItem, Block block, int meta) { + ItemStack stack = usingItem; + float f = stack == null ? 1.0F : stack.getItem().getDigSpeed(stack, block, meta); + + if (f > 1.0F) { + int i = EnchantmentHelper.getEfficiencyModifier(robot); + ItemStack itemstack = usingItem; + + if (i > 0 && itemstack != null) { + float f1 = i * i + 1; + + boolean canHarvest = ForgeHooks.canToolHarvestBlock(block, meta, itemstack); + + if (!canHarvest && f <= 1.0F) { + f += f1 * 0.08F; + } else { + f += f1; + } + } + } + + return f; + } +} diff --git a/common/buildcraft/core/robots/boards/AIRobotFetchAxe.java b/common/buildcraft/core/robots/boards/AIRobotFetchAxe.java new file mode 100755 index 00000000..f14aca58 --- /dev/null +++ b/common/buildcraft/core/robots/boards/AIRobotFetchAxe.java @@ -0,0 +1,83 @@ +/** + * 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.boards; + +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.core.inventory.ITransactor; +import buildcraft.core.inventory.Transactor; +import buildcraft.core.inventory.filters.ArrayStackFilter; +import buildcraft.core.robots.AIRobotGoToDock; +import buildcraft.robots.AIRobot; +import buildcraft.robots.DockingStation; +import buildcraft.robots.DockingStationRegistry; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotFetchAxe extends AIRobot { + + private DockingStation axeDocking = null; + + public AIRobotFetchAxe(EntityRobotBase iRobot) { + super(iRobot); + } + + @Override + public void update() { + for (DockingStation d : DockingStationRegistry.getStations()) { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + TileEntity nearbyTile = robot.worldObj.getTileEntity(d.pipe.xCoord + dir.offsetX, d.pipe.yCoord + + dir.offsetY, d.pipe.zCoord + + dir.offsetZ); + + if (nearbyTile != null && nearbyTile instanceof IInventory) { + ArrayStackFilter filter = new ArrayStackFilter(new ItemStack(Items.wooden_axe)); + ITransactor trans = Transactor.getTransactorFor(nearbyTile); + + if (trans.remove(filter, dir.getOpposite(), false) != null) { + axeDocking = d; + startDelegateAI(new AIRobotGoToDock(robot, axeDocking)); + return; + } + } + } + } + } + + @Override + public void delegateAIEnded(AIRobot ai) { + ItemStack axeFound = null; + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + TileEntity nearbyTile = robot.worldObj.getTileEntity(axeDocking.pipe.xCoord + dir.offsetX, + axeDocking.pipe.yCoord + + dir.offsetY, axeDocking.pipe.zCoord + dir.offsetZ); + + if (nearbyTile != null && nearbyTile instanceof IInventory) { + ArrayStackFilter filter = new ArrayStackFilter(new ItemStack(Items.wooden_axe)); + ITransactor trans = Transactor.getTransactorFor(nearbyTile); + + axeFound = trans.remove(filter, dir.getOpposite(), true); + + if (axeFound != null) { + break; + } + } + } + + if (axeFound != null) { + robot.setItemInUse(axeFound); + terminate(); + } + } +} diff --git a/common/buildcraft/core/robots/boards/AIRobotFetchItem.java b/common/buildcraft/core/robots/boards/AIRobotFetchItem.java new file mode 100755 index 00000000..1e911962 --- /dev/null +++ b/common/buildcraft/core/robots/boards/AIRobotFetchItem.java @@ -0,0 +1,108 @@ +/** + * 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.boards; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.core.inventory.TransactorSimple; +import buildcraft.core.inventory.filters.IStackFilter; +import buildcraft.core.robots.AIRobotMoveToBlock; +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotFetchItem extends AIRobot { + + public EntityItem target; + + private float maxRange; + private IStackFilter stackFilter; + private int pickTime = -1; + + public AIRobotFetchItem(EntityRobotBase iRobot, float iMaxRange, IStackFilter iStackFilter) { + super(iRobot); + + maxRange = iMaxRange; + stackFilter = iStackFilter; + } + + @Override + public void start() { + TransactorSimple inventoryInsert = new TransactorSimple(robot); + + for (Object o : robot.worldObj.loadedEntityList) { + Entity e = (Entity) o; + + if (!e.isDead && e instanceof EntityItem && !BoardRobotPicker.targettedItems.contains(e.getEntityId())) { + double dx = e.posX - robot.posX; + double dy = e.posY - robot.posY; + double dz = e.posZ - robot.posZ; + + double sqrDistance = dx * dx + dy * dy + dz * dz; + double maxDistance = maxRange * maxRange; + + if (sqrDistance >= maxDistance) { + continue; + } else if (stackFilter != null && !stackFilter.matches(((EntityItem) e).getEntityItem())) { + continue; + } else { + EntityItem item = (EntityItem) e; + + if (inventoryInsert.inject(item.getEntityItem(), ForgeDirection.UNKNOWN, false) > 0) { + target = item; + BoardRobotPicker.targettedItems.add(e.getEntityId()); + + startDelegateAI(new AIRobotMoveToBlock(robot, (int) Math.floor(e.posX), + (int) Math.floor(e.posY), (int) Math.floor(e.posZ))); + + return; + } + } + } + } + + // No item was found, terminate this AI + terminate(); + } + + @Override + public void preempt() { + if (target.isDead) { + BoardRobotPicker.targettedItems.remove(target.getEntityId()); + terminate(); + } + } + + @Override + public void update() { + if (target.isDead) { + BoardRobotPicker.targettedItems.remove(target.getEntityId()); + terminate(); + } else { + pickTime++; + + if (pickTime > 20) { + TransactorSimple inventoryInsert = new TransactorSimple(robot); + + target.getEntityItem().stackSize -= inventoryInsert.inject( + target.getEntityItem(), ForgeDirection.UNKNOWN, + true); + + if (target.getEntityItem().stackSize <= 0) { + target.setDead(); + } + + BoardRobotPicker.targettedItems.remove(target.getEntityId()); + terminate(); + } + } + } +} diff --git a/common/buildcraft/core/robots/boards/AIRobotGoToWood.java b/common/buildcraft/core/robots/boards/AIRobotGoToWood.java new file mode 100755 index 00000000..1a4167d6 --- /dev/null +++ b/common/buildcraft/core/robots/boards/AIRobotGoToWood.java @@ -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.boards; + +import java.util.LinkedList; + +import net.minecraft.init.Blocks; +import net.minecraft.world.IBlockAccess; + +import buildcraft.core.BlockIndex; +import buildcraft.core.robots.AIRobotMoveToBlock; +import buildcraft.core.utils.IPathFound; +import buildcraft.core.utils.PathFinding; +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; + +public class AIRobotGoToWood extends AIRobot { + + public BlockIndex woodFound; + private PathFinding woodScanner = null; + + public AIRobotGoToWood(EntityRobotBase iRobot) { + super(iRobot); + } + + @Override + public void start() { + woodScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), new IPathFound() { + @Override + public boolean endReached(IBlockAccess world, int x, int y, int z) { + return world.getBlock(x, y, z) == Blocks.log || world.getBlock(x, y, z) == Blocks.log2; + } + }); + } + + @Override + public void update() { + woodScanner.iterate(PathFinding.PATH_ITERATIONS); + + if (woodScanner.isDone()) { + LinkedList path = woodScanner.getResult(); + woodFound = path.removeLast(); + startDelegateAI(new AIRobotMoveToBlock(robot, path)); + } + } + + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotMoveToBlock) { + terminate(); + } + } + +} diff --git a/common/buildcraft/core/robots/boards/BoardRobotLumberjack.java b/common/buildcraft/core/robots/boards/BoardRobotLumberjack.java index 80e03afe..513f05f8 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotLumberjack.java +++ b/common/buildcraft/core/robots/boards/BoardRobotLumberjack.java @@ -1,229 +1,44 @@ +/** + * 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.boards; -import java.util.LinkedList; - -import net.minecraft.block.Block; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.util.ForgeDirection; - -import buildcraft.api.boards.IRedstoneBoardRobot; -import buildcraft.api.boards.RedstoneBoardNBT; -import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; -import buildcraft.core.BlockIndex; -import buildcraft.core.inventory.ITransactor; -import buildcraft.core.inventory.Transactor; -import buildcraft.core.inventory.filters.ArrayStackFilter; -import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.RobotAIGoToDock; -import buildcraft.core.robots.RobotAIMoveTo; -import buildcraft.core.utils.BlockUtil; -import buildcraft.core.utils.IPathFound; -import buildcraft.core.utils.PathFinding; -import buildcraft.robots.DockingStation; -import buildcraft.robots.DockingStationRegistry; +import buildcraft.robots.AIRobot; +import buildcraft.robots.EntityRobotBase; -public class BoardRobotLumberjack implements IRedstoneBoardRobot { +public class BoardRobotLumberjack extends RedstoneBoardRobot { - private static enum Stages { - LOOK_FOR_AXE, GO_TO_AXE_INVENTORY, LOOK_FOR_WOOD, GO_TO_WOOD, CUT_WOOD - }; - - private NBTTagCompound data; - private RedstoneBoardNBT board; - private int range; - private boolean initialized = false; - private PathFinding woodScanner = null; - private DockingStation axeDocking = null; - private Stages stage = Stages.LOOK_FOR_AXE; - private BlockIndex woodToChop; - private float blockDamage; - - public BoardRobotLumberjack(NBTTagCompound nbt) { - data = nbt; - - board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt); + public BoardRobotLumberjack(EntityRobotBase iRobot, NBTTagCompound nbt) { + super(iRobot); } @Override - public void updateBoard(EntityRobot robot) { - if (robot.worldObj.isRemote) { - return; - } - - if (!initialized) { - range = data.getInteger("range"); - initialized = true; - } - - if (stage == Stages.LOOK_FOR_AXE) { - for (DockingStation d : DockingStationRegistry.getStations()) { - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - TileEntity nearbyTile = robot.worldObj.getTileEntity(d.pipe.xCoord + dir.offsetX, d.pipe.yCoord - + dir.offsetY, d.pipe.zCoord - + dir.offsetZ); - - if (nearbyTile != null && nearbyTile instanceof IInventory) { - ArrayStackFilter filter = new ArrayStackFilter(new ItemStack(Items.wooden_axe)); - ITransactor trans = Transactor.getTransactorFor(nearbyTile); - - if (trans.remove(filter, dir.getOpposite(), false) != null) { - axeDocking = d; - robot.setMainAI(new RobotAIGoToDock(robot, axeDocking)); - stage = Stages.GO_TO_AXE_INVENTORY; - return; - } - } - } - } - } else if (stage == Stages.GO_TO_AXE_INVENTORY) { - if (robot.currentDockingStation != null && robot.currentDockingStation.equals(axeDocking)) { - ItemStack axeFound = null; - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - TileEntity nearbyTile = robot.worldObj.getTileEntity(axeDocking.pipe.xCoord + dir.offsetX, - axeDocking.pipe.yCoord - + dir.offsetY, axeDocking.pipe.zCoord + dir.offsetZ); - - if (nearbyTile != null && nearbyTile instanceof IInventory) { - ArrayStackFilter filter = new ArrayStackFilter(new ItemStack(Items.wooden_axe)); - ITransactor trans = Transactor.getTransactorFor(nearbyTile); - - axeFound = trans.remove(filter, dir.getOpposite(), true); - - if (axeFound != null) { - break; - } - } - } - - reset(); - - if (axeFound == null) { - stage = Stages.LOOK_FOR_AXE; - } else { - robot.setItemInUse(axeFound); - stage = Stages.LOOK_FOR_WOOD; - } - } - } else if (stage == Stages.LOOK_FOR_WOOD) { - if (woodScanner == null) { - woodScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), new IPathFound() { - @Override - public boolean endReached(IBlockAccess world, int x, int y, int z) { - return world.getBlock(x, y, z) == Blocks.log || world.getBlock(x, y, z) == Blocks.log2; - } - }); - } else { - woodScanner.iterate(PathFinding.PATH_ITERATIONS); - - if (woodScanner.isDone()) { - LinkedList path = woodScanner.getResult(); - woodToChop = path.removeLast(); - robot.setMainAI(new RobotAIMoveTo(robot, path)); - stage = Stages.GO_TO_WOOD; - } - } - } else if (stage == Stages.GO_TO_WOOD) { - if (robot.currentAI.isDone()) { - stage = Stages.CUT_WOOD; - blockDamage = 0; - - float a1 = (float) Math.atan2(woodToChop.z - Math.floor(robot.posZ), - woodToChop.x - Math.floor(robot.posX)); - - float a2 = 0; - - if (Math.floor(robot.posY) < woodToChop.y) { - a2 = (float) -Math.PI / 4; - - if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) { - a2 -= (float) Math.PI / 4; - } - } else if (Math.floor(robot.posY) > woodToChop.y) { - a2 = (float) Math.PI / 2; - - if (Math.floor(robot.posX) == woodToChop.x && Math.floor(robot.posZ) == woodToChop.z) { - a2 += (float) Math.PI / 4; - } - } - - robot.setItemAngle(a1, a2); - robot.setItemActive(true); - } - } else if (stage == Stages.CUT_WOOD) { - Block block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z); - int meta = robot.worldObj.getBlockMetadata(woodToChop.x, woodToChop.y, woodToChop.z); - float hardness = block.getBlockHardness(robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z); - float speed = getBreakSpeed(robot, robot.itemInUse, block, meta); - blockDamage += speed / hardness / 30F; - - if (blockDamage > 1.0F) { - robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x, - woodToChop.y, woodToChop.z, -1); - blockDamage = 0; - BlockUtil.breakBlock((WorldServer) robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z, 6000); - robot.worldObj.setBlockToAir(woodToChop.x, woodToChop.y, woodToChop.z); - stage = Stages.LOOK_FOR_WOOD; - robot.setItemActive(false); - robot.itemInUse.getItem().onBlockDestroyed(robot.itemInUse, robot.worldObj, block, woodToChop.x, - woodToChop.y, woodToChop.z, robot); - - if (robot.itemInUse.getItemDamage() >= robot.itemInUse.getMaxDamage()) { - robot.setItemInUse(null); - stage = Stages.LOOK_FOR_AXE; - } - - reset(); - } else { - robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x, - woodToChop.y, woodToChop.z, (int) (blockDamage * 10.0F) - 1); - } + public void update() { + if (robot.getItemInUse() == null) { + startDelegateAI(new AIRobotFetchAxe(robot)); + } else { + startDelegateAI(new AIRobotGoToWood(robot)); } } - private void reset() { - axeDocking = null; - woodToChop = null; - woodScanner = null; + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotGoToWood) { + startDelegateAI(new AIRobotCutWood(robot, ((AIRobotGoToWood) ai).woodFound)); + } } @Override public RedstoneBoardRobotNBT getNBTHandler() { return BoardRobotLumberjackNBT.instance; } - - private float getBreakSpeed(EntityRobot robot, ItemStack usingItem, Block block, int meta) { - ItemStack stack = usingItem; - float f = stack == null ? 1.0F : stack.getItem().getDigSpeed(stack, block, meta); - - if (f > 1.0F) { - int i = EnchantmentHelper.getEfficiencyModifier(robot); - ItemStack itemstack = usingItem; - - if (i > 0 && itemstack != null) { - float f1 = i * i + 1; - - boolean canHarvest = ForgeHooks.canToolHarvestBlock(block, meta, itemstack); - - if (!canHarvest && f <= 1.0F) { - f += f1 * 0.08F; - } else { - f += f1; - } - } - } - - return f; - } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotLumberjackNBT.java b/common/buildcraft/core/robots/boards/BoardRobotLumberjackNBT.java index 1daa2c48..c951fc6c 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotLumberjackNBT.java +++ b/common/buildcraft/core/robots/boards/BoardRobotLumberjackNBT.java @@ -17,11 +17,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; -import buildcraft.api.boards.IRedstoneBoardRobot; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.core.robots.EntityRobot; import buildcraft.core.utils.NBTUtils; import buildcraft.core.utils.StringUtils; +import buildcraft.robots.EntityRobotBase; public final class BoardRobotLumberjackNBT extends RedstoneBoardRobotNBT { @@ -48,8 +49,8 @@ public final class BoardRobotLumberjackNBT extends RedstoneBoardRobotNBT { } @Override - public IRedstoneBoardRobot create(NBTTagCompound nbt) { - return new BoardRobotLumberjack(nbt); + public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) { + return new BoardRobotLumberjack(robot, nbt); } @Override diff --git a/common/buildcraft/core/robots/boards/BoardRobotPicker.java b/common/buildcraft/core/robots/boards/BoardRobotPicker.java index 68b37755..7c2a9cc6 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPicker.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPicker.java @@ -3,175 +3,104 @@ package buildcraft.core.robots.boards; import java.util.HashSet; import java.util.Set; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; - import buildcraft.api.boards.IBoardParameter; import buildcraft.api.boards.IBoardParameterStack; -import buildcraft.api.boards.IRedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardNBT; import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.core.SafeTimeTracker; -import buildcraft.core.inventory.TransactorSimple; import buildcraft.core.inventory.filters.ArrayStackFilter; import buildcraft.core.inventory.filters.IStackFilter; -import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.RobotAIMoveTo; -import buildcraft.core.robots.RobotAIReturnToDock; +import buildcraft.core.robots.AIRobotGoToDock; +import buildcraft.robots.AIRobot; +import buildcraft.robots.DockingStation; +import buildcraft.robots.EntityRobotBase; import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TravelingItem; -public class BoardRobotPicker implements IRedstoneBoardRobot { +public class BoardRobotPicker extends RedstoneBoardRobot { - private static Set targettedItems = new HashSet(); + public static Set targettedItems = new HashSet(); private SafeTimeTracker scanTracker = new SafeTimeTracker(40, 10); - private SafeTimeTracker pickTracker = new SafeTimeTracker(20, 0); - private SafeTimeTracker unloadTracker = new SafeTimeTracker(20, 0); - private EntityItem target; - private int pickTime = -1; private NBTTagCompound data; - private RedstoneBoardNBT board; private IBoardParameter[] params; private int range; private IStackFilter stackFilter; - private boolean initialized = false; - public BoardRobotPicker(NBTTagCompound nbt) { + public BoardRobotPicker(EntityRobotBase robot, NBTTagCompound nbt) { + super(robot); data = nbt; board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt); params = board.getParameters(nbt); + + range = nbt.getInteger("range"); + + ItemStack[] stacks = new ItemStack[params.length]; + + for (int i = 0; i < stacks.length; ++i) { + IBoardParameterStack pStak = (IBoardParameterStack) params[i]; + stacks[i] = pStak.getStack(); + } + + if (stacks.length > 0) { + stackFilter = new ArrayStackFilter(stacks); + } else { + stackFilter = null; + } } @Override - public void updateBoard(EntityRobot robot) { - TransactorSimple inventoryInsert = new TransactorSimple(robot); - - if (robot.worldObj.isRemote) { - return; - } - - if (!initialized) { - range = data.getInteger("range"); - - ItemStack[] stacks = new ItemStack[params.length]; - - for (int i = 0; i < stacks.length; ++i) { - IBoardParameterStack pStak = (IBoardParameterStack) params[i]; - stacks[i] = pStak.getStack(); - } - - if (stacks.length > 0) { - stackFilter = new ArrayStackFilter(stacks); - } else { - stackFilter = null; - } - - initialized = true; - } - - if (target != null) { - if (target.isDead) { - targettedItems.remove(target.getEntityId()); - target = null; - robot.setMainAI(new RobotAIReturnToDock(robot)); - scan(robot); - } else if (pickTime == -1) { - if (robot.currentAI.isDone()) { - pickTracker = new SafeTimeTracker(200); - pickTime = 0; - } - } else { - pickTime++; - - if (pickTime > 20) { - target.getEntityItem().stackSize -= inventoryInsert.inject( - target.getEntityItem(), ForgeDirection.UNKNOWN, - true); - - if (target.getEntityItem().stackSize <= 0) { - target.setDead(); - } - } - } - } else { - if (robot.isDocked) { - TileGenericPipe pipe = (TileGenericPipe) robot.worldObj - .getTileEntity(robot.currentDockingStation.pipe.xCoord, robot.currentDockingStation.pipe.yCoord, - robot.currentDockingStation.pipe.zCoord); - - if (pipe != null && pipe.pipe.transport instanceof PipeTransportItems) { - if (unloadTracker.markTimeIfDelay(robot.worldObj)) { - for (int i = 0; i < robot.getSizeInventory(); ++i) { - if (robot.getStackInSlot(i) != null) { - float cx = robot.currentDockingStation.pipe.xCoord + 0.5F + 0.2F - * robot.currentDockingStation.side.offsetX; - float cy = robot.currentDockingStation.pipe.yCoord + 0.5F + 0.2F - * robot.currentDockingStation.side.offsetY; - float cz = robot.currentDockingStation.pipe.zCoord + 0.5F + 0.2F - * robot.currentDockingStation.side.offsetZ; - - TravelingItem item = TravelingItem.make(cx, cy, - cz, robot.getStackInSlot(i)); - - ((PipeTransportItems) pipe.pipe.transport) - .injectItem(item, robot.currentDockingStation.side.getOpposite()); - - robot.setInventorySlotContents(i, null); - - break; - } - } - } - } - } - - if (scanTracker.markTimeIfDelay(robot.worldObj)) { - scan(robot); - } + public void update() { + if (scanTracker.markTimeIfDelay(robot.worldObj)) { + startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter)); } } - public void scan(EntityRobot robot) { - TransactorSimple inventoryInsert = new TransactorSimple(robot); + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotFetchItem) { + if (((AIRobotFetchItem) ai).target != null) { + // if we could get an item, let's try to get another one + startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter)); + } else { + // otherwise, let's return to base + startDelegateAI(new AIRobotGoToDock(robot, robot.getMainDockingStation())); + } + } else if (ai instanceof AIRobotGoToDock) { + emptyContainerInStation(); + } + } - for (Object o : robot.worldObj.loadedEntityList) { - Entity e = (Entity) o; + private void emptyContainerInStation() { + DockingStation station = robot.getCurrentDockingStation(); - if (!e.isDead && e instanceof EntityItem && !targettedItems.contains(e.getEntityId())) { - double dx = e.posX - robot.posX; - double dy = e.posY - robot.posY; - double dz = e.posZ - robot.posZ; + TileGenericPipe pipe = (TileGenericPipe) robot.worldObj + .getTileEntity(station.pipe.xCoord, station.pipe.yCoord, station.pipe.zCoord); - double sqrDistance = dx * dx + dy * dy + dz * dz; - double maxDistance = range * range; + if (pipe != null && pipe.pipe.transport instanceof PipeTransportItems) { + for (int i = 0; i < robot.getSizeInventory(); ++i) { + if (robot.getStackInSlot(i) != null) { + float cx = station.pipe.xCoord + 0.5F + 0.2F * station.side.offsetX; + float cy = station.pipe.yCoord + 0.5F + 0.2F * station.side.offsetY; + float cz = station.pipe.zCoord + 0.5F + 0.2F * station.side.offsetZ; - if (sqrDistance >= maxDistance) { - continue; - } else if (stackFilter != null && !stackFilter.matches(((EntityItem) e).getEntityItem())) { - continue; - } else { - EntityItem item = (EntityItem) e; + TravelingItem item = TravelingItem.make(cx, cy, + cz, robot.getStackInSlot(i)); - if (inventoryInsert.inject(item.getEntityItem(), ForgeDirection.UNKNOWN, false) > 0) { - target = item; - targettedItems.add(e.getEntityId()); - robot.isDocked = false; - robot.setMainAI(new RobotAIMoveTo(robot, (float) e.posX, - (float) e.posY, (float) e.posZ)); - pickTime = -1; + ((PipeTransportItems) pipe.pipe.transport).injectItem(item, station.side.getOpposite()); - break; - } + robot.setInventorySlotContents(i, null); + + break; } } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java index 0433bfad..39b44933 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java @@ -18,12 +18,13 @@ import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import buildcraft.api.boards.IBoardParameter; -import buildcraft.api.boards.IRedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.core.robots.EntityRobot; import buildcraft.core.utils.NBTUtils; import buildcraft.core.utils.StringUtils; +import buildcraft.robots.EntityRobotBase; public final class BoardRobotPickerNBT extends RedstoneBoardRobotNBT { @@ -56,8 +57,8 @@ public final class BoardRobotPickerNBT extends RedstoneBoardRobotNBT { } @Override - public IRedstoneBoardRobot create(NBTTagCompound nbt) { - return new BoardRobotPicker(nbt); + public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase object) { + return new BoardRobotPicker(object, nbt); } @Override diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index d2f38b46..88afd9d4 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -56,7 +56,6 @@ import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.ItemRobot; import buildcraft.core.TileBuffer; import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.RobotAIDocked; import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.Utils; import buildcraft.robots.DockingStationRegistry; @@ -797,7 +796,7 @@ public class BlockGenericPipe extends BlockBuildCraft { robot.setPosition(px, py, pz); robot.setMainDockingStation(DockingStationRegistry.getStation(x, y, z, rayTraceResult.sideHit)); - robot.setMainAI(new RobotAIDocked(robot, robot.mainDockingStation)); + robot.setCurrentDockingStation(robot.getMainDockingStation()); world.spawnEntityInWorld(robot); if (!player.capabilities.isCreativeMode) {