further cleanup - make robots respect IPipeTile

This commit is contained in:
asiekierka 2015-01-24 09:46:02 +01:00
parent f5c3220c53
commit 281d7409f9
5 changed files with 55 additions and 20 deletions

View 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;
}
}

View file

@ -19,7 +19,9 @@ import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.statements.StatementParameterItemStack;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.ItemMapLocation; import buildcraft.core.ItemMapLocation;
import buildcraft.robots.RobotUtils;
import buildcraft.robots.ai.AIRobotGoAndLinkToDock; import buildcraft.robots.ai.AIRobotGoAndLinkToDock;
import buildcraft.robots.DockingStation; import buildcraft.robots.DockingStation;
import buildcraft.robots.EntityRobot; import buildcraft.robots.EntityRobot;
@ -47,11 +49,15 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern
@Override @Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) { public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
Pipe<?> pipe = ((Gate) container).pipe; if (!(container.getTile() instanceof IPipeTile)) {
RobotRegistry registry = RobotRegistry.getRegistry(pipe.getWorld()); return;
}
IPipeTile tile = (IPipeTile) container.getTile();
RobotRegistry registry = RobotRegistry.getRegistry(tile.getWorldObj());
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
DockingStation station = pipe.container.getStation(d); DockingStation station = RobotUtils.getStation(tile, d);
if (station != null && station.robotTaking() != null) { if (station != null && station.robotTaking() != null) {
EntityRobot robot = (EntityRobot) station.robotTaking(); EntityRobot robot = (EntityRobot) station.robotTaking();

View file

@ -27,7 +27,10 @@ import buildcraft.api.statements.IActionExternal;
import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IActionProvider; import buildcraft.api.statements.IActionProvider;
import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeTile;
import buildcraft.robots.DockingStation; import buildcraft.robots.DockingStation;
import buildcraft.robots.RobotUtils;
import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
@ -36,19 +39,18 @@ public class RobotsActionProvider implements IActionProvider {
@Override @Override
public Collection<IActionInternal> getInternalActions(IStatementContainer container) { public Collection<IActionInternal> getInternalActions(IStatementContainer container) {
LinkedList<IActionInternal> result = new LinkedList<IActionInternal>();
TileEntity tile = container.getTile(); TileEntity tile = container.getTile();
if (!(tile instanceof TileGenericPipe)) { if (!(tile instanceof IPipeTile)) {
return null; return result;
} }
LinkedList<IActionInternal> result = new LinkedList<IActionInternal>();
ArrayList<DockingStation> stations = new ArrayList<DockingStation>(); ArrayList<DockingStation> stations = new ArrayList<DockingStation>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (((TileGenericPipe) tile).getStation(dir) != null) { if (RobotUtils.getStation((IPipeTile) tile, dir) != null) {
stations.add(((TileGenericPipe) tile).getStation(dir)); stations.add(RobotUtils.getStation((IPipeTile) tile, dir));
} }
} }

View file

@ -8,6 +8,7 @@
*/ */
package buildcraft.robots.statements; package buildcraft.robots.statements;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
@ -16,10 +17,14 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftSilicon; import buildcraft.BuildCraftSilicon;
import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.ITriggerExternal; import buildcraft.api.statements.ITriggerExternal;
import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerInternal;
import buildcraft.api.statements.ITriggerProvider; import buildcraft.api.statements.ITriggerProvider;
import buildcraft.api.transport.IPipeTile;
import buildcraft.robots.DockingStation;
import buildcraft.robots.RobotUtils;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
public class RobotsTriggerProvider implements ITriggerProvider { public class RobotsTriggerProvider implements ITriggerProvider {
@ -29,20 +34,19 @@ public class RobotsTriggerProvider implements ITriggerProvider {
LinkedList<ITriggerInternal> result = new LinkedList<ITriggerInternal>(); LinkedList<ITriggerInternal> result = new LinkedList<ITriggerInternal>();
TileEntity tile = container.getTile(); TileEntity tile = container.getTile();
if (!(tile instanceof TileGenericPipe)) { if (!(tile instanceof IPipeTile)) {
return result; return result;
} }
boolean stationFound = false; ArrayList<DockingStation> stations = new ArrayList<DockingStation>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (((TileGenericPipe) tile).getStation(dir) != null) { if (RobotUtils.getStation((IPipeTile) tile, dir) != null) {
stationFound = true; stations.add(RobotUtils.getStation((IPipeTile) tile, dir));
break;
} }
} }
if (!stationFound) { if (stations.size() == 0) {
return result; return result;
} }

View file

@ -16,6 +16,8 @@ import buildcraft.api.gates.IGate;
import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.ITriggerInternal; import buildcraft.api.statements.ITriggerInternal;
import buildcraft.api.transport.IPipeTile;
import buildcraft.robots.RobotUtils;
import buildcraft.robots.ai.AIRobotSleep; import buildcraft.robots.ai.AIRobotSleep;
import buildcraft.robots.DockingStation; import buildcraft.robots.DockingStation;
import buildcraft.robots.EntityRobot; import buildcraft.robots.EntityRobot;
@ -42,15 +44,14 @@ public class TriggerRobotSleep extends BCStatement implements ITriggerInternal {
@Override @Override
public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) { public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) {
if (!(container instanceof IGate)) { if (!(container.getTile() instanceof IPipeTile)) {
return false; return false;
} }
Pipe<?> pipe = (Pipe<?>) ((IGate) container).getPipe(); IPipeTile tile = (IPipeTile) container.getTile();
TileGenericPipe tile = pipe.container;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
DockingStation station = tile.getStation(d); DockingStation station = RobotUtils.getStation(tile, d);
if (station != null && station.robotTaking() != null) { if (station != null && station.robotTaking() != null) {
EntityRobot robot = (EntityRobot) station.robotTaking(); EntityRobot robot = (EntityRobot) station.robotTaking();