further cleanup - make robots respect IPipeTile
This commit is contained in:
parent
f5c3220c53
commit
281d7409f9
5 changed files with 55 additions and 20 deletions
22
common/buildcraft/robots/RobotUtils.java
Normal file
22
common/buildcraft/robots/RobotUtils.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package buildcraft.robots;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
|
||||
/**
|
||||
* Created by asie on 1/24/15.
|
||||
*/
|
||||
public class RobotUtils {
|
||||
private RobotUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static DockingStation getStation(IPipeTile tile, ForgeDirection d) {
|
||||
if (tile.getPipePluggable(d) instanceof RobotStationPluggable) {
|
||||
RobotStationPluggable pluggable = (RobotStationPluggable) tile.getPipePluggable(d);
|
||||
return pluggable.getStation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,9 @@ import buildcraft.api.statements.IActionInternal;
|
|||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
import buildcraft.api.statements.StatementParameterItemStack;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.core.ItemMapLocation;
|
||||
import buildcraft.robots.RobotUtils;
|
||||
import buildcraft.robots.ai.AIRobotGoAndLinkToDock;
|
||||
import buildcraft.robots.DockingStation;
|
||||
import buildcraft.robots.EntityRobot;
|
||||
|
@ -47,11 +49,15 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern
|
|||
|
||||
@Override
|
||||
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
|
||||
Pipe<?> pipe = ((Gate) container).pipe;
|
||||
RobotRegistry registry = RobotRegistry.getRegistry(pipe.getWorld());
|
||||
if (!(container.getTile() instanceof IPipeTile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IPipeTile tile = (IPipeTile) container.getTile();
|
||||
RobotRegistry registry = RobotRegistry.getRegistry(tile.getWorldObj());
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
|
||||
DockingStation station = pipe.container.getStation(d);
|
||||
DockingStation station = RobotUtils.getStation(tile, d);
|
||||
|
||||
if (station != null && station.robotTaking() != null) {
|
||||
EntityRobot robot = (EntityRobot) station.robotTaking();
|
||||
|
|
|
@ -27,7 +27,10 @@ import buildcraft.api.statements.IActionExternal;
|
|||
import buildcraft.api.statements.IActionInternal;
|
||||
import buildcraft.api.statements.IActionProvider;
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.robots.DockingStation;
|
||||
import buildcraft.robots.RobotUtils;
|
||||
import buildcraft.silicon.TileAssemblyTable;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
|
@ -36,19 +39,18 @@ public class RobotsActionProvider implements IActionProvider {
|
|||
|
||||
@Override
|
||||
public Collection<IActionInternal> getInternalActions(IStatementContainer container) {
|
||||
LinkedList<IActionInternal> result = new LinkedList<IActionInternal>();
|
||||
TileEntity tile = container.getTile();
|
||||
|
||||
if (!(tile instanceof TileGenericPipe)) {
|
||||
return null;
|
||||
if (!(tile instanceof IPipeTile)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
LinkedList<IActionInternal> result = new LinkedList<IActionInternal>();
|
||||
|
||||
ArrayList<DockingStation> stations = new ArrayList<DockingStation>();
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (((TileGenericPipe) tile).getStation(dir) != null) {
|
||||
stations.add(((TileGenericPipe) tile).getStation(dir));
|
||||
if (RobotUtils.getStation((IPipeTile) tile, dir) != null) {
|
||||
stations.add(RobotUtils.getStation((IPipeTile) tile, dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
package buildcraft.robots.statements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
@ -16,10 +17,14 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.statements.IActionInternal;
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
import buildcraft.api.statements.ITriggerInternal;
|
||||
import buildcraft.api.statements.ITriggerProvider;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.robots.DockingStation;
|
||||
import buildcraft.robots.RobotUtils;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
|
||||
public class RobotsTriggerProvider implements ITriggerProvider {
|
||||
|
@ -29,20 +34,19 @@ public class RobotsTriggerProvider implements ITriggerProvider {
|
|||
LinkedList<ITriggerInternal> result = new LinkedList<ITriggerInternal>();
|
||||
TileEntity tile = container.getTile();
|
||||
|
||||
if (!(tile instanceof TileGenericPipe)) {
|
||||
if (!(tile instanceof IPipeTile)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean stationFound = false;
|
||||
ArrayList<DockingStation> stations = new ArrayList<DockingStation>();
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (((TileGenericPipe) tile).getStation(dir) != null) {
|
||||
stationFound = true;
|
||||
break;
|
||||
if (RobotUtils.getStation((IPipeTile) tile, dir) != null) {
|
||||
stations.add(RobotUtils.getStation((IPipeTile) tile, dir));
|
||||
}
|
||||
}
|
||||
|
||||
if (!stationFound) {
|
||||
if (stations.size() == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import buildcraft.api.gates.IGate;
|
|||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
import buildcraft.api.statements.ITriggerInternal;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.robots.RobotUtils;
|
||||
import buildcraft.robots.ai.AIRobotSleep;
|
||||
import buildcraft.robots.DockingStation;
|
||||
import buildcraft.robots.EntityRobot;
|
||||
|
@ -42,15 +44,14 @@ public class TriggerRobotSleep extends BCStatement implements ITriggerInternal {
|
|||
|
||||
@Override
|
||||
public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) {
|
||||
if (!(container instanceof IGate)) {
|
||||
if (!(container.getTile() instanceof IPipeTile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pipe<?> pipe = (Pipe<?>) ((IGate) container).getPipe();
|
||||
TileGenericPipe tile = pipe.container;
|
||||
IPipeTile tile = (IPipeTile) container.getTile();
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
|
||||
DockingStation station = tile.getStation(d);
|
||||
DockingStation station = RobotUtils.getStation(tile, d);
|
||||
|
||||
if (station != null && station.robotTaking() != null) {
|
||||
EntityRobot robot = (EntityRobot) station.robotTaking();
|
||||
|
|
Loading…
Reference in a new issue