Merge pull request #2635 from hea3ven/robot-fixes

Robot fixes
This commit is contained in:
Adrian Siekierka 2015-04-15 13:12:12 +02:00
commit 875c8e47ee
36 changed files with 588 additions and 530 deletions

View file

@ -8,14 +8,16 @@
*/ */
package buildcraft.api.robots; package buildcraft.api.robots;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BlockIndex;
import buildcraft.api.transport.IPipeTile; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IInjectable;
public class DockingStation { public abstract class DockingStation {
public ForgeDirection side; public ForgeDirection side;
public World world; public World world;
@ -25,20 +27,12 @@ public class DockingStation {
private boolean linkIsMain = false; private boolean linkIsMain = false;
private BlockIndex index; private BlockIndex index;
private IPipeTile pipe;
public DockingStation(BlockIndex iIndex, ForgeDirection iSide) { public DockingStation(BlockIndex iIndex, ForgeDirection iSide) {
index = iIndex; index = iIndex;
side = iSide; 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 DockingStation() {
} }
@ -46,20 +40,6 @@ public class DockingStation {
return linkIsMain; 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() { public int x() {
return index.x; return index.x;
} }
@ -80,7 +60,8 @@ public class DockingStation {
if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) { if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) {
return null; return null;
} else if (robotTaking == null) { } else if (robotTaking == null) {
robotTaking = RobotManager.registryProvider.getRegistry(world).getLoadedRobot(robotTakingId); robotTaking = RobotManager.registryProvider.getRegistry(world).getLoadedRobot(
robotTakingId);
} }
return robotTaking; return robotTaking;
@ -100,7 +81,6 @@ public class DockingStation {
linkIsMain = true; linkIsMain = true;
robotTaking = robot; robotTaking = robot;
robotTakingId = robot.getRobotId(); robotTakingId = robot.getRobotId();
getPipe().scheduleRenderUpdate();
registry.registryMarkDirty(); registry.registryMarkDirty();
robot.setMainStation(this); robot.setMainStation(this);
registry.take(this, robot.getRobotId()); registry.take(this, robot.getRobotId());
@ -117,7 +97,6 @@ public class DockingStation {
linkIsMain = false; linkIsMain = false;
robotTaking = robot; robotTaking = robot;
robotTakingId = robot.getRobotId(); robotTakingId = robot.getRobotId();
getPipe().scheduleRenderUpdate();
registry.registryMarkDirty(); registry.registryMarkDirty();
registry.take(this, robot.getRobotId()); registry.take(this, robot.getRobotId());
@ -145,7 +124,6 @@ public class DockingStation {
linkIsMain = false; linkIsMain = false;
robotTaking = null; robotTaking = null;
robotTakingId = EntityRobotBase.NULL_ROBOT_ID; robotTakingId = EntityRobotBase.NULL_ROBOT_ID;
getPipe().scheduleRenderUpdate();
} }
} }
@ -159,7 +137,7 @@ public class DockingStation {
} }
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
index = new BlockIndex (nbt.getCompoundTag("index")); index = new BlockIndex(nbt.getCompoundTag("index"));
side = ForgeDirection.values()[nbt.getByte("side")]; side = ForgeDirection.values()[nbt.getByte("side")];
linkIsMain = nbt.getBoolean("isMain"); linkIsMain = nbt.getBoolean("isMain");
robotTakingId = nbt.getLong("robotId"); robotTakingId = nbt.getLong("robotId");
@ -179,7 +157,8 @@ public class DockingStation {
@Override @Override
public String toString() { public String toString() {
return "{" + index.x + ", " + index.y + ", " + index.z + ", " + side + " :" + robotTakingId + "}"; return "{" + index.x + ", " + index.y + ", " + index.z + ", " + side + " :" + robotTakingId
+ "}";
} }
public boolean linkIsDocked() { public boolean linkIsDocked() {
@ -193,5 +172,35 @@ public class DockingStation {
public boolean canRelease() { public boolean canRelease() {
return !isMainStation() && !linkIsDocked(); return !isMainStation() && !linkIsDocked();
} }
}
public boolean isInitialized() {
return true;
}
public abstract Iterable<StatementSlot> getActiveActions();
public IInjectable getItemOutput() {
return null;
}
public IInventory getItemInput() {
return null;
}
public IFluidHandler getFluidOutput() {
return null;
}
public IFluidHandler getFluidInput() {
return null;
}
public boolean providesPower() {
return false;
}
public IRequestProvider getRequestProvider() {
return null;
}
}

View file

@ -24,6 +24,8 @@ public abstract class RobotManager {
resourceIdNames = new HashMap<Class<? extends ResourceId>, String>(); resourceIdNames = new HashMap<Class<? extends ResourceId>, String>();
resourceIdByNames = new HashMap<String, Class<? extends ResourceId>>(); resourceIdByNames = new HashMap<String, Class<? extends ResourceId>>();
resourceIdLegacyClassNames = new HashMap<String, Class<? extends ResourceId>>(); resourceIdLegacyClassNames = new HashMap<String, Class<? extends ResourceId>>();
dockingStationNames = new HashMap<Class<? extends DockingStation>, String>();
dockingStationByNames = new HashMap<String, Class<? extends DockingStation>>();
registerResourceId(ResourceIdBlock.class, "resourceIdBlock", "buildcraft.core.robots.ResourceIdBlock"); registerResourceId(ResourceIdBlock.class, "resourceIdBlock", "buildcraft.core.robots.ResourceIdBlock");
registerResourceId(ResourceIdRequest.class, "resourceIdRequest", "buildcraft.core.robots.ResourceIdRequest"); registerResourceId(ResourceIdRequest.class, "resourceIdRequest", "buildcraft.core.robots.ResourceIdRequest");
@ -37,6 +39,9 @@ public abstract class RobotManager {
private static Map<String, Class<? extends ResourceId>> resourceIdByNames; private static Map<String, Class<? extends ResourceId>> resourceIdByNames;
private static Map<String, Class<? extends ResourceId>> resourceIdLegacyClassNames; private static Map<String, Class<? extends ResourceId>> resourceIdLegacyClassNames;
private static Map<Class<? extends DockingStation>, String> dockingStationNames;
private static Map<String, Class<? extends DockingStation>> dockingStationByNames;
public static void registerAIRobot(Class<? extends AIRobot> aiRobot, String name) { public static void registerAIRobot(Class<? extends AIRobot> aiRobot, String name) {
registerAIRobot(aiRobot, name, null); registerAIRobot(aiRobot, name, null);
} }
@ -88,4 +93,17 @@ public abstract class RobotManager {
public static Class<?> getResourceIdByLegacyClassName(String resourceIdLegacyClassName) { public static Class<?> getResourceIdByLegacyClassName(String resourceIdLegacyClassName) {
return resourceIdLegacyClassNames.get(resourceIdLegacyClassName); return resourceIdLegacyClassNames.get(resourceIdLegacyClassName);
} }
public static void registerDockingStation(Class<? extends DockingStation> dockingStation, String name) {
dockingStationByNames.put(name, dockingStation);
dockingStationNames.put(dockingStation, name);
}
public static Class<? extends DockingStation> getDockingStationByName(String dockingStationTypeName) {
return dockingStationByNames.get(dockingStationTypeName);
}
public static String getDockingStationName(Class<? extends DockingStation> dockingStation) {
return dockingStationNames.get(dockingStation);
}
} }

View file

@ -141,7 +141,8 @@ gate.action.station.povide_fluids=Provide Fluids
gate.action.robot.work_in_area=Work in Area gate.action.robot.work_in_area=Work in Area
gate.action.robot.load_unload_area=Load/Unload in Area gate.action.robot.load_unload_area=Load/Unload in Area
gate.action.robot.wakeup=Wake Up gate.action.robot.wakeup=Wake Up
gate.action.station.forbid_robot=Robot Forbidden gate.action.station.forbid_robot=Forbid Robot
gate.action.station.forbid_robot=Force Robot
gate.action.robot.filter=Filter gate.action.robot.filter=Filter
gate.action.robot.filter_tool=Filter Tool gate.action.robot.filter_tool=Filter Tool
@ -196,6 +197,9 @@ gate.trigger.pipe.wire.active=%s Pipe Signal On
gate.trigger.pipe.wire.inactive=%s Pipe Signal Off gate.trigger.pipe.wire.inactive=%s Pipe Signal Off
gate.trigger.timer=%s Sec Timer gate.trigger.timer=%s Sec Timer
gate.trigger.robot.sleep=Sleep gate.trigger.robot.sleep=Sleep
gate.trigger.robot.in.station=Robot In Station
gate.trigger.robot.linked=Station Linked
gate.trigger.robot.reserved=Station Reserved
gate.trigger.machine.energyStored.high=High Energy Stored gate.trigger.machine.energyStored.high=High Energy Stored
gate.trigger.machine.energyStored.low=Low Energy Stored gate.trigger.machine.energyStored.low=Low Energy Stored
gate.trigger.machine.energyStored.below25=Energy < 25% gate.trigger.machine.energyStored.below25=Energy < 25%

View file

@ -49,6 +49,7 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.robotics.BlockRequester; import buildcraft.robotics.BlockRequester;
import buildcraft.robotics.BlockZonePlan; import buildcraft.robotics.BlockZonePlan;
import buildcraft.robotics.BoardProgrammingRecipe; import buildcraft.robotics.BoardProgrammingRecipe;
import buildcraft.robotics.DockingStationPipe;
import buildcraft.robotics.EntityRobot; import buildcraft.robotics.EntityRobot;
import buildcraft.robotics.ImplRedstoneBoardRegistry; import buildcraft.robotics.ImplRedstoneBoardRegistry;
import buildcraft.robotics.ItemRedstoneBoard; import buildcraft.robotics.ItemRedstoneBoard;
@ -142,6 +143,7 @@ import buildcraft.robotics.statements.ActionRobotFilterTool;
import buildcraft.robotics.statements.ActionRobotGotoStation; import buildcraft.robotics.statements.ActionRobotGotoStation;
import buildcraft.robotics.statements.ActionRobotWakeUp; import buildcraft.robotics.statements.ActionRobotWakeUp;
import buildcraft.robotics.statements.ActionRobotWorkInArea; import buildcraft.robotics.statements.ActionRobotWorkInArea;
import buildcraft.robotics.statements.ActionRobotWorkInArea.AreaType;
import buildcraft.robotics.statements.ActionStationAcceptFluids; import buildcraft.robotics.statements.ActionStationAcceptFluids;
import buildcraft.robotics.statements.ActionStationAcceptItems; import buildcraft.robotics.statements.ActionStationAcceptItems;
import buildcraft.robotics.statements.ActionStationAllowCraft; import buildcraft.robotics.statements.ActionStationAllowCraft;
@ -155,7 +157,6 @@ import buildcraft.robotics.statements.RobotsTriggerProvider;
import buildcraft.robotics.statements.TriggerRobotInStation; import buildcraft.robotics.statements.TriggerRobotInStation;
import buildcraft.robotics.statements.TriggerRobotLinked; import buildcraft.robotics.statements.TriggerRobotLinked;
import buildcraft.robotics.statements.TriggerRobotSleep; import buildcraft.robotics.statements.TriggerRobotSleep;
import buildcraft.robotics.statements.ActionRobotWorkInArea.AreaType;
import buildcraft.silicon.ItemRedstoneChipset; import buildcraft.silicon.ItemRedstoneChipset;
@Mod(name = "BuildCraft Robotics", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Robotics", dependencies = DefaultProps.DEPENDENCY_CORE) @Mod(name = "BuildCraft Robotics", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Robotics", dependencies = DefaultProps.DEPENDENCY_CORE)
@ -343,6 +344,8 @@ public class BuildCraftRobotics extends BuildCraftMod {
RobotManager.registerAIRobot(AIRobotUnloadFluids.class, "aiRobotUnloadFluids", "buildcraft.core.robots.AIRobotUnloadFluids"); RobotManager.registerAIRobot(AIRobotUnloadFluids.class, "aiRobotUnloadFluids", "buildcraft.core.robots.AIRobotUnloadFluids");
RobotManager.registerAIRobot(AIRobotUseToolOnBlock.class, "aiRobotUseToolOnBlock", "buildcraft.core.robots.AIRobotUseToolOnBlock"); RobotManager.registerAIRobot(AIRobotUseToolOnBlock.class, "aiRobotUseToolOnBlock", "buildcraft.core.robots.AIRobotUseToolOnBlock");
RobotManager.registerDockingStation(DockingStationPipe.class, "dockingStationPipe");
RoboticsProxy.proxy.registerRenderers(); RoboticsProxy.proxy.registerRenderers();
} }

View file

@ -0,0 +1,188 @@
package buildcraft.robotics;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.EnumColor;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.robots.RobotManager;
import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IInjectable;
import buildcraft.api.transport.IPipeTile;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.pipes.PipeFluidsWood;
import buildcraft.transport.pipes.PipeItemsWood;
public class DockingStationPipe extends DockingStation {
private IInjectable injectablePipe = new IInjectable() {
@Override
public boolean canInjectItems(ForgeDirection from) {
return true;
}
@Override
public int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from, EnumColor color) {
if (doAdd) {
float cx = x() + 0.5F + 0.2F * side().offsetX;
float cy = y() + 0.5F + 0.2F * side().offsetY;
float cz = z() + 0.5F + 0.2F * side().offsetZ;
TravelingItem item = TravelingItem.make(cx, cy, cz, stack);
((PipeTransportItems) ((Pipe) getPipe().getPipe()).transport)
.injectItem(item, from);
}
return stack.stackSize;
}
};
private IPipeTile pipe;
public DockingStationPipe() {
// Loading later from NBT
}
public DockingStationPipe(IPipeTile iPipe, ForgeDirection side) {
super(new BlockIndex(iPipe.x(), iPipe.y(), iPipe.z()), side);
pipe = iPipe;
world = iPipe.getWorld();
}
public IPipeTile getPipe() {
if (pipe == null) {
pipe = (IPipeTile) world.getTileEntity(x(), y(), z());
}
if (pipe == null || ((TileEntity) pipe).isInvalid()) {
// Inconsistency - remove this pipe from the registry.
RobotManager.registryProvider.getRegistry(world).removeStation(this);
pipe = null;
}
return pipe;
}
@Override
public Iterable<StatementSlot> getActiveActions() {
return new ActionIterator(getPipe().getPipe());
}
@Override
public IInjectable getItemOutput() {
if (getPipe().getPipeType() != IPipeTile.PipeType.ITEM) {
return null;
}
return injectablePipe;
}
@Override
public IInventory getItemInput() {
if (getPipe().getPipeType() != IPipeTile.PipeType.ITEM) {
return null;
}
if (!(getPipe().getPipe() instanceof PipeItemsWood)) {
return null;
}
int meta = ((TileEntity) getPipe()).getBlockMetadata();
ForgeDirection dir = ForgeDirection.getOrientation(meta);
TileEntity connectedTile = getPipe().getWorld().getTileEntity(x() + dir.offsetX,
y() + dir.offsetY, z() + dir.offsetZ);
if (connectedTile instanceof IInventory) {
return (IInventory) connectedTile;
}
return null;
}
@Override
public IFluidHandler getFluidInput() {
if (getPipe().getPipeType() != IPipeTile.PipeType.FLUID) {
return null;
}
if (!(getPipe().getPipe() instanceof PipeFluidsWood)) {
return null;
}
int meta = ((TileEntity) getPipe()).getBlockMetadata();
ForgeDirection dir = ForgeDirection.getOrientation(meta);
TileEntity connectedTile = getPipe().getWorld().getTileEntity(x() + dir.offsetX,
y() + dir.offsetY, z() + dir.offsetZ);
if (connectedTile instanceof IFluidHandler) {
return (IFluidHandler) connectedTile;
}
return null;
}
@Override
public IFluidHandler getFluidOutput() {
if (getPipe().getPipeType() != IPipeTile.PipeType.FLUID) {
return null;
}
return (IFluidHandler) ((Pipe) getPipe().getPipe()).transport;
}
@Override
public boolean providesPower() {
return getPipe().getPipeType() == IPipeTile.PipeType.POWER;
}
@Override
public IRequestProvider getRequestProvider() {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = getPipe().getWorld().getTileEntity(x() + dir.offsetX,
y() + dir.offsetY, z() + dir.offsetZ);
if (nearbyTile instanceof IRequestProvider) {
return (IRequestProvider) nearbyTile;
}
}
return null;
}
@Override
public boolean isInitialized() {
return ((Pipe) getPipe().getPipe()).isInitialized();
}
@Override
public boolean take(EntityRobotBase robot) {
boolean result = super.take(robot);
if (result) {
getPipe().scheduleRenderUpdate();
}
return result;
}
@Override
public boolean takeAsMain(EntityRobotBase robot) {
boolean result = super.takeAsMain(robot);
if (result) {
getPipe().scheduleRenderUpdate();
}
return result;
}
@Override
public void unsafeRelease(EntityRobotBase robot) {
super.unsafeRelease(robot);
if (robotTaking() == null) {
getPipe().scheduleRenderUpdate();
}
}
}

View file

@ -53,7 +53,6 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.RobotManager; import buildcraft.api.robots.RobotManager;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.tiles.IDebuggable; import buildcraft.api.tiles.IDebuggable;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.ItemWrench; import buildcraft.core.ItemWrench;
import buildcraft.core.LaserData; import buildcraft.core.LaserData;
@ -68,8 +67,6 @@ import buildcraft.robotics.ai.AIRobotShutdown;
import buildcraft.robotics.ai.AIRobotSleep; import buildcraft.robotics.ai.AIRobotSleep;
import buildcraft.robotics.statements.ActionRobotWorkInArea; import buildcraft.robotics.statements.ActionRobotWorkInArea;
import buildcraft.robotics.statements.ActionRobotWorkInArea.AreaType; import buildcraft.robotics.statements.ActionRobotWorkInArea.AreaType;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.ActionIterator;
public class EntityRobot extends EntityRobotBase implements public class EntityRobot extends EntityRobotBase implements
IEntityAdditionalSpawnData, IInventory, IFluidHandler, ICommandReceiver, IDebuggable { IEntityAdditionalSpawnData, IInventory, IFluidHandler, ICommandReceiver, IDebuggable {
@ -315,8 +312,7 @@ public class EntityRobot extends EntityRobotBase implements
currentDockingStationSide); currentDockingStationSide);
} }
if (linkedDockingStation == null || if (linkedDockingStation == null || linkedDockingStation.isInitialized()) {
((Pipe) linkedDockingStation.getPipe().getPipe()).isInitialized()) {
this.worldObj.theProfiler.startSection("bcRobotAIMainCycle"); this.worldObj.theProfiler.startSection("bcRobotAIMainCycle");
mainAI.cycle(); mainAI.cycle();
this.worldObj.theProfiler.endSection(); this.worldObj.theProfiler.endSection();
@ -332,16 +328,6 @@ public class EntityRobot extends EntityRobotBase implements
this.worldObj.theProfiler.endSection(); this.worldObj.theProfiler.endSection();
} }
private boolean linkedToChargeStation() {
if (currentDockingStation == null) {
return false;
}
if (currentDockingStation.getPipe().getPipeType() != IPipeTile.PipeType.POWER) {
return false;
}
return true;
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
private void updateEnergyFX() { private void updateEnergyFX() {
energyFX += energySpendPerCycle; energyFX += energySpendPerCycle;
@ -358,7 +344,7 @@ public class EntityRobot extends EntityRobotBase implements
worldObj, worldObj,
posX + steamDx * 0.25, posY + steamDy * 0.25, posZ + steamDz * 0.25, posX + steamDx * 0.25, posY + steamDy * 0.25, posZ + steamDz * 0.25,
steamDx * 0.05, steamDy * 0.05, steamDz * 0.05, steamDx * 0.05, steamDy * 0.05, steamDz * 0.05,
energySpendPerCycle * 0.075F < 1 ? 1 : energySpendPerCycle * 0.075F)); energySpendPerCycle * 0.075F < 1 ? 1 : energySpendPerCycle * 0.075F));
} }
public void setRegularBoundingBox() { public void setRegularBoundingBox() {
@ -586,7 +572,7 @@ public class EntityRobot extends EntityRobotBase implements
@Override @Override
public void dock(DockingStation station) { public void dock(DockingStation station) {
currentDockingStation = (DockingStation) station; currentDockingStation = station;
setSteamDirection( setSteamDirection(
currentDockingStation.side.offsetX, currentDockingStation.side.offsetX,
@ -901,8 +887,6 @@ public class EntityRobot extends EntityRobotBase implements
} }
public void attackTargetEntityWithCurrentItem(Entity par1Entity) { public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
ItemStack stack = itemInUse;
if (par1Entity.canAttackWithItem()) { if (par1Entity.canAttackWithItem()) {
if (!par1Entity.hitByEntity(this)) { if (!par1Entity.hitByEntity(this)) {
this.setLastAttacker(par1Entity); this.setLastAttacker(par1Entity);
@ -915,7 +899,6 @@ public class EntityRobot extends EntityRobotBase implements
if (itemstack != null && object instanceof EntityLivingBase) { if (itemstack != null && object instanceof EntityLivingBase) {
itemstack.getItem().hitEntity(itemstack, (EntityLivingBase) object, this); itemstack.getItem().hitEntity(itemstack, (EntityLivingBase) object, this);
} }
} }
} }
} }
@ -935,7 +918,7 @@ public class EntityRobot extends EntityRobotBase implements
} }
private IZone getZone(AreaType areaType) { private IZone getZone(AreaType areaType) {
for (StatementSlot s : new ActionIterator(linkedDockingStation.getPipe().getPipe())) { for (StatementSlot s : linkedDockingStation.getActiveActions()) {
if (s.statement instanceof ActionRobotWorkInArea if (s.statement instanceof ActionRobotWorkInArea
&& ((ActionRobotWorkInArea) s.statement).getAreaType() == areaType) { && ((ActionRobotWorkInArea) s.statement).getAreaType() == areaType) {
IZone zone = ActionRobotWorkInArea.getArea(s); IZone zone = ActionRobotWorkInArea.getArea(s);

View file

@ -27,6 +27,7 @@ import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRobotRegistry; import buildcraft.api.robots.IRobotRegistry;
import buildcraft.api.robots.ResourceId; import buildcraft.api.robots.ResourceId;
import buildcraft.api.robots.RobotManager;
public class RobotRegistry extends WorldSavedData implements IRobotRegistry { public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
@ -204,7 +205,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
.clone(); .clone();
for (StationIndex s : stationSet) { for (StationIndex s : stationSet) {
DockingStation d = (DockingStation) stations.get(s); DockingStation d = stations.get(s);
if (d != null) { if (d != null) {
if (!d.canRelease()) { if (!d.canRelease()) {
@ -316,6 +317,7 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
for (Map.Entry<StationIndex, DockingStation> e : stations.entrySet()) { for (Map.Entry<StationIndex, DockingStation> e : stations.entrySet()) {
NBTTagCompound cpt = new NBTTagCompound(); NBTTagCompound cpt = new NBTTagCompound();
e.getValue().writeToNBT(cpt); e.getValue().writeToNBT(cpt);
cpt.setString("stationType", RobotManager.getDockingStationName(e.getValue().getClass()));
stationList.appendTag(cpt); stationList.appendTag(cpt);
} }
@ -340,13 +342,31 @@ public class RobotRegistry extends WorldSavedData implements IRobotRegistry {
for (int i = 0; i < stationList.tagCount(); ++i) { for (int i = 0; i < stationList.tagCount(); ++i) {
NBTTagCompound cpt = stationList.getCompoundTagAt(i); NBTTagCompound cpt = stationList.getCompoundTagAt(i);
DockingStation station = new DockingStation();
station.readFromNBT(cpt);
registerStation(station); Class<? extends DockingStation> cls = null;
if (station.linkedId() != EntityRobotBase.NULL_ROBOT_ID) { if (!cpt.hasKey("stationType")) {
take(station, station.linkedId()); cls = DockingStationPipe.class;
} else {
cls = RobotManager.getDockingStationByName(cpt.getString("stationType"));
if (cls == null) {
BCLog.logger.error("Could not load docking station of type "
+ nbt.getString("stationType"));
continue;
}
}
try {
DockingStation station = cls.newInstance();
station.readFromNBT(cpt);
registerStation(station);
if (station.linkedId() != EntityRobotBase.NULL_ROBOT_ID) {
take(station, station.linkedId());
}
} catch (Exception e) {
BCLog.logger.error("Could not load docking station", e);
} }
} }
} }

View file

@ -24,7 +24,7 @@ public class RobotRegistryProvider implements IRobotRegistryProvider {
newRegistry.world = world; newRegistry.world = world;
for (DockingStation d : newRegistry.stations.values()) { for (DockingStation d : newRegistry.stations.values()) {
((DockingStation) d).world = world; d.world = world;
} }
MinecraftForge.EVENT_BUS.register(newRegistry); MinecraftForge.EVENT_BUS.register(newRegistry);

View file

@ -153,7 +153,7 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab
} }
private RobotStationState renderState; private RobotStationState renderState;
private DockingStation station; private DockingStationPipe station;
private boolean isValid = false; private boolean isValid = false;
public RobotStationPluggable() { public RobotStationPluggable() {
@ -199,7 +199,7 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab
public void validate(IPipeTile pipe, ForgeDirection direction) { public void validate(IPipeTile pipe, ForgeDirection direction) {
TileGenericPipe gPipe = (TileGenericPipe) pipe; TileGenericPipe gPipe = (TileGenericPipe) pipe;
if (!isValid && !gPipe.getWorld().isRemote) { if (!isValid && !gPipe.getWorld().isRemote) {
station = (DockingStation) station = (DockingStationPipe)
RobotManager.registryProvider.getRegistry(gPipe.getWorld()).getStation( RobotManager.registryProvider.getRegistry(gPipe.getWorld()).getStation(
gPipe.xCoord, gPipe.xCoord,
gPipe.yCoord, gPipe.yCoord,
@ -207,7 +207,7 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab
direction); direction);
if (station == null) { if (station == null) {
station = new DockingStation(gPipe, direction); station = new DockingStationPipe(gPipe, direction);
RobotManager.registryProvider.getRegistry(gPipe.getWorld()).registerStation(station); RobotManager.registryProvider.getRegistry(gPipe.getWorld()).registerStation(station);
} }

View file

@ -105,7 +105,7 @@ public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
terminate(); terminate();
} }
} else if (ai instanceof AIRobotSearchAndGotoStation) { } else if (ai instanceof AIRobotSearchAndGotoStation) {
if (new StationWorkbenchFilter().matches((DockingStation) robot.getDockingStation())) { if (new StationWorkbenchFilter().matches(robot.getDockingStation())) {
craftingTimer = 40; craftingTimer = 40;
} else { } else {
terminate(); terminate();

View file

@ -9,20 +9,13 @@
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRequestProvider; import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.robots.StackRequest; import buildcraft.api.robots.StackRequest;
import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IPipe;
import buildcraft.core.lib.inventory.InvUtils; import buildcraft.core.lib.inventory.InvUtils;
import buildcraft.core.lib.inventory.filters.ArrayStackOrListFilter; import buildcraft.core.lib.inventory.filters.ArrayStackOrListFilter;
import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionStationRequestItemsMachine;
import buildcraft.transport.gates.ActionIterator;
public class AIRobotDeliverRequested extends AIRobot { public class AIRobotDeliverRequested extends AIRobot {
@ -85,30 +78,4 @@ public class AIRobotDeliverRequested extends AIRobot {
public boolean success() { public boolean success() {
return delivered; return delivered;
} }
private class StationProviderFilter implements IStationFilter {
@Override
public boolean matches(DockingStation station) {
boolean actionFound = false;
IPipe pipe = station.getPipe().getPipe();
if (!station.index().nextTo(new BlockIndex(requested.requester))) {
return false;
}
for (StatementSlot s : new ActionIterator(pipe)) {
if (s.statement instanceof ActionStationRequestItemsMachine) {
actionFound = true;
}
}
if (!actionFound) {
return false;
}
return true;
}
}
} }

View file

@ -37,7 +37,7 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
@Override @Override
public void update() { public void update() {
startDelegateAI(new AIRobotGotoStationToLoad(robot, filter)); startDelegateAI(new AIRobotGotoStationToLoad(robot, filter, 1));
} }
@Override @Override
@ -61,14 +61,13 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
private void equipItemStack() { private void equipItemStack() {
if (robot.getDockingStation() != null) { if (robot.getDockingStation() != null) {
DockingStation station = (DockingStation) robot.getDockingStation(); DockingStation station = robot.getDockingStation();
ItemStack itemFound = null; ItemStack itemFound = null;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX,
station.y() station.y() + dir.offsetY, station.z() + dir.offsetZ);
+ dir.offsetY, station.z() + dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) { if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile); ITransactor trans = Transactor.getTransactorFor(nearbyTile);

View file

@ -34,11 +34,13 @@ public class AIRobotGotoStation extends AIRobot {
@Override @Override
public void start() { public void start() {
DockingStation station = (DockingStation) DockingStation station = robot.getRegistry().getStation(stationIndex.x, stationIndex.y,
robot.getRegistry().getStation(stationIndex.x, stationIndex.y, stationIndex.z, stationIndex.z, stationSide);
stationSide);
if (station == null || station == robot.getDockingStation()) { if (station == null) {
terminate();
} else if (station == robot.getDockingStation()) {
setSuccess(true);
terminate(); terminate();
} else { } else {
if (station.take(robot)) { if (station.take(robot)) {
@ -54,9 +56,8 @@ public class AIRobotGotoStation extends AIRobot {
@Override @Override
public void delegateAIEnded(AIRobot ai) { public void delegateAIEnded(AIRobot ai) {
DockingStation station = (DockingStation) DockingStation station = robot.getRegistry().getStation(stationIndex.x, stationIndex.y,
robot.getRegistry().getStation(stationIndex.x, stationIndex.y, stationIndex.z, stationIndex.z, stationSide);
stationSide);
if (station == null) { if (station == null) {
terminate(); terminate();

View file

@ -30,7 +30,7 @@ public class AIRobotGotoStationAndLoad extends AIRobot {
@Override @Override
public void start() { public void start() {
startDelegateAI(new AIRobotGotoStationToLoad(robot, filter)); startDelegateAI(new AIRobotGotoStationToLoad(robot, filter, quantity));
} }
@Override @Override
@ -42,6 +42,9 @@ public class AIRobotGotoStationAndLoad extends AIRobot {
setSuccess(false); setSuccess(false);
terminate(); terminate();
} }
} else if (ai instanceof AIRobotGotoStationToLoad) {
setSuccess(ai.success());
terminate();
} }
} }
} }

View file

@ -8,31 +8,26 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.lib.inventory.ITransactor;
import buildcraft.core.lib.inventory.Transactor;
import buildcraft.core.lib.inventory.filters.IStackFilter; import buildcraft.core.lib.inventory.filters.IStackFilter;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationProvideItems;
public class AIRobotGotoStationToLoad extends AIRobot { public class AIRobotGotoStationToLoad extends AIRobot {
private IStackFilter filter; private IStackFilter filter;
private int quantity;
public AIRobotGotoStationToLoad(EntityRobotBase iRobot) { public AIRobotGotoStationToLoad(EntityRobotBase iRobot) {
super(iRobot); super(iRobot);
} }
public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter) { public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter, int iQuantity) {
this(iRobot); this(iRobot);
filter = iFilter; filter = iFilter;
quantity = iQuantity;
} }
@Override @Override
@ -52,25 +47,7 @@ public class AIRobotGotoStationToLoad extends AIRobot {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)) { return AIRobotLoad.load(robot, station, filter, quantity, false);
return false;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile);
if (trans.remove(filter, dir.getOpposite(), false) != null) {
return true;
}
}
}
return false;
} }
} }

View file

@ -8,22 +8,14 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.core.IZone;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.lib.inventory.filters.IFluidFilter; import buildcraft.core.lib.inventory.filters.IFluidFilter;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationProvideFluids;
public class AIRobotGotoStationToLoadFluids extends AIRobot { public class AIRobotGotoStationToLoadFluids extends AIRobot {
private IZone zone;
private IFluidFilter filter; private IFluidFilter filter;
public AIRobotGotoStationToLoadFluids(EntityRobotBase iRobot) { public AIRobotGotoStationToLoadFluids(EntityRobotBase iRobot) {
@ -38,7 +30,8 @@ public class AIRobotGotoStationToLoadFluids extends AIRobot {
@Override @Override
public void update() { public void update() {
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), robot.getZoneToLoadUnload())); startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(),
robot.getZoneToLoadUnload()));
} }
@Override @Override
@ -53,31 +46,7 @@ public class AIRobotGotoStationToLoadFluids extends AIRobot {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithFluid(station, filter, ActionStationProvideFluids.class)) { return AIRobotLoadFluids.load(robot, station, filter, false) > 0;
return false;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IFluidHandler) {
IFluidHandler handler = (IFluidHandler) nearbyTile;
FluidStack drainable = handler.drain(station.side, 1, false);
// TODO: there is no account taken for the filter on the
// gate here. See LoadFluid, GotoStationToLoad and Load for
// items as well.
if (drainable != null
&& filter.matches(drainable.getFluid())
&& robot.canFill(ForgeDirection.UNKNOWN, drainable.getFluid())) {
return true;
}
}
}
return false;
} }
} }

View file

@ -8,18 +8,10 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IPipe;
import buildcraft.core.lib.inventory.InventoryIterator;
import buildcraft.robotics.EntityRobot;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionStationInputItems;
import buildcraft.transport.gates.ActionIterator;
public class AIRobotGotoStationToUnload extends AIRobot { public class AIRobotGotoStationToUnload extends AIRobot {
@ -43,23 +35,7 @@ public class AIRobotGotoStationToUnload extends AIRobot {
private class StationInventory implements IStationFilter { private class StationInventory implements IStationFilter {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
IPipe pipe = station.getPipe().getPipe(); return AIRobotUnload.unload(robot, station, false);
for (IInvSlot robotSlot : InventoryIterator.getIterable(robot, ForgeDirection.UNKNOWN)) {
if (robotSlot.getStackInSlot() == null) {
continue;
}
for (StatementSlot s : new ActionIterator(pipe)) {
if (s.statement instanceof ActionStationInputItems) {
if (((ActionStationInputItems) s.statement).insert(station, (EntityRobot) robot, s, robotSlot, false)) {
return true;
}
}
}
}
return false;
} }
} }

View file

@ -8,17 +8,10 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.lib.inventory.filters.SimpleFluidFilter;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationAcceptFluids;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportFluids;
public class AIRobotGotoStationToUnloadFluids extends AIRobot { public class AIRobotGotoStationToUnloadFluids extends AIRobot {
@ -28,7 +21,8 @@ public class AIRobotGotoStationToUnloadFluids extends AIRobot {
@Override @Override
public void update() { public void update() {
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), robot.getZoneToLoadUnload())); startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(),
robot.getZoneToLoadUnload()));
} }
@Override @Override
@ -43,24 +37,7 @@ public class AIRobotGotoStationToUnloadFluids extends AIRobot {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithFluid(station, return AIRobotUnloadFluids.unload(robot, station, false) > 0;
new SimpleFluidFilter(robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid),
ActionStationAcceptFluids.class)) {
return false;
}
if (((Pipe) station.getPipe().getPipe()).transport instanceof PipeTransportFluids) {
PipeTransportFluids transport = (PipeTransportFluids) ((Pipe) station.getPipe().getPipe()).transport;
FluidStack drainable = robot.drain(ForgeDirection.UNKNOWN, 1, false);
int filledAmount = transport.fill(station.side, drainable, false);
if (filledAmount > 0) {
return true;
}
}
return false;
} }
} }

View file

@ -10,7 +10,6 @@ package buildcraft.robotics.ai;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
@ -52,59 +51,62 @@ public class AIRobotLoad extends AIRobot {
waitedCycles++; waitedCycles++;
if (waitedCycles > 40) { if (waitedCycles > 40) {
doLoad(); setSuccess(load(robot, robot.getDockingStation(), filter, quantity, true));
terminate(); terminate();
} }
} }
private void doLoad() { public static boolean load(EntityRobotBase robot, DockingStation station, IStackFilter filter,
if (robot.getDockingStation() != null) { int quantity, boolean doLoad) {
DockingStation station = (DockingStation) robot.getDockingStation(); if (station == null) {
return false;
}
int loaded = 0; int loaded = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { IInventory tileInventory = station.getItemInput();
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, if (tileInventory == null) {
station.y() return false;
+ dir.offsetY, station.z() + dir.offsetZ); }
if (nearbyTile != null && nearbyTile instanceof IInventory) { for (IInvSlot slot : InventoryIterator.getIterable(tileInventory)) {
IInventory tileInventory = (IInventory) nearbyTile; ItemStack stack = slot.getStackInSlot();
ITransactor robotTransactor = Transactor.getTransactorFor(robot);
for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, dir.getOpposite())) { if (stack == null
ItemStack stack = slot.getStackInSlot(); || !filter.matches(stack)
|| !ActionRobotFilter.canInteractWithItem(station, filter,
ActionStationProvideItems.class)) {
continue;
}
if (stack != null) { ITransactor robotTransactor = Transactor.getTransactorFor(robot);
if (ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)
&& filter.matches(stack)) {
ITransactor t = Transactor.getTransactorFor(robot); if (quantity == ANY_QUANTITY) {
ItemStack added = robotTransactor.add(slot.getStackInSlot(),
ForgeDirection.UNKNOWN, doLoad);
if (doLoad) {
slot.decreaseStackInSlot(added.stackSize);
}
return added.stackSize > 0;
} else {
ItemStack toAdd = slot.getStackInSlot().copy();
if (quantity == ANY_QUANTITY) { if (toAdd.stackSize > quantity - loaded) {
ItemStack added = t.add(slot.getStackInSlot(), ForgeDirection.UNKNOWN, true); toAdd.stackSize = quantity - loaded;
slot.decreaseStackInSlot(added.stackSize); }
} else {
ItemStack toAdd = slot.getStackInSlot().copy();
if (toAdd.stackSize > quantity - loaded) { ItemStack added = robotTransactor.add(toAdd, ForgeDirection.UNKNOWN, doLoad);
toAdd.stackSize = quantity - loaded; if (doLoad) {
} slot.decreaseStackInSlot(added.stackSize);
}
loaded += added.stackSize;
ItemStack added = t.add(toAdd, ForgeDirection.UNKNOWN, true); if (quantity - loaded <= 0) {
slot.decreaseStackInSlot(added.stackSize); return true;
loaded += added.stackSize;
if (quantity - loaded <= 0) {
return;
}
}
}
}
}
} }
} }
} }
return false;
} }
@Override @Override

View file

@ -8,7 +8,6 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
@ -22,7 +21,6 @@ import buildcraft.robotics.statements.ActionStationProvideFluids;
public class AIRobotLoadFluids extends AIRobot { public class AIRobotLoadFluids extends AIRobot {
private int loaded = 0;
private int waitedCycles = 0; private int waitedCycles = 0;
private IFluidFilter filter; private IFluidFilter filter;
@ -34,6 +32,7 @@ public class AIRobotLoadFluids extends AIRobot {
this(iRobot); this(iRobot);
filter = iFilter; filter = iFilter;
setSuccess(false);
} }
@Override @Override
@ -41,51 +40,45 @@ public class AIRobotLoadFluids extends AIRobot {
waitedCycles++; waitedCycles++;
if (waitedCycles > 40) { if (waitedCycles > 40) {
int previousLoaded = loaded; if (load(robot, robot.getDockingStation(), filter, true) == 0) {
doLoad();
if (loaded == previousLoaded) {
terminate(); terminate();
} else { } else {
setSuccess(true);
waitedCycles = 0; waitedCycles = 0;
} }
} }
} }
private void doLoad() { public static int load(EntityRobotBase robot, DockingStation station, IFluidFilter filter,
if (robot.getDockingStation() != null) { boolean doLoad) {
DockingStation station = (DockingStation) robot.getDockingStation(); if (station == null) {
return 0;
if (!ActionRobotFilter.canInteractWithFluid(station, filter, ActionStationProvideFluids.class)) {
return;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IFluidHandler) {
IFluidHandler handler = (IFluidHandler) nearbyTile;
FluidStack drainable = handler.drain(station.side, FluidContainerRegistry.BUCKET_VOLUME, false);
if (drainable != null
&& filter.matches(drainable.getFluid())) {
drainable = drainable.copy();
int filled = robot.fill(ForgeDirection.UNKNOWN, drainable, true);
if (filled > 0) {
drainable.amount = filled;
handler.drain(station.side, drainable, true);
loaded += filled;
return;
}
}
}
}
} }
if (!ActionRobotFilter.canInteractWithFluid(station, filter,
ActionStationProvideFluids.class)) {
return 0;
}
IFluidHandler handler = station.getFluidInput();
if (handler == null) {
return 0;
}
FluidStack drainable = handler.drain(station.side, FluidContainerRegistry.BUCKET_VOLUME,
false);
if (drainable == null || !filter.matches(drainable.getFluid())) {
return 0;
}
drainable = drainable.copy();
int filled = robot.fill(ForgeDirection.UNKNOWN, drainable, doLoad);
if (filled > 0 && doLoad) {
drainable.amount = filled;
handler.drain(station.side, drainable, true);
}
return filled;
} }
@Override @Override
@ -93,8 +86,4 @@ public class AIRobotLoadFluids extends AIRobot {
return 8; return 8;
} }
@Override
public boolean success() {
return loaded > 0;
}
} }

View file

@ -28,7 +28,8 @@ public class AIRobotMain extends AIRobot {
@Override @Override
public void preempt(AIRobot ai) { public void preempt(AIRobot ai) {
if (robot.getEnergy() <= EntityRobotBase.SHUTDOWN_ENERGY) { if (robot.getEnergy() <= EntityRobotBase.SHUTDOWN_ENERGY
&& (robot.getDockingStation() == null || !robot.getDockingStation().providesPower())) {
if (!(ai instanceof AIRobotShutdown)) { if (!(ai instanceof AIRobotShutdown)) {
startDelegateAI(new AIRobotShutdown(robot)); startDelegateAI(new AIRobotShutdown(robot));
} }

View file

@ -11,7 +11,6 @@ package buildcraft.robotics.ai;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.transport.IPipeTile;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
public class AIRobotRecharge extends AIRobot { public class AIRobotRecharge extends AIRobot {
@ -33,7 +32,7 @@ public class AIRobotRecharge extends AIRobot {
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() { startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
return station.getPipe().getPipeType() == IPipeTile.PipeType.POWER; return station.providesPower();
} }
}, null)); }, null));
} }

View file

@ -10,8 +10,6 @@ package buildcraft.robotics.ai;
import java.util.Collection; import java.util.Collection;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
@ -20,14 +18,12 @@ import buildcraft.api.robots.StackRequest;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.statements.StatementParameterItemStack;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IPipe;
import buildcraft.core.lib.inventory.StackHelper; import buildcraft.core.lib.inventory.StackHelper;
import buildcraft.core.lib.inventory.filters.IStackFilter; import buildcraft.core.lib.inventory.filters.IStackFilter;
import buildcraft.robotics.IStationFilter; import buildcraft.robotics.IStationFilter;
import buildcraft.robotics.statements.ActionRobotFilter; import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationRequestItems; import buildcraft.robotics.statements.ActionStationRequestItems;
import buildcraft.robotics.statements.ActionStationRequestItemsMachine; import buildcraft.robotics.statements.ActionStationRequestItemsMachine;
import buildcraft.transport.gates.ActionIterator;
public class AIRobotSearchStackRequest extends AIRobot { public class AIRobotSearchStackRequest extends AIRobot {
@ -90,30 +86,25 @@ public class AIRobotSearchStackRequest extends AIRobot {
return null; return null;
} }
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { IRequestProvider provider = station.getRequestProvider();
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y() if (provider == null) {
+ dir.offsetY, station.z() return null;
+ dir.offsetZ); }
if (nearbyTile instanceof IRequestProvider) { for (int i = 0; i < provider.getNumberOfRequests(); ++i) {
IRequestProvider provider = (IRequestProvider) nearbyTile; StackRequest requestFound = provider.getAvailableRequest(i);
for (int i = 0; i < provider.getNumberOfRequests(); ++i) { if (requestFound != null
StackRequest requestFound = provider.getAvailableRequest(i); && !isBlacklisted(requestFound.stack)
&& filter.matches(requestFound.stack)) {
requestFound.station = station;
if (requestFound != null if (take) {
&& !isBlacklisted(requestFound.stack) if (provider.takeRequest(i, robot)) {
&& filter.matches(requestFound.stack)) { return requestFound;
requestFound.station = station;
if (take) {
if (provider.takeRequest(i, robot)) {
return requestFound;
}
} else {
return requestFound;
}
} }
} else {
return requestFound;
} }
} }
} }
@ -122,10 +113,7 @@ public class AIRobotSearchStackRequest extends AIRobot {
} }
private StackRequest getOrderFromRequestingAction(DockingStation station) { private StackRequest getOrderFromRequestingAction(DockingStation station) {
boolean actionFound = false; for (StatementSlot s : station.getActiveActions()) {
IPipe pipe = station.getPipe().getPipe();
for (StatementSlot s : new ActionIterator(pipe)) {
if (s.statement instanceof ActionStationRequestItems) { if (s.statement instanceof ActionStationRequestItems) {
for (IStatementParameter p : s.parameters) { for (IStatementParameter p : s.parameters) {
StatementParameterItemStack param = (StatementParameterItemStack) p; StatementParameterItemStack param = (StatementParameterItemStack) p;

View file

@ -35,8 +35,8 @@ public class AIRobotSearchStation extends AIRobot {
@Override @Override
public void start() { public void start() {
if (robot.getDockingStation() != null if (robot.getDockingStation() != null
&& filter.matches((DockingStation) robot.getDockingStation())) { && filter.matches(robot.getDockingStation())) {
targetStation = (DockingStation) robot.getDockingStation(); targetStation = robot.getDockingStation();
terminate(); terminate();
return; return;
} }
@ -44,14 +44,13 @@ public class AIRobotSearchStation extends AIRobot {
double potentialStationDistance = Float.MAX_VALUE; double potentialStationDistance = Float.MAX_VALUE;
DockingStation potentialStation = null; DockingStation potentialStation = null;
for (DockingStation d : robot.getRegistry().getStations()) { for (DockingStation station : robot.getRegistry().getStations()) {
DockingStation station = (DockingStation) d;
if (d.isTaken() && d.robotIdTaking() != robot.getRobotId()) { if (station.isTaken() && station.robotIdTaking() != robot.getRobotId()) {
continue; continue;
} }
if (zone != null && !zone.contains(d.x(), d.y(), d.z())) { if (zone != null && !zone.contains(station.x(), station.y(), station.z())) {
continue; continue;
} }
@ -60,9 +59,9 @@ public class AIRobotSearchStation extends AIRobot {
continue; continue;
} }
double dx = robot.posX - d.x(); double dx = robot.posX - station.x();
double dy = robot.posY - d.y(); double dy = robot.posY - station.y();
double dz = robot.posZ - d.z(); double dz = robot.posZ - station.z();
double distance = dx * dx + dy * dy + dz * dz; double distance = dx * dx + dy * dy + dz * dz;
if (potentialStation == null || distance < potentialStationDistance) { if (potentialStation == null || distance < potentialStationDistance) {

View file

@ -9,11 +9,9 @@
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.robotics.statements.ActionRobotWakeUp; import buildcraft.robotics.statements.ActionRobotWakeUp;
import buildcraft.transport.gates.ActionIterator;
public class AIRobotSleep extends AIRobot { public class AIRobotSleep extends AIRobot {
@ -26,7 +24,7 @@ public class AIRobotSleep extends AIRobot {
@Override @Override
public void preempt(AIRobot ai) { public void preempt(AIRobot ai) {
for (StatementSlot s : new ActionIterator(((DockingStation) robot.getLinkedStation()).getPipe().getPipe())) { for (StatementSlot s :robot.getLinkedStation().getActiveActions()) {
if (s.statement instanceof ActionRobotWakeUp) { if (s.statement instanceof ActionRobotWakeUp) {
terminate(); terminate();
} }

View file

@ -8,17 +8,17 @@
*/ */
package buildcraft.robotics.ai; package buildcraft.robotics.ai;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.transport.IInjectable;
import buildcraft.api.transport.IPipe;
import buildcraft.core.lib.inventory.InventoryIterator; import buildcraft.core.lib.inventory.InventoryIterator;
import buildcraft.robotics.EntityRobot; import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationInputItems; import buildcraft.robotics.statements.ActionStationInputItems;
import buildcraft.transport.gates.ActionIterator;
public class AIRobotUnload extends AIRobot { public class AIRobotUnload extends AIRobot {
@ -33,36 +33,50 @@ public class AIRobotUnload extends AIRobot {
waitedCycles++; waitedCycles++;
if (waitedCycles > 40) { if (waitedCycles > 40) {
if (!doUnload()) { if (unload(robot, robot.getDockingStation(), true)) {
terminate();
} else {
waitedCycles = 0; waitedCycles = 0;
} else {
setSuccess(!robot.containsItems());
terminate();
} }
} }
} }
private boolean doUnload() { public static boolean unload(EntityRobotBase robot, DockingStation station, boolean doUnload) {
DockingStation station = (DockingStation) robot.getDockingStation();
if (station == null) { if (station == null) {
setSuccess(false);
return false; return false;
} }
IPipe pipe = station.getPipe().getPipe(); IInjectable output = station.getItemOutput();
if (output == null) {
return false;
}
for (IInvSlot robotSlot : InventoryIterator.getIterable(robot, ForgeDirection.UNKNOWN)) { for (IInvSlot robotSlot : InventoryIterator.getIterable(robot, ForgeDirection.UNKNOWN)) {
if (robotSlot.getStackInSlot() == null) { if (robotSlot.getStackInSlot() == null) {
continue; continue;
} }
for (StatementSlot s : new ActionIterator(pipe)) { if (!ActionRobotFilter
if (s.statement instanceof ActionStationInputItems) { .canInteractWithItem(station, new ArrayStackFilter(robotSlot.getStackInSlot()),
if (((ActionStationInputItems) s.statement) ActionStationInputItems.class)) {
.insert(station, (EntityRobot) robot, s, robotSlot, true)) { return false;
return true; }
ForgeDirection injectSide = station.side().getOpposite();
ItemStack stack = robotSlot.getStackInSlot();
int used = output.injectItem(stack, doUnload, injectSide, null);
if (used > 0) {
if (doUnload) {
stack.stackSize -= used;
if (stack.stackSize > 0) {
robotSlot.setStackInSlot(stack);
} else {
robotSlot.setStackInSlot(null);
} }
} }
return true;
} }
} }

View file

@ -11,71 +11,69 @@ package buildcraft.robotics.ai;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.lib.inventory.filters.SimpleFluidFilter; import buildcraft.core.lib.inventory.filters.SimpleFluidFilter;
import buildcraft.robotics.statements.ActionRobotFilter; import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.robotics.statements.ActionStationAcceptFluids; import buildcraft.robotics.statements.ActionStationAcceptFluids;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportFluids;
public class AIRobotUnloadFluids extends AIRobot { public class AIRobotUnloadFluids extends AIRobot {
private int unloaded = 0; private int waitedCycles = 0;
public AIRobotUnloadFluids(EntityRobotBase iRobot) { public AIRobotUnloadFluids(EntityRobotBase iRobot) {
super(iRobot); super(iRobot);
setSuccess(false);
} }
@Override @Override
public void update() { public void update() {
int previousUnloaded = unloaded; waitedCycles++;
doLoad();
if (unloaded == previousUnloaded) { if (waitedCycles > 40) {
terminate(); if (unload(robot, robot.getDockingStation(), true) == 0) {
terminate();
} else {
setSuccess(true);
}
} }
} }
private void doLoad() { public static int unload(EntityRobotBase robot, DockingStation station, boolean doUnload) {
if (robot.getDockingStation() != null) { if (station == null) {
DockingStation station = (DockingStation) robot.getDockingStation(); return 0;
if (!ActionRobotFilter.canInteractWithFluid(station,
new SimpleFluidFilter(robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid),
ActionStationAcceptFluids.class)) {
return;
}
if (((Pipe) station.getPipe().getPipe()).transport instanceof PipeTransportFluids) {
PipeTransportFluids transport = (PipeTransportFluids) ((Pipe) station.getPipe().getPipe()).transport;
FluidStack drainable = robot.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.BUCKET_VOLUME,
false);
if (drainable != null) {
drainable = drainable.copy();
int filled = transport.fill(station.side, drainable, true);
if (filled > 0) {
drainable.amount = filled;
robot.drain(ForgeDirection.UNKNOWN, drainable, true);
unloaded += filled;
return;
}
}
}
} }
if (!ActionRobotFilter.canInteractWithFluid(station,
new SimpleFluidFilter(robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid),
ActionStationAcceptFluids.class)) {
return 0;
}
IFluidHandler fluidHandler = station.getFluidOutput();
if (fluidHandler == null) {
return 0;
}
FluidStack drainable = robot.drain(ForgeDirection.UNKNOWN,
FluidContainerRegistry.BUCKET_VOLUME, false);
if (drainable == null) {
return 0;
}
drainable = drainable.copy();
int filled = fluidHandler.fill(station.side, drainable, doUnload);
if (filled > 0 && doUnload) {
drainable.amount = filled;
robot.drain(ForgeDirection.UNKNOWN, drainable, true);
}
return filled;
} }
@Override @Override
public int getEnergyCost() { public int getEnergyCost() {
return 10; return 10;
} }
@Override
public boolean success() {
return unloaded > 0;
}
} }

View file

@ -17,7 +17,6 @@ import net.minecraft.world.World;
import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BlockIndex;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.ResourceIdBlock; import buildcraft.api.robots.ResourceIdBlock;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
@ -30,7 +29,6 @@ import buildcraft.robotics.ai.AIRobotFetchAndEquipItemStack;
import buildcraft.robotics.ai.AIRobotGotoSleep; import buildcraft.robotics.ai.AIRobotGotoSleep;
import buildcraft.robotics.ai.AIRobotSearchAndGotoBlock; import buildcraft.robotics.ai.AIRobotSearchAndGotoBlock;
import buildcraft.robotics.statements.ActionRobotFilter; import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.transport.gates.ActionIterator;
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
@ -112,9 +110,7 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
blockFilter.clear(); blockFilter.clear();
metaFilter.clear(); metaFilter.clear();
DockingStation station = (DockingStation) robot.getLinkedStation(); for (StatementSlot slot : robot.getLinkedStation().getActiveActions()) {
for (StatementSlot slot : new ActionIterator(station.getPipe().getPipe())) {
if (slot.statement instanceof ActionRobotFilter) { if (slot.statement instanceof ActionRobotFilter) {
for (IStatementParameter p : slot.parameters) { for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) { if (p != null && p instanceof StatementParameterItemStack) {

View file

@ -8,13 +8,10 @@
*/ */
package buildcraft.robotics.boards; package buildcraft.robotics.boards;
import java.util.ArrayList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobot;
@ -23,24 +20,21 @@ import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IWorldProperty; import buildcraft.api.core.IWorldProperty;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.ResourceIdBlock; import buildcraft.api.robots.ResourceIdBlock;
import buildcraft.api.statements.IStatementParameter; import buildcraft.core.lib.inventory.filters.IFluidFilter;
import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.core.lib.inventory.filters.PassThroughFluidFilter;
import buildcraft.api.statements.StatementSlot;
import buildcraft.core.lib.utils.IBlockFilter; import buildcraft.core.lib.utils.IBlockFilter;
import buildcraft.robotics.ai.AIRobotGotoSleep; import buildcraft.robotics.ai.AIRobotGotoSleep;
import buildcraft.robotics.ai.AIRobotGotoStationAndUnloadFluids; import buildcraft.robotics.ai.AIRobotGotoStationAndUnloadFluids;
import buildcraft.robotics.ai.AIRobotPumpBlock; import buildcraft.robotics.ai.AIRobotPumpBlock;
import buildcraft.robotics.ai.AIRobotSearchAndGotoBlock; import buildcraft.robotics.ai.AIRobotSearchAndGotoBlock;
import buildcraft.robotics.statements.ActionRobotFilter; import buildcraft.robotics.statements.ActionRobotFilter;
import buildcraft.transport.gates.ActionIterator;
public class BoardRobotPump extends RedstoneBoardRobot { public class BoardRobotPump extends RedstoneBoardRobot {
private BlockIndex blockFound; private BlockIndex blockFound;
private ArrayList<Fluid> fluidFilter = new ArrayList<Fluid>(); private IFluidFilter fluidFilter = null;
public BoardRobotPump(EntityRobotBase iRobot) { public BoardRobotPump(EntityRobotBase iRobot) {
super(iRobot); super(iRobot);
@ -102,32 +96,14 @@ public class BoardRobotPump extends RedstoneBoardRobot {
} }
public void updateFilter() { public void updateFilter() {
fluidFilter.clear(); fluidFilter = ActionRobotFilter.getGateFluidFilter(robot.getLinkedStation());
if (fluidFilter instanceof PassThroughFluidFilter) {
DockingStation station = (DockingStation) robot.getLinkedStation(); fluidFilter = null;
for (StatementSlot slot : new ActionIterator(station.getPipe().getPipe())) {
if (slot.statement instanceof ActionRobotFilter) {
for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) {
StatementParameterItemStack param = (StatementParameterItemStack) p;
ItemStack stack = param.getItemStack();
if (stack != null) {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
if (fluid != null) {
fluidFilter.add(fluid.getFluid());
}
}
}
}
}
} }
} }
private boolean matchesGateFilter(World world, int x, int y, int z) { private boolean matchesGateFilter(World world, int x, int y, int z) {
if (fluidFilter.size() == 0) { if (fluidFilter == null) {
return true; return true;
} }
@ -138,13 +114,7 @@ public class BoardRobotPump extends RedstoneBoardRobot {
Fluid fluid = FluidRegistry.lookupFluidForBlock(block); Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
for (Fluid f : fluidFilter) { return fluidFilter.matches(fluid);
if (f.getID() == fluid.getID()) {
return true;
}
}
return false;
} }
} }

View file

@ -20,7 +20,6 @@ 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.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IPipe;
import buildcraft.core.lib.inventory.filters.ArrayFluidFilter; import buildcraft.core.lib.inventory.filters.ArrayFluidFilter;
import buildcraft.core.lib.inventory.filters.ArrayStackOrListFilter; import buildcraft.core.lib.inventory.filters.ArrayStackOrListFilter;
import buildcraft.core.lib.inventory.filters.IFluidFilter; import buildcraft.core.lib.inventory.filters.IFluidFilter;
@ -30,7 +29,6 @@ import buildcraft.core.lib.inventory.filters.PassThroughStackFilter;
import buildcraft.core.lib.inventory.filters.StatementParameterStackFilter; import buildcraft.core.lib.inventory.filters.StatementParameterStackFilter;
import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.core.statements.BCStatement; import buildcraft.core.statements.BCStatement;
import buildcraft.transport.gates.ActionIterator;
public class ActionRobotFilter extends BCStatement implements IActionInternal { public class ActionRobotFilter extends BCStatement implements IActionInternal {
@ -66,7 +64,7 @@ public class ActionRobotFilter extends BCStatement implements IActionInternal {
public static Collection<ItemStack> getGateFilterStacks(DockingStation station) { public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
ArrayList<ItemStack> result = new ArrayList<ItemStack>(); ArrayList<ItemStack> result = new ArrayList<ItemStack>();
for (StatementSlot slot : new ActionIterator(((DockingStation) station).getPipe().getPipe())) { for (StatementSlot slot : station.getActiveActions()) {
if (slot.statement instanceof ActionRobotFilter) { if (slot.statement instanceof ActionRobotFilter) {
for (IStatementParameter p : slot.parameters) { for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) { if (p != null && p instanceof StatementParameterItemStack) {
@ -107,9 +105,7 @@ public class ActionRobotFilter extends BCStatement implements IActionInternal {
public static boolean canInteractWithItem(DockingStation station, IStackFilter filter, Class<?> actionClass) { public static boolean canInteractWithItem(DockingStation station, IStackFilter filter, Class<?> actionClass) {
boolean actionFound = false; boolean actionFound = false;
IPipe pipe = station.getPipe().getPipe(); for (StatementSlot s : station.getActiveActions()) {
for (StatementSlot s : new ActionIterator(pipe)) {
if (actionClass.isAssignableFrom(s.statement.getClass())) { if (actionClass.isAssignableFrom(s.statement.getClass())) {
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters); StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);
@ -125,9 +121,8 @@ public class ActionRobotFilter extends BCStatement implements IActionInternal {
public static boolean canInteractWithFluid(DockingStation station, IFluidFilter filter, Class<?> actionClass) { public static boolean canInteractWithFluid(DockingStation station, IFluidFilter filter, Class<?> actionClass) {
boolean actionFound = false; boolean actionFound = false;
IPipe pipe = station.getPipe().getPipe();
for (StatementSlot s : new ActionIterator(pipe)) { for (StatementSlot s : station.getActiveActions()) {
if (actionClass.isAssignableFrom(s.statement.getClass())) { if (actionClass.isAssignableFrom(s.statement.getClass())) {
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters); StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);

View file

@ -23,7 +23,6 @@ import buildcraft.core.lib.inventory.filters.IStackFilter;
import buildcraft.core.lib.inventory.filters.PassThroughStackFilter; import buildcraft.core.lib.inventory.filters.PassThroughStackFilter;
import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.core.statements.BCStatement; import buildcraft.core.statements.BCStatement;
import buildcraft.transport.gates.ActionIterator;
public class ActionRobotFilterTool extends BCStatement implements IActionInternal { public class ActionRobotFilterTool extends BCStatement implements IActionInternal {
@ -59,7 +58,7 @@ public class ActionRobotFilterTool extends BCStatement implements IActionInterna
public static Collection<ItemStack> getGateFilterStacks(DockingStation station) { public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
ArrayList<ItemStack> result = new ArrayList<ItemStack>(); ArrayList<ItemStack> result = new ArrayList<ItemStack>();
for (StatementSlot slot : new ActionIterator(((DockingStation) station).getPipe().getPipe())) { for (StatementSlot slot : station.getActiveActions()) {
if (slot.statement instanceof ActionRobotFilterTool) { if (slot.statement instanceof ActionRobotFilterTool) {
for (IStatementParameter p : slot.parameters) { for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) { if (p != null && p instanceof StatementParameterItemStack) {

View file

@ -8,8 +8,6 @@
*/ */
package buildcraft.robotics.statements; package buildcraft.robotics.statements;
import javax.print.Doc;
import java.util.List; import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -18,16 +16,15 @@ import buildcraft.api.core.BlockIndex;
import buildcraft.api.items.IMapLocation; import buildcraft.api.items.IMapLocation;
import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.IRobotRegistry;
import buildcraft.api.robots.RobotManager; import buildcraft.api.robots.RobotManager;
import buildcraft.api.statements.IActionInternal; 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.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.core.statements.BCStatement; import buildcraft.core.statements.BCStatement;
import buildcraft.robotics.EntityRobot; import buildcraft.robotics.EntityRobot;
import buildcraft.robotics.RobotRegistry;
import buildcraft.robotics.RobotUtils; import buildcraft.robotics.RobotUtils;
import buildcraft.robotics.ai.AIRobotGoAndLinkToDock; import buildcraft.robotics.ai.AIRobotGoAndLinkToDock;
@ -49,14 +46,10 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern
@Override @Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) { public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
if (!(container.getTile() instanceof IPipeTile)) { IRobotRegistry registry = RobotManager.registryProvider.getRegistry(container.getTile()
return; .getWorldObj());
}
IPipeTile tile = (IPipeTile) container.getTile(); List<DockingStation> stations = RobotUtils.getStations(container.getTile());
RobotRegistry registry = (RobotRegistry) RobotManager.registryProvider.getRegistry(tile.getWorld());
List<DockingStation> stations = RobotUtils.getStations(tile);
for (DockingStation station : stations) { for (DockingStation station : stations) {
if (station.robotTaking() != null) { if (station.robotTaking() != null) {
@ -70,24 +63,7 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern
DockingStation newStation = station; DockingStation newStation = station;
if (parameters[0] != null) { if (parameters[0] != null) {
StatementParameterItemStack stackParam = (StatementParameterItemStack) parameters[0]; newStation = getStation((StatementParameterItemStack) parameters[0], registry);
ItemStack item = stackParam.getItemStack();
if (item != null && item.getItem() instanceof IMapLocation) {
IMapLocation map = (IMapLocation) item.getItem();
BlockIndex index = map.getPoint(item);
if (index != null) {
ForgeDirection side = map.getPointSide(item);
DockingStation paramStation = (DockingStation)
registry.getStation(index.x,
index.y, index.z, side);
if (paramStation != null) {
newStation = paramStation;
}
}
}
} }
robot.overrideAI(new AIRobotGoAndLinkToDock(robot, newStation)); robot.overrideAI(new AIRobotGoAndLinkToDock(robot, newStation));
@ -95,6 +71,26 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern
} }
} }
private DockingStation getStation(StatementParameterItemStack stackParam,
IRobotRegistry registry) {
ItemStack item = stackParam.getItemStack();
if (item != null && item.getItem() instanceof IMapLocation) {
IMapLocation map = (IMapLocation) item.getItem();
BlockIndex index = map.getPoint(item);
if (index != null) {
ForgeDirection side = map.getPointSide(item);
DockingStation paramStation = registry.getStation(index.x, index.y, index.z, side);
if (paramStation != null) {
return paramStation;
}
}
}
return null;
}
@Override @Override
public int maxParameters() { public int maxParameters() {
return 1; return 1;

View file

@ -9,17 +9,17 @@
package buildcraft.robotics.statements; package buildcraft.robotics.statements;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementManager; import buildcraft.api.statements.StatementManager;
import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.statements.StatementParameterItemStack;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IInjectable;
import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.robotics.EntityRobot; import buildcraft.robotics.EntityRobot;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
public class ActionStationAcceptItems extends ActionStationInputItems { public class ActionStationAcceptItems extends ActionStationInputItems {
@ -55,21 +55,31 @@ public class ActionStationAcceptItems extends ActionStationInputItems {
return false; return false;
} }
IInjectable injectable = station.getItemOutput();
if (injectable == null) {
return false;
}
ForgeDirection injectSide = station.side().getOpposite();
if (!injectable.canInjectItems(injectSide)) {
return false;
}
if (!doInsert) { if (!doInsert) {
return true; return true;
} }
if (((Pipe) station.getPipe().getPipe()).transport instanceof PipeTransportItems) { ItemStack stack = invSlot.getStackInSlot();
float cx = station.x() + 0.5F + 0.2F * station.side().offsetX; int used = injectable.injectItem(stack, doInsert, injectSide, null);
float cy = station.y() + 0.5F + 0.2F * station.side().offsetY; if (used > 0) {
float cz = station.z() + 0.5F + 0.2F * station.side().offsetZ; stack.stackSize -= used;
if (stack.stackSize > 0) {
TravelingItem item = TravelingItem.make(cx, cy, cz, invSlot.getStackInSlot()); invSlot.setStackInSlot(stack);
} else {
((PipeTransportItems) ((Pipe) station.getPipe().getPipe()).transport).injectItem(item, station.side().getOpposite()); invSlot.setStackInSlot(null);
}
invSlot.setStackInSlot(null);
return true; return true;
} }

View file

@ -20,7 +20,6 @@ import buildcraft.api.statements.StatementSlot;
import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.core.statements.BCStatement; import buildcraft.core.statements.BCStatement;
import buildcraft.robotics.ItemRobot; import buildcraft.robotics.ItemRobot;
import buildcraft.transport.gates.ActionIterator;
public class ActionStationForbidRobot extends BCStatement implements IActionInternal { public class ActionStationForbidRobot extends BCStatement implements IActionInternal {
private final boolean invert; private final boolean invert;
@ -56,7 +55,7 @@ public class ActionStationForbidRobot extends BCStatement implements IActionInte
} }
public static boolean isForbidden(DockingStation station, EntityRobotBase robot) { public static boolean isForbidden(DockingStation station, EntityRobotBase robot) {
for (StatementSlot s : new ActionIterator(station.getPipe().getPipe())) { for (StatementSlot s : station.getActiveActions()) {
if (s.statement instanceof ActionStationForbidRobot) { if (s.statement instanceof ActionStationForbidRobot) {
if (((ActionStationForbidRobot) s.statement).invert ^ ActionStationForbidRobot.isForbidden(s, robot)) { if (((ActionStationForbidRobot) s.statement).invert ^ ActionStationForbidRobot.isForbidden(s, robot)) {
return true; return true;
@ -70,7 +69,6 @@ public class ActionStationForbidRobot extends BCStatement implements IActionInte
public static boolean isForbidden(StatementSlot slot, EntityRobotBase robot) { public static boolean isForbidden(StatementSlot slot, EntityRobotBase robot) {
for (IStatementParameter p : slot.parameters) { for (IStatementParameter p : slot.parameters) {
if (p != null) { if (p != null) {
StatementParameterItemStack actionStack = (StatementParameterItemStack) p;
ItemStack stack = p.getItemStack(); ItemStack stack = p.getItemStack();
if (stack != null && stack.getItem() instanceof ItemRobot) { if (stack != null && stack.getItem() instanceof ItemRobot) {

View file

@ -9,16 +9,16 @@
package buildcraft.robotics.statements; package buildcraft.robotics.statements;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.statements.StatementParameterItemStack;
import buildcraft.api.statements.StatementSlot; import buildcraft.api.statements.StatementSlot;
import buildcraft.api.transport.IInjectable;
import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.lib.utils.StringUtils;
import buildcraft.robotics.EntityRobot; import buildcraft.robotics.EntityRobot;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TravelingItem;
public class ActionStationRequestItems extends ActionStationInputItems { public class ActionStationRequestItems extends ActionStationInputItems {
@ -58,17 +58,31 @@ public class ActionStationRequestItems extends ActionStationInputItems {
return false; return false;
} }
if (((Pipe) station.getPipe().getPipe()).transport instanceof PipeTransportItems) { IInjectable injectable = station.getItemOutput();
float cx = station.x() + 0.5F + 0.2F * station.side().offsetX;
float cy = station.y() + 0.5F + 0.2F * station.side().offsetY;
float cz = station.z() + 0.5F + 0.2F * station.side().offsetZ;
TravelingItem item = TravelingItem.make(cx, cy, cz, invSlot.getStackInSlot()); if (injectable == null) {
return false;
}
((PipeTransportItems) ((Pipe) station.getPipe().getPipe()).transport).injectItem(item, station.side().getOpposite()); ForgeDirection injectSide = station.side().getOpposite();
invSlot.setStackInSlot(null); if (!injectable.canInjectItems(injectSide)) {
return false;
}
if (!doInsert) {
return true;
}
ItemStack stack = invSlot.getStackInSlot();
int used = injectable.injectItem(stack, doInsert, injectSide, null);
if (used > 0) {
stack.stackSize -= used;
if (stack.stackSize > 0) {
invSlot.setStackInSlot(stack);
} else {
invSlot.setStackInSlot(null);
}
return true; return true;
} }

View file

@ -13,23 +13,19 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockWorkbench; import net.minecraft.block.BlockWorkbench;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftRobotics; import buildcraft.BuildCraftRobotics;
import buildcraft.api.robots.DockingStation; import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.statements.IActionExternal; 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.IPipeTile; import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.robotics.RobotUtils; import buildcraft.robotics.RobotUtils;
import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable;
import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
public class RobotsActionProvider implements IActionProvider { public class RobotsActionProvider implements IActionProvider {
@ -38,12 +34,14 @@ public class RobotsActionProvider implements IActionProvider {
public Collection<IActionInternal> getInternalActions(IStatementContainer container) { public Collection<IActionInternal> getInternalActions(IStatementContainer container) {
LinkedList<IActionInternal> result = new LinkedList<IActionInternal>(); LinkedList<IActionInternal> result = new LinkedList<IActionInternal>();
TileEntity tile = container.getTile(); TileEntity tile = container.getTile();
if (!(tile instanceof IPipeTile)) { if (!(tile instanceof IPipeTile)) {
return result; return result;
} }
List<DockingStation> stations = RobotUtils.getStations(tile); IPipeTile pipeTile = (IPipeTile) tile;
List<DockingStation> stations = RobotUtils.getStations(pipeTile);
if (stations.size() == 0) { if (stations.size() == 0) {
return result; return result;
@ -58,32 +56,32 @@ public class RobotsActionProvider implements IActionProvider {
result.add(BuildCraftRobotics.actionStationForbidRobot); result.add(BuildCraftRobotics.actionStationForbidRobot);
result.add(BuildCraftRobotics.actionStationForceRobot); result.add(BuildCraftRobotics.actionStationForceRobot);
if (((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) { if (pipeTile.getPipeType() == PipeType.ITEM) {
result.add(BuildCraftRobotics.actionStationRequestItems); result.add(BuildCraftRobotics.actionStationRequestItems);
result.add(BuildCraftRobotics.actionStationAcceptItems); result.add(BuildCraftRobotics.actionStationAcceptItems);
} }
if (((TileGenericPipe) tile).pipe.transport instanceof PipeTransportFluids) { if (pipeTile.getPipeType() == PipeType.FLUID) {
result.add(BuildCraftRobotics.actionStationAcceptFluids); result.add(BuildCraftRobotics.actionStationAcceptFluids);
} }
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for (DockingStation station : stations) {
TileEntity sideTile = ((TileGenericPipe) tile).getTile(dir); TileEntity sideTile = ((TileGenericPipe) tile).getTile(station.side);
Block sideBlock = ((TileGenericPipe) tile).getBlock(dir); Block sideBlock = ((TileGenericPipe) tile).getBlock(station.side);
if (sideTile instanceof IPipeTile) { if (sideTile instanceof IPipeTile) {
continue; continue;
} }
if (sideTile instanceof IInventory) { if (station.getItemInput() != null) {
result.add(BuildCraftRobotics.actionStationProvideItems); result.add(BuildCraftRobotics.actionStationProvideItems);
} }
if (sideTile instanceof IFluidHandler) { if (station.getFluidInput() != null) {
result.add(BuildCraftRobotics.actionStationProvideFluids); result.add(BuildCraftRobotics.actionStationProvideFluids);
} }
if (sideTile instanceof IRequestProvider) { if (station.getRequestProvider() != null) {
result.add(BuildCraftRobotics.actionStationMachineRequestItems); result.add(BuildCraftRobotics.actionStationMachineRequestItems);
} }