diff --git a/api/buildcraft/api/robots/DockingStation.java b/api/buildcraft/api/robots/DockingStation.java new file mode 100755 index 00000000..2c51b901 --- /dev/null +++ b/api/buildcraft/api/robots/DockingStation.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) 2011-2015, 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.robots; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.core.BlockIndex; +import buildcraft.api.transport.IPipeTile; + +public class DockingStation { + public ForgeDirection side; + public World world; + + private long robotTakingId = EntityRobotBase.NULL_ROBOT_ID; + private EntityRobotBase robotTaking; + + private boolean linkIsMain = false; + + private BlockIndex index; + private IPipeTile pipe; + + public DockingStation(BlockIndex iIndex, ForgeDirection iSide) { + index = iIndex; + side = iSide; + } + + public DockingStation(IPipeTile iPipe, ForgeDirection iSide) { + index = new BlockIndex(iPipe.x(), iPipe.y(), iPipe.z()); + pipe = iPipe; + side = iSide; + world = iPipe.getWorld(); + } + + public DockingStation() { + } + + public boolean isMainStation() { + return linkIsMain; + } + + public IPipeTile getPipe() { + if (pipe == null) { + pipe = (IPipeTile) world.getTileEntity(index.x, index.y, index.z); + } + + if (pipe == null || ((TileEntity) pipe).isInvalid()) { + // Inconsistency - remove this pipe from the registry. + RobotManager.registryProvider.getRegistry(world).removeStation(this); + pipe = null; + } + + return pipe; + } + + public int x() { + return index.x; + } + + public int y() { + return index.y; + } + + public int z() { + return index.z; + } + + public ForgeDirection side() { + return side; + } + + public EntityRobotBase robotTaking() { + if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) { + return null; + } else if (robotTaking == null) { + robotTaking = RobotManager.registryProvider.getRegistry(world).getLoadedRobot(robotTakingId); + } + + return robotTaking; + } + + public void invalidateRobotTakingEntity() { + robotTaking = null; + } + + public long linkedId() { + return robotTakingId; + } + + public boolean takeAsMain(EntityRobotBase robot) { + if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + linkIsMain = true; + robotTaking = robot; + robotTakingId = robot.getRobotId(); + getPipe().scheduleRenderUpdate(); + registry.markDirty(); + robot.setMainStation(this); + registry.take(this, robot.getRobotId()); + + return true; + } else { + return robotTakingId == robot.getRobotId(); + } + } + + public boolean take(EntityRobotBase robot) { + if (robotTaking == null) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + linkIsMain = false; + robotTaking = robot; + robotTakingId = robot.getRobotId(); + getPipe().scheduleRenderUpdate(); + registry.markDirty(); + registry.take(this, robot.getRobotId()); + + return true; + } else { + return robot.getRobotId() == robotTakingId; + } + } + + public void release(EntityRobotBase robot) { + if (robotTaking == robot && !linkIsMain) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + unsafeRelease(robot); + registry.markDirty(); + registry.release(this, robot.getRobotId()); + } + } + + /** + * Same a release but doesn't clear the registry (presumably called from the + * registry). + */ + public void unsafeRelease(EntityRobotBase robot) { + if (robotTaking == robot) { + linkIsMain = false; + robotTaking = null; + robotTakingId = EntityRobotBase.NULL_ROBOT_ID; + getPipe().scheduleRenderUpdate(); + } + } + + public void writeToNBT(NBTTagCompound nbt) { + NBTTagCompound indexNBT = new NBTTagCompound(); + index.writeTo(indexNBT); + nbt.setTag("index", indexNBT); + nbt.setByte("side", (byte) side.ordinal()); + nbt.setBoolean("isMain", linkIsMain); + nbt.setLong("robotId", robotTakingId); + } + + public void readFromNBT(NBTTagCompound nbt) { + index = new BlockIndex (nbt.getCompoundTag("index")); + side = ForgeDirection.values()[nbt.getByte("side")]; + linkIsMain = nbt.getBoolean("isMain"); + robotTakingId = nbt.getLong("robotId"); + } + + public boolean isTaken() { + return robotTakingId != EntityRobotBase.NULL_ROBOT_ID; + } + + public long robotIdTaking() { + return robotTakingId; + } + + public BlockIndex index() { + return index; + } + + @Override + public String toString() { + return "{" + index.x + ", " + index.y + ", " + index.z + ", " + side + " :" + robotTakingId + "}"; + } + + public boolean linkIsDocked() { + if (isTaken()) { + return robotTaking().getDockingStation() == this; + } else { + return false; + } + } + + public boolean canRelease() { + return !isMainStation() && !linkIsDocked(); + } +} + diff --git a/api/buildcraft/api/robots/EntityRobotBase.java b/api/buildcraft/api/robots/EntityRobotBase.java index efc0ef0f..22d1f888 100755 --- a/api/buildcraft/api/robots/EntityRobotBase.java +++ b/api/buildcraft/api/robots/EntityRobotBase.java @@ -38,7 +38,7 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory public abstract boolean isMoving(); - public abstract IDockingStation getLinkedStation(); + public abstract DockingStation getLinkedStation(); public abstract RedstoneBoardRobot getBoard(); @@ -48,9 +48,9 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory public abstract IEnergyStorage getBattery(); - public abstract IDockingStation getDockingStation(); + public abstract DockingStation getDockingStation(); - public abstract void dock(IDockingStation station); + public abstract void dock(DockingStation station); public abstract void undock(); @@ -73,4 +73,6 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory public abstract void onChunkUnload(); public abstract ItemStack receiveItem(TileEntity tile, ItemStack stack); + + public abstract void setMainStation(DockingStation station); } diff --git a/api/buildcraft/api/robots/IDockingStation.java b/api/buildcraft/api/robots/IDockingStation.java deleted file mode 100755 index 76e04622..00000000 --- a/api/buildcraft/api/robots/IDockingStation.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * The BuildCraft API is distributed under the terms of the MIT License. - * Please check the contents of the license, which should be located - * as "LICENSE.API" in the BuildCraft source code distribution. - */ -package buildcraft.api.robots; - -import net.minecraft.nbt.NBTTagCompound; - -import net.minecraftforge.common.util.ForgeDirection; - -import buildcraft.api.core.BlockIndex; - -public interface IDockingStation { - - int x(); - - int y(); - - int z(); - - ForgeDirection side(); - - EntityRobotBase robotTaking(); - - long robotIdTaking(); - - long linkedId(); - - boolean isTaken(); - - void writeToNBT(NBTTagCompound nbt); - - void readFromNBT(NBTTagCompound nbt); - - BlockIndex index(); - - boolean take(EntityRobotBase robot); -} diff --git a/api/buildcraft/api/robots/IDockingStationPluggable.java b/api/buildcraft/api/robots/IDockingStationPluggable.java deleted file mode 100644 index 71314019..00000000 --- a/api/buildcraft/api/robots/IDockingStationPluggable.java +++ /dev/null @@ -1,5 +0,0 @@ -package buildcraft.api.robots; - -public interface IDockingStationPluggable { - IDockingStation getStation(); -} diff --git a/api/buildcraft/api/robots/IDockingStationProvider.java b/api/buildcraft/api/robots/IDockingStationProvider.java new file mode 100644 index 00000000..608c3b6b --- /dev/null +++ b/api/buildcraft/api/robots/IDockingStationProvider.java @@ -0,0 +1,8 @@ +package buildcraft.api.robots; + +/** + * By default, this can be either an IPipePluggable or a TileEntity. + */ +public interface IDockingStationProvider { + DockingStation getStation(); +} diff --git a/api/buildcraft/api/robots/IRobotRegistry.java b/api/buildcraft/api/robots/IRobotRegistry.java index 1c9bb425..def62db4 100755 --- a/api/buildcraft/api/robots/IRobotRegistry.java +++ b/api/buildcraft/api/robots/IRobotRegistry.java @@ -40,19 +40,21 @@ public interface IRobotRegistry { void releaseResources(EntityRobotBase robot); - IDockingStation getStation(int x, int y, int z, ForgeDirection side); + DockingStation getStation(int x, int y, int z, ForgeDirection side); - Collection getStations(); + Collection getStations(); - void registerStation(IDockingStation station); + void registerStation(DockingStation station); - void removeStation(IDockingStation station); + void removeStation(DockingStation station); - void take(IDockingStation station, long robotId); + void take(DockingStation station, long robotId); - void release(IDockingStation station, long robotId); + void release(DockingStation station, long robotId); void writeToNBT(NBTTagCompound nbt); void readFromNBT(NBTTagCompound nbt); + + void markDirty(); } diff --git a/api/buildcraft/api/robots/StackRequest.java b/api/buildcraft/api/robots/StackRequest.java index e1f5f768..888622dd 100755 --- a/api/buildcraft/api/robots/StackRequest.java +++ b/api/buildcraft/api/robots/StackRequest.java @@ -15,5 +15,5 @@ public class StackRequest { public ItemStack stack; public int index; public TileEntity requester; - public IDockingStation station; + public DockingStation station; } diff --git a/buildcraft_resources/assets/buildcraftcore/textures/gui/buttons.png b/buildcraft_resources/assets/buildcraftcore/textures/gui/buttons.png index 7a53811c..099e2974 100755 Binary files a/buildcraft_resources/assets/buildcraftcore/textures/gui/buttons.png and b/buildcraft_resources/assets/buildcraftcore/textures/gui/buttons.png differ diff --git a/buildcraft_resources/assets/buildcraftrobotics/textures/gui/zone_planner_gui.png b/buildcraft_resources/assets/buildcraftrobotics/textures/gui/zone_planner_gui.png index 51046c81..1f365e2c 100755 Binary files a/buildcraft_resources/assets/buildcraftrobotics/textures/gui/zone_planner_gui.png and b/buildcraft_resources/assets/buildcraftrobotics/textures/gui/zone_planner_gui.png differ