add a gate action to filter the tools of the robots

This commit is contained in:
Hea3veN 2015-02-17 18:10:26 -03:00
parent adebf197df
commit 6fe8ec37db
7 changed files with 139 additions and 1 deletions

View file

@ -101,6 +101,7 @@ gate.action.robot.work_in_area=Work 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=Robot Forbidden
gate.action.robot.filter=Filter gate.action.robot.filter=Filter
gate.action.robot.filter_tool=Filter Tool
gate.expansion.fader=Redstone Fader gate.expansion.fader=Redstone Fader
gate.expansion.pulsar=Autarchic Pulsar gate.expansion.pulsar=Autarchic Pulsar

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

View file

@ -11,6 +11,7 @@ package buildcraft;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -65,6 +66,7 @@ import buildcraft.robots.boards.BoardRobotPlanterNBT;
import buildcraft.robots.boards.BoardRobotPumpNBT; import buildcraft.robots.boards.BoardRobotPumpNBT;
import buildcraft.robots.boards.BoardRobotShovelmanNBT; import buildcraft.robots.boards.BoardRobotShovelmanNBT;
import buildcraft.robots.statements.ActionRobotFilter; import buildcraft.robots.statements.ActionRobotFilter;
import buildcraft.robots.statements.ActionRobotFilterTool;
import buildcraft.robots.statements.ActionRobotGotoStation; import buildcraft.robots.statements.ActionRobotGotoStation;
import buildcraft.robots.statements.ActionRobotWakeUp; import buildcraft.robots.statements.ActionRobotWakeUp;
import buildcraft.robots.statements.ActionRobotWorkInArea; import buildcraft.robots.statements.ActionRobotWorkInArea;
@ -117,6 +119,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
public static IActionInternal actionRobotWakeUp = new ActionRobotWakeUp(); public static IActionInternal actionRobotWakeUp = new ActionRobotWakeUp();
public static IActionInternal actionRobotWorkInArea = new ActionRobotWorkInArea(); public static IActionInternal actionRobotWorkInArea = new ActionRobotWorkInArea();
public static IActionInternal actionRobotFilter = new ActionRobotFilter(); public static IActionInternal actionRobotFilter = new ActionRobotFilter();
public static IActionInternal actionRobotFilterTool = new ActionRobotFilterTool();
public static IActionInternal actionRobotAllowCraft = new ActionStationAllowCraft(); public static IActionInternal actionRobotAllowCraft = new ActionStationAllowCraft();
public static IActionInternal actionStationRequestItems = new ActionStationRequestItems(); public static IActionInternal actionStationRequestItems = new ActionStationRequestItems();
public static IActionInternal actionStationAcceptItems = new ActionStationAcceptItemsInv(); public static IActionInternal actionStationAcceptItems = new ActionStationAcceptItemsInv();

View file

@ -0,0 +1,34 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.inventory.filters;
import net.minecraft.item.ItemStack;
/**
* Returns true if the stack matches all of the stack filters.
*/
public class AggregateFilter implements IStackFilter {
private final IStackFilter[] filters;
public AggregateFilter(IStackFilter... iFilters) {
filters = iFilters;
}
@Override
public boolean matches(ItemStack stack) {
for (IStackFilter f : filters) {
if (!f.matches(stack)) {
return false;
}
}
return true;
}
}

View file

@ -18,8 +18,10 @@ import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor; import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.AggregateFilter;
import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.robots.DockingStation; import buildcraft.robots.DockingStation;
import buildcraft.robots.statements.ActionRobotFilterTool;
public class AIRobotFetchAndEquipItemStack extends AIRobot { public class AIRobotFetchAndEquipItemStack extends AIRobot {
@ -32,7 +34,7 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
public AIRobotFetchAndEquipItemStack(EntityRobotBase iRobot, IStackFilter iFilter) { public AIRobotFetchAndEquipItemStack(EntityRobotBase iRobot, IStackFilter iFilter) {
super(iRobot); super(iRobot);
filter = iFilter; filter = new AggregateFilter(ActionRobotFilterTool.getGateFilter(iRobot.getLinkedStation()), iFilter);
} }
@Override @Override

View file

@ -0,0 +1,97 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.robots.statements;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import buildcraft.api.robots.IDockingStation;
import buildcraft.api.statements.IActionInternal;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementParameterItemStack;
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.inventory.filters.PassThroughStackFilter;
import buildcraft.core.statements.BCStatement;
import buildcraft.core.utils.StringUtils;
import buildcraft.robots.DockingStation;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.StatementSlot;
public class ActionRobotFilterTool extends BCStatement implements IActionInternal {
public ActionRobotFilterTool() {
super("buildcraft:robot.work_filter_tool");
}
@Override
public String getDescription() {
return StringUtils.localize("gate.action.robot.filter_tool");
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_filter_tool");
}
@Override
public int minParameters() {
return 1;
}
@Override
public int maxParameters() {
return 1;
}
@Override
public IStatementParameter createParameter(int index) {
return new StatementParameterItemStack();
}
public static Collection<ItemStack> getGateFilterStacks(IDockingStation station) {
ArrayList<ItemStack> result = new ArrayList<ItemStack>();
for (StatementSlot slot : new ActionIterator(((DockingStation) station).getPipe().pipe)) {
if (slot.statement instanceof ActionRobotFilterTool) {
for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) {
StatementParameterItemStack param = (StatementParameterItemStack) p;
ItemStack stack = param.getItemStack();
if (stack != null) {
result.add(stack);
}
}
}
}
}
return result;
}
public static IStackFilter getGateFilter(IDockingStation station) {
Collection<ItemStack> stacks = getGateFilterStacks(station);
if (stacks.size() == 0) {
return new PassThroughStackFilter();
} else {
return new ArrayStackOrListFilter(stacks.toArray(new ItemStack[stacks.size()]));
}
}
@Override
public void actionActivate(IStatementContainer source,
IStatementParameter[] parameters) {
}
}

View file

@ -61,6 +61,7 @@ public class RobotsActionProvider implements IActionProvider {
result.add(BuildCraftSilicon.actionRobotWorkInArea); result.add(BuildCraftSilicon.actionRobotWorkInArea);
result.add(BuildCraftSilicon.actionRobotWakeUp); result.add(BuildCraftSilicon.actionRobotWakeUp);
result.add(BuildCraftSilicon.actionRobotFilter); result.add(BuildCraftSilicon.actionRobotFilter);
result.add(BuildCraftSilicon.actionRobotFilterTool);
result.add(BuildCraftSilicon.actionStationForbidRobot); result.add(BuildCraftSilicon.actionStationForbidRobot);
if (((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) { if (((TileGenericPipe) tile).pipe.transport instanceof PipeTransportItems) {