Implemented filters for crafting robots.

Crafting robots now only answers to stack requests.
This commit is contained in:
SpaceToad 2014-08-17 11:37:30 +02:00
parent a38bedf5fe
commit 73198c4a7b
18 changed files with 101 additions and 117 deletions

View file

@ -66,7 +66,7 @@ gate.action.station.provide_items=Provide Items
gate.action.station.accept_items=Accept Items
gate.action.station.request_items=Request Items
gate.action.station.drop_items_in_pipe=Drop Items In Pipe
gate.action.station.craft=Craft
gate.action.station.allow_craft=Allow Craft
gate.action.station.provide_machine_request=Provide Computed Items
gate.action.station.accept_fluids=Accept Fluids
gate.action.station.povide_fluids=Provide Fluids

Binary file not shown.

Before

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

View file

@ -85,7 +85,6 @@ import buildcraft.silicon.network.PacketHandlerSilicon;
import buildcraft.silicon.recipes.AdvancedFacadeRecipe;
import buildcraft.silicon.recipes.GateExpansionRecipe;
import buildcraft.silicon.recipes.GateLogicSwapRecipe;
import buildcraft.silicon.statements.ActionRobotCraft;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionRobotGotoStation;
import buildcraft.silicon.statements.ActionRobotWakeUp;
@ -93,6 +92,7 @@ import buildcraft.silicon.statements.ActionRobotWorkInArea;
import buildcraft.silicon.statements.ActionStationAcceptFluids;
import buildcraft.silicon.statements.ActionStationAcceptItemsInv;
import buildcraft.silicon.statements.ActionStationAcceptItemsPipe;
import buildcraft.silicon.statements.ActionStationAllowCraft;
import buildcraft.silicon.statements.ActionStationForbidRobot;
import buildcraft.silicon.statements.ActionStationProvideFluids;
import buildcraft.silicon.statements.ActionStationProvideItems;
@ -131,7 +131,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
public static IAction actionRobotWakeUp = new ActionRobotWakeUp();
public static IAction actionRobotWorkInArea = new ActionRobotWorkInArea();
public static IAction actionRobotFilter = new ActionRobotFilter();
public static IAction actionRobotCraft = new ActionRobotCraft();
public static IAction actionRobotAllowCraft = new ActionStationAllowCraft();
public static IAction actionStationRequestItems = new ActionStationRequestItems();
public static IAction actionStationAcceptItems = new ActionStationAcceptItemsInv();
public static IAction actionStationProvideItems = new ActionStationProvideItems();

View file

@ -44,10 +44,10 @@ public final class TileBuffer {
return;
}
block = world.getBlock(this.x, this.y, this.z);
block = world.getBlock(x, y, z);
if (block != null && block.hasTileEntity(world.getBlockMetadata(this.x, this.y, this.z))) {
tile = world.getTileEntity(this.x, this.y, this.z);
if (block != null && block.hasTileEntity(world.getBlockMetadata(x, y, z))) {
tile = world.getTileEntity(x, y, z);
}
}
@ -59,20 +59,12 @@ public final class TileBuffer {
public Block getBlock() {
if (tile != null && !tile.isInvalid()) {
return block;
}
if (tracker.markTimeIfDelay(world)) {
if ((tile != null && tile.isInvalid()) || (tile == null && tracker.markTimeIfDelay(world))) {
refresh();
}
if (tile != null && !tile.isInvalid()) {
return block;
}
}
return null;
}
public TileEntity getTile() {
if (tile != null && !tile.isInvalid()) {

View file

@ -31,6 +31,8 @@ import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.silicon.BlockLaserTable;
import buildcraft.silicon.TileAssemblyTable;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationAllowCraft;
public class AIRobotCraftAssemblyTable extends AIRobotCraftGeneric {
@ -207,6 +209,11 @@ public class AIRobotCraftAssemblyTable extends AIRobotCraftGeneric {
@Override
public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(expectedResult.crafted),
ActionStationAllowCraft.class)) {
return false;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (getUsableAssemblyTable(new BlockIndex(station.x(), station.y(), station.z())) != null) {
return true;

View file

@ -25,6 +25,8 @@ import buildcraft.core.inventory.StackHelper;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationAllowCraft;
public class AIRobotCraftFurnace extends AIRobotCraftGeneric {
@ -38,15 +40,17 @@ public class AIRobotCraftFurnace extends AIRobotCraftGeneric {
private boolean craftStarted = false;
private int waitedTime = 0;
private ItemStack expectedOutput;
public AIRobotCraftFurnace(EntityRobotBase iRobot) {
super(iRobot);
}
public AIRobotCraftFurnace(EntityRobotBase iRobot, ItemStack iInput) {
public AIRobotCraftFurnace(EntityRobotBase iRobot, ItemStack iInput, ItemStack iOutput) {
super(iRobot);
input = iInput;
expectedOutput = iOutput;
}
@Override
@ -158,6 +162,11 @@ public class AIRobotCraftFurnace extends AIRobotCraftGeneric {
@Override
public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(expectedOutput),
ActionStationAllowCraft.class)) {
return false;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (getUsableFurnace(new BlockIndex(station.x(), station.y(), station.z())) != null) {
return true;

View file

@ -34,6 +34,8 @@ import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationAllowCraft;
public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
@ -217,6 +219,11 @@ public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
@Override
public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(recipe.getRecipeOutput()),
ActionStationAllowCraft.class)) {
return false;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
Block nearbyBlock = robot.worldObj.getBlock(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()

View file

@ -19,11 +19,8 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.inventory.filters.StatementParameterStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationProvideItems;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.ActionSlot;
public class AIRobotGotoStationToLoad extends AIRobot {
@ -65,22 +62,7 @@ public class AIRobotGotoStationToLoad extends AIRobot {
@Override
public boolean matches(DockingStation station) {
boolean actionFound = false;
Pipe pipe = station.getPipe().pipe;
for (ActionSlot s : new ActionIterator(pipe)) {
if (s.action instanceof ActionStationProvideItems) {
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);
if (!param.hasFilter() || param.matches(filter)) {
actionFound = true;
break;
}
}
}
if (!actionFound) {
if (!ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)) {
return false;
}

View file

@ -21,10 +21,8 @@ import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.inventory.filters.StatementParameterStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationProvideItems;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.ActionSlot;
public class AIRobotLoad extends AIRobot {
@ -76,21 +74,9 @@ public class AIRobotLoad extends AIRobot {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
boolean allowed = false;
if (ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)
&& filter.matches(stack)) {
for (ActionSlot s : new ActionIterator(station.getPipe().pipe)) {
if (s.action instanceof ActionStationProvideItems) {
StatementParameterStackFilter param = new StatementParameterStackFilter(
s.parameters);
if (!param.hasFilter() || param.matches(stack)) {
allowed = true;
break;
}
}
}
if (allowed && filter.matches(stack)) {
ITransactor t = Transactor.getTransactorFor(robot);
if (quantity == -1) {

View file

@ -22,6 +22,8 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.robots.StackRequest;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationRequestItems;
import buildcraft.silicon.statements.ActionStationRequestItemsMachine;
import buildcraft.transport.Pipe;
@ -34,14 +36,17 @@ public class AIRobotSearchStackRequest extends AIRobot {
private Collection<ItemStack> blackList;
private IStackFilter filter;
public AIRobotSearchStackRequest(EntityRobotBase iRobot) {
super(iRobot);
}
public AIRobotSearchStackRequest(EntityRobotBase iRobot, Collection<ItemStack> iBlackList) {
public AIRobotSearchStackRequest(EntityRobotBase iRobot, IStackFilter iFilter, Collection<ItemStack> iBlackList) {
super(iRobot);
blackList = iBlackList;
filter = iFilter;
}
@Override
@ -82,17 +87,7 @@ public class AIRobotSearchStackRequest extends AIRobot {
}
private StackRequest getOrderFromRequestingStation(DockingStation station, boolean take) {
boolean actionFound = false;
Pipe pipe = station.getPipe().pipe;
for (ActionSlot s : new ActionIterator(pipe)) {
if (s.action instanceof ActionStationRequestItemsMachine) {
actionFound = true;
}
}
if (!actionFound) {
if (!ActionRobotFilter.canInteractWithItem(station, filter, ActionStationRequestItemsMachine.class)) {
return null;
}
@ -107,7 +102,9 @@ public class AIRobotSearchStackRequest extends AIRobot {
for (int i = 0; i < provider.getNumberOfRequests(); ++i) {
StackRequest requestFound = provider.getAvailableRequest(i);
if (requestFound != null && !isBlacklisted(requestFound.stack)) {
if (requestFound != null
&& !isBlacklisted(requestFound.stack)
&& filter.matches(requestFound.stack)) {
requestFound.station = station;
if (take) {

View file

@ -288,7 +288,8 @@ public class EntityRobot extends EntityRobotBase implements
linkedDockingStationIndex = null;
if (linkedDockingStation.robotTaking() != this) {
if (linkedDockingStation == null
|| linkedDockingStation.robotTaking() != this) {
// Error at load time, the expected linked stations is not
// properly set, kill this robot.

View file

@ -24,8 +24,6 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.api.robots.AIRobot;
@ -44,10 +42,7 @@ import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotGotoStationToUnload;
import buildcraft.core.robots.AIRobotSearchStackRequest;
import buildcraft.core.robots.AIRobotUnload;
import buildcraft.core.robots.DockingStation;
import buildcraft.silicon.statements.ActionRobotCraft;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.ActionSlot;
import buildcraft.silicon.statements.ActionRobotFilter;
public class BoardRobotCrafter extends RedstoneBoardRobot {
@ -75,14 +70,15 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
return;
}
if (currentRequest == null) {
order = getOrderFromHomeStation();
} else {
if (currentRequest != null) {
order = currentRequest.stack;
} else {
order = null;
}
if (order == null) {
startDelegateAI(new AIRobotSearchStackRequest(robot, craftingBlacklist));
startDelegateAI(new AIRobotSearchStackRequest(robot, ActionRobotFilter.getGateFilter(robot
.getLinkedStation()), craftingBlacklist));
return;
}
@ -96,7 +92,7 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
ItemStack furnaceInput = lookForFurnaceRecipe(order);
if (furnaceInput != null) {
startDelegateAI(new AIRobotCraftFurnace(robot, furnaceInput));
startDelegateAI(new AIRobotCraftFurnace(robot, furnaceInput, order));
return;
}
@ -203,25 +199,4 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
return false;
}
private ItemStack getOrderFromHomeStation() {
DockingStation s = (DockingStation) robot.getLinkedStation();
for (ActionSlot slot : new ActionIterator(s.getPipe().pipe)) {
if (slot.action instanceof ActionRobotCraft) {
for (IActionParameter p : slot.parameters) {
if (p != null && p instanceof ActionParameterItemStack) {
ActionParameterItemStack param = (ActionParameterItemStack) p;
ItemStack stack = param.getItemStackToDraw();
if (stack != null && !isBlacklisted(stack)) {
return stack;
}
}
}
}
}
return null;
}
}

View file

@ -24,6 +24,7 @@ import buildcraft.core.robots.AIRobotDisposeItems;
import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotGotoStationAndLoad;
import buildcraft.core.robots.AIRobotSearchStackRequest;
import buildcraft.silicon.statements.ActionRobotFilter;
public class BoardRobotDelivery extends RedstoneBoardRobot {
@ -51,7 +52,8 @@ public class BoardRobotDelivery extends RedstoneBoardRobot {
}
if (currentRequest == null) {
startDelegateAI(new AIRobotSearchStackRequest(robot, deliveryBlacklist));
startDelegateAI(new AIRobotSearchStackRequest(robot, ActionRobotFilter.getGateFilter(robot
.getLinkedStation()), deliveryBlacklist));
} else {
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqFilter(), robot.getZoneToWork()));
}

View file

@ -106,6 +106,25 @@ public class ActionRobotFilter extends BCActionPassive {
}
}
public static boolean canInteractWithItem(DockingStation station, IStackFilter filter, Class<?> actionClass) {
boolean actionFound = false;
Pipe pipe = station.getPipe().pipe;
for (ActionSlot s : new ActionIterator(pipe)) {
if (actionClass.isAssignableFrom(s.action.getClass())) {
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);
if (!param.hasFilter() || param.matches(filter)) {
actionFound = true;
break;
}
}
}
return actionFound;
}
public static boolean canInteractWithFluid(DockingStation station, IFluidFilter filter, Class<?> actionClass) {
boolean actionFound = false;
Pipe pipe = station.getPipe().pipe;

View file

@ -15,20 +15,20 @@ import buildcraft.api.gates.IActionParameter;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
public class ActionRobotCraft extends BCActionPassive {
public class ActionStationAllowCraft extends BCActionPassive {
public ActionRobotCraft() {
super("buildcraft:station.craft");
public ActionStationAllowCraft() {
super("buildcraft:robot.allow_craft");
}
@Override
public String getDescription() {
return StringUtils.localize("gate.action.station.craft");
return StringUtils.localize("gate.action.station.allow_craft");
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_craft");
icon = iconRegister.registerIcon("buildcraft:triggers/action_station_allow_craft");
}
@Override

View file

@ -13,8 +13,10 @@ import java.util.Collection;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockWorkbench;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
@ -25,7 +27,7 @@ import buildcraft.api.gates.IActionProvider;
import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.boards.BoardRobotCrafter;
import buildcraft.silicon.TileAssemblyTable;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe;
@ -53,31 +55,34 @@ public class RobotsActionProvider implements IActionProvider {
result.add(BuildCraftSilicon.actionRobotFilter);
result.add(BuildCraftSilicon.actionStationForbidRobot);
for (DockingStation s : stations) {
if (s.robotTaking() != null && s.robotTaking().getBoard() instanceof BoardRobotCrafter) {
result.add(BuildCraftSilicon.actionRobotCraft);
}
}
if (((TileGenericPipe) pipe).pipe.transport instanceof PipeTransportItems) {
result.add(BuildCraftSilicon.actionStationDropInPipe);
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (((TileGenericPipe) pipe).getTile(dir) instanceof IInventory) {
TileEntity tile = ((TileGenericPipe) pipe).getTile(dir);
Block block = ((TileGenericPipe) pipe).getBlock(dir);
if (tile instanceof IInventory) {
result.add(BuildCraftSilicon.actionStationProvideItems);
result.add(BuildCraftSilicon.actionStationRequestItems);
result.add(BuildCraftSilicon.actionStationAcceptItems);
}
if (((TileGenericPipe) pipe).getTile(dir) instanceof IFluidHandler) {
if (tile instanceof IFluidHandler) {
result.add(BuildCraftSilicon.actionStationAcceptFluids);
result.add(BuildCraftSilicon.actionStationProvideFluids);
}
if (((TileGenericPipe) pipe).getTile(dir) instanceof IRequestProvider) {
if (tile instanceof IRequestProvider) {
result.add(BuildCraftSilicon.actionStationMachineRequestItems);
}
if (tile instanceof TileEntityFurnace
|| tile instanceof TileAssemblyTable
|| block instanceof BlockWorkbench) {
result.add(BuildCraftSilicon.actionRobotAllowCraft);
}
}
return result;

View file

@ -99,7 +99,9 @@ public class ItemRobotStation extends ItemBuildCraft {
@Override
public void invalidate() {
if (station != null && !station.getPipe().getWorld().isRemote) {
if (station != null
&& station.getPipe() != null
&& !station.getPipe().getWorld().isRemote) {
RobotRegistry.getRegistry(station.world).removeStation(station);
isValid = false;
}