implemented robot sleep / wakeup, for #1873 and #1877

This commit is contained in:
SpaceToad 2014-06-27 23:42:30 +02:00
parent e4e477a241
commit 9f1187c3aa
37 changed files with 537 additions and 143 deletions

View file

@ -89,4 +89,12 @@ public class AIRobot {
delegateAI.abort();
}
}
public final AIRobot getActiveAI() {
if (delegateAI != null) {
return delegateAI.getActiveAI();
} else {
return this;
}
}
}

View file

@ -52,8 +52,6 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory
public abstract boolean linkToStation(IDockingStation station);
public abstract void workInArea(IBox box);
public abstract IBox getAreaToWork();
}

View file

@ -58,6 +58,7 @@ gate.action.pipe.close=Close Pipe
gate.action.station.provide_items=Provide Items
gate.action.station.request_items=Request Items
gate.action.robot.work_in_area=Work in Area
gate.action.robot.wakeup=Wake Up
gate.expansion.fader=Redstone Fader
gate.expansion.pulsar=Autarchic Pulsar
@ -101,6 +102,7 @@ gate.trigger.pipe.tooMuchEnergy=Power Overloaded
gate.trigger.pipe.wire.active=%s Pipe Signal On
gate.trigger.pipe.wire.inactive=%s Pipe Signal Off
gate.trigger.timer=%s Sec Timer
gate.trigger.robot.sleep=Sleep
gui.building.resources=Building Resources
gui.building.fluids=Fluid Tanks

View file

@ -63,6 +63,8 @@ import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.StatementManager;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.robots.DockingStationRegistry;
@ -94,7 +96,6 @@ import buildcraft.core.robots.EntityRobot;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.triggers.ActionMachineControl.Mode;
import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.triggers.DefaultActionProvider;
import buildcraft.core.triggers.DefaultTriggerProvider;
@ -153,28 +154,28 @@ public class BuildCraftCore extends BuildCraftMod {
public static int blockByEntityModel;
public static int legacyPipeModel;
public static int markerModel;
public static BCTrigger triggerMachineActive = new TriggerMachine(true);
public static BCTrigger triggerMachineInactive = new TriggerMachine(false);
public static BCTrigger triggerEmptyInventory = new TriggerInventory(TriggerInventory.State.Empty);
public static BCTrigger triggerContainsInventory = new TriggerInventory(TriggerInventory.State.Contains);
public static BCTrigger triggerSpaceInventory = new TriggerInventory(TriggerInventory.State.Space);
public static BCTrigger triggerFullInventory = new TriggerInventory(TriggerInventory.State.Full);
public static BCTrigger triggerEmptyFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Empty);
public static BCTrigger triggerContainsFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Contains);
public static BCTrigger triggerSpaceFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Space);
public static BCTrigger triggerFullFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Full);
public static BCTrigger triggerRedstoneActive = new TriggerRedstoneInput(true);
public static BCTrigger triggerRedstoneInactive = new TriggerRedstoneInput(false);
public static BCTrigger triggerInventoryBelow25 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_25);
public static BCTrigger triggerInventoryBelow50 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_50);
public static BCTrigger triggerInventoryBelow75 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_75);
public static BCTrigger triggerFluidContainerBelow25 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_25);
public static BCTrigger triggerFluidContainerBelow50 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_50);
public static BCTrigger triggerFluidContainerBelow75 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_75);
public static BCAction actionRedstone = new ActionRedstoneOutput();
public static BCAction actionOn = new ActionMachineControl(Mode.On);
public static BCAction actionOff = new ActionMachineControl(Mode.Off);
public static BCAction actionLoop = new ActionMachineControl(Mode.Loop);
public static ITrigger triggerMachineActive = new TriggerMachine(true);
public static ITrigger triggerMachineInactive = new TriggerMachine(false);
public static ITrigger triggerEmptyInventory = new TriggerInventory(TriggerInventory.State.Empty);
public static ITrigger triggerContainsInventory = new TriggerInventory(TriggerInventory.State.Contains);
public static ITrigger triggerSpaceInventory = new TriggerInventory(TriggerInventory.State.Space);
public static ITrigger triggerFullInventory = new TriggerInventory(TriggerInventory.State.Full);
public static ITrigger triggerEmptyFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Empty);
public static ITrigger triggerContainsFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Contains);
public static ITrigger triggerSpaceFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Space);
public static ITrigger triggerFullFluid = new TriggerFluidContainer(TriggerFluidContainer.State.Full);
public static ITrigger triggerRedstoneActive = new TriggerRedstoneInput(true);
public static ITrigger triggerRedstoneInactive = new TriggerRedstoneInput(false);
public static ITrigger triggerInventoryBelow25 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_25);
public static ITrigger triggerInventoryBelow50 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_50);
public static ITrigger triggerInventoryBelow75 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_75);
public static ITrigger triggerFluidContainerBelow25 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_25);
public static ITrigger triggerFluidContainerBelow50 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_50);
public static ITrigger triggerFluidContainerBelow75 = new TriggerFluidContainerLevel(TriggerFluidContainerLevel.TriggerType.BELOW_75);
public static IAction actionRedstone = new ActionRedstoneOutput();
public static IAction actionOn = new ActionMachineControl(Mode.On);
public static IAction actionOff = new ActionMachineControl(Mode.Off);
public static IAction actionLoop = new ActionMachineControl(Mode.Loop);
public static boolean loadDefaultRecipes = true;
public static boolean consumeWaterSources = false;
//public static BptItem[] itemBptProps = new BptItem[Item.itemsList.length];

View file

@ -27,6 +27,8 @@ import net.minecraftforge.oredict.OreDictionary;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.StatementManager;
import buildcraft.api.gates.TriggerParameterItemStack;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
@ -48,7 +50,6 @@ import buildcraft.core.robots.boards.BoardRobotLumberjackNBT;
import buildcraft.core.robots.boards.BoardRobotMinerNBT;
import buildcraft.core.robots.boards.BoardRobotPickerNBT;
import buildcraft.core.robots.boards.BoardRobotPlanterNBT;
import buildcraft.core.triggers.BCAction;
import buildcraft.silicon.BlockLaser;
import buildcraft.silicon.BlockLaserTable;
import buildcraft.silicon.GuiHandler;
@ -67,11 +68,14 @@ import buildcraft.silicon.network.PacketHandlerSilicon;
import buildcraft.silicon.recipes.AdvancedFacadeRecipe;
import buildcraft.silicon.recipes.GateExpansionRecipe;
import buildcraft.silicon.recipes.GateLogicSwapRecipe;
import buildcraft.silicon.statements.ActionRobotGoToStation;
import buildcraft.silicon.statements.ActionRobotGotoStation;
import buildcraft.silicon.statements.ActionRobotWakeUp;
import buildcraft.silicon.statements.ActionRobotWorkInArea;
import buildcraft.silicon.statements.ActionStationProvideItems;
import buildcraft.silicon.statements.ActionStationRequestItems;
import buildcraft.silicon.statements.RobotsActionProvider;
import buildcraft.silicon.statements.RobotsTriggerProvider;
import buildcraft.silicon.statements.TriggerRobotSleep;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.GateExpansionPulsar;
@ -94,10 +98,13 @@ public class BuildCraftSilicon extends BuildCraftMod {
public static Item redstoneCrystal;
public static Item robotItem;
public static BCAction actionRobotGotoStation = new ActionRobotGoToStation();
public static BCAction actionRobotWorkInArea = new ActionRobotWorkInArea();
public static BCAction actionStationRequestItems = new ActionStationRequestItems();
public static BCAction actionStationProvideItems = new ActionStationProvideItems();
public static IAction actionRobotGotoStation = new ActionRobotGotoStation();
public static IAction actionRobotWakeUp = new ActionRobotWakeUp();
public static IAction actionRobotWorkInArea = new ActionRobotWorkInArea();
public static IAction actionStationRequestItems = new ActionStationRequestItems();
public static IAction actionStationProvideItems = new ActionStationProvideItems();
public static ITrigger triggerRobotSleep = new TriggerRobotSleep();
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent evt) {
@ -140,6 +147,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBomberNBT.instance, 1);
StatementManager.registerActionProvider(new RobotsActionProvider());
StatementManager.registerTriggerProvider(new RobotsTriggerProvider());
}
@Mod.EventHandler

View file

@ -36,6 +36,8 @@ import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.StatementManager;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.transport.IExtractionHandler;
@ -49,8 +51,6 @@ import buildcraft.core.Version;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionPipeClose;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.BlockFilteredBuffer;
import buildcraft.transport.BlockGenericPipe;
@ -170,23 +170,23 @@ public class BuildCraftTransport extends BuildCraftMod {
public static int groupItemsTrigger;
public static String[] facadeBlacklist;
public static BCTrigger[] triggerPipe = new BCTrigger[PipeContents.values().length];
public static BCTrigger[] triggerPipeWireActive = new BCTrigger[PipeWire.values().length];
public static BCTrigger[] triggerPipeWireInactive = new BCTrigger[PipeWire.values().length];
public static BCTrigger[] triggerTimer = new BCTrigger[TriggerClockTimer.Time.VALUES.length];
public static BCTrigger[] triggerRedstoneLevel = new BCTrigger[15];
public static BCAction[] actionPipeWire = new ActionSignalOutput[PipeWire.values().length];
public static BCAction actionPipeClose = new ActionPipeClose();
public static BCAction actionEnergyPulser = new ActionEnergyPulsar();
public static BCAction actionSingleEnergyPulse = new ActionSingleEnergyPulse();
public static BCAction[] actionPipeColor = new BCAction[16];
public static BCAction[] actionPipeDirection = new BCAction[16];
public static BCAction[] actionPowerLimiter = new BCAction[7];
public static BCAction[] actionRedstoneLevel = new BCAction[15];
public static BCAction actionExtractionPresetRed = new ActionExtractionPreset(EnumColor.RED);
public static BCAction actionExtractionPresetBlue = new ActionExtractionPreset(EnumColor.BLUE);
public static BCAction actionExtractionPresetGreen = new ActionExtractionPreset(EnumColor.GREEN);
public static BCAction actionExtractionPresetYellow = new ActionExtractionPreset(EnumColor.YELLOW);
public static ITrigger[] triggerPipe = new ITrigger[PipeContents.values().length];
public static ITrigger[] triggerPipeWireActive = new ITrigger[PipeWire.values().length];
public static ITrigger[] triggerPipeWireInactive = new ITrigger[PipeWire.values().length];
public static ITrigger[] triggerTimer = new ITrigger[TriggerClockTimer.Time.VALUES.length];
public static ITrigger[] triggerRedstoneLevel = new ITrigger[15];
public static IAction[] actionPipeWire = new ActionSignalOutput[PipeWire.values().length];
public static IAction actionPipeClose = new ActionPipeClose();
public static IAction actionEnergyPulser = new ActionEnergyPulsar();
public static IAction actionSingleEnergyPulse = new ActionSingleEnergyPulse();
public static IAction[] actionPipeColor = new IAction[16];
public static IAction[] actionPipeDirection = new IAction[16];
public static IAction[] actionPowerLimiter = new IAction[7];
public static IAction[] actionRedstoneLevel = new IAction[15];
public static IAction actionExtractionPresetRed = new ActionExtractionPreset(EnumColor.RED);
public static IAction actionExtractionPresetBlue = new ActionExtractionPreset(EnumColor.BLUE);
public static IAction actionExtractionPresetGreen = new ActionExtractionPreset(EnumColor.GREEN);
public static IAction actionExtractionPresetYellow = new ActionExtractionPreset(EnumColor.YELLOW);
@Mod.Instance("BuildCraft|Transport")
public static BuildCraftTransport instance;

View file

@ -11,9 +11,9 @@ package buildcraft.builders.triggers;
import net.minecraft.util.IIcon;
import buildcraft.builders.filler.pattern.FillerPattern;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
public class ActionFiller extends BCAction {
public class ActionFiller extends BCActionPassive {
public final FillerPattern pattern;

View file

@ -186,7 +186,7 @@ public class ItemMapLocation extends ItemBuildCraft {
}
}
public static IBox getBlox(ItemStack item) {
public static IBox getBox(ItemStack item) {
NBTTagCompound cpt = NBTUtils.getItemData(item);
if (cpt.hasKey("kind") && cpt.getByte("kind") == 1) {

View file

@ -63,5 +63,7 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
terminate();
}
}
terminate();
}
}

View file

@ -16,11 +16,14 @@ import buildcraft.core.Box;
public class AIRobotFindRandomGroundBlock extends AIRobot {
private static final int MAX_ATTEMPTS = 4096;
public BlockIndex blockFound;
private int range;
private IBlockFilter filter;
private IBox area;
private int attempts = 0;
public AIRobotFindRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
super(iRobot, 2, 1);
@ -32,29 +35,33 @@ public class AIRobotFindRandomGroundBlock extends AIRobot {
@Override
public void update() {
if (blockFound == null) {
int x = 0;
int z = 0;
attempts++;
if (area == null) {
double r = robot.worldObj.rand.nextFloat() * range;
double a = robot.worldObj.rand.nextFloat() * 2.0 * Math.PI;
if (attempts > MAX_ATTEMPTS) {
terminate();
}
x = (int) (Math.cos(a) * r + Math.floor(robot.posX));
z = (int) (Math.sin(a) * r + Math.floor(robot.posZ));
} else {
x = (int) area.pMin().x + robot.worldObj.rand.nextInt(((Box) area).sizeX());
z = (int) area.pMin().z + robot.worldObj.rand.nextInt(((Box) area).sizeZ());
}
int x = 0;
int z = 0;
for (int y = robot.worldObj.getHeight(); y >= 0; --y) {
if (filter.matches(robot.worldObj, x, y, z)) {
blockFound = new BlockIndex(x, y, z);
terminate();
return;
} else if (!robot.worldObj.isAirBlock(x, y, z)) {
return;
}
if (area == null) {
double r = robot.worldObj.rand.nextFloat() * range;
double a = robot.worldObj.rand.nextFloat() * 2.0 * Math.PI;
x = (int) (Math.cos(a) * r + Math.floor(robot.posX));
z = (int) (Math.sin(a) * r + Math.floor(robot.posZ));
} else {
x = (int) area.pMin().x + robot.worldObj.rand.nextInt(((Box) area).sizeX());
z = (int) area.pMin().z + robot.worldObj.rand.nextInt(((Box) area).sizeZ());
}
for (int y = robot.worldObj.getHeight(); y >= 0; --y) {
if (filter.matches(robot.worldObj, x, y, z)) {
blockFound = new BlockIndex(x, y, z);
terminate();
return;
} else if (!robot.worldObj.isAirBlock(x, y, z)) {
return;
}
}
}

View file

@ -0,0 +1,33 @@
/**
* 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.robots;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
public class AIRobotGotoSleep extends AIRobot {
public AIRobotGotoSleep(EntityRobotBase iRobot) {
super(iRobot, 0, 1);
}
@Override
public void start() {
startDelegateAI(new AIRobotGotoDock(robot, (DockingStation) robot.getLinkedStation()));
}
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoDock) {
startDelegateAI(new AIRobotSleep(robot));
} else if (ai instanceof AIRobotSleep) {
terminate();
}
}
}

View file

@ -0,0 +1,43 @@
/**
* 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.robots;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.silicon.statements.ActionRobotWakeUp;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.ActionSlot;
public class AIRobotSleep extends AIRobot {
private static final int SLEEPING_TIME = 60 * 20;
private int sleptTime = 0;
public AIRobotSleep(EntityRobotBase iRobot) {
super(iRobot, 0, 1);
}
@Override
public void preempt(AIRobot ai) {
for (ActionSlot s : new ActionIterator(((DockingStation) robot.getLinkedStation()).pipe.pipe)) {
if (s.action instanceof ActionRobotWakeUp) {
terminate();
}
}
}
@Override
public void update() {
sleptTime++;
if (sleptTime > SLEEPING_TIME) {
terminate();
}
}
}

View file

@ -45,6 +45,9 @@ import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCMessageInfo;
import buildcraft.core.network.RPCSide;
import buildcraft.silicon.statements.ActionRobotWorkInArea;
import buildcraft.transport.gates.ActionIterator;
import buildcraft.transport.gates.ActionSlot;
public class EntityRobot extends EntityRobotBase implements
IEntityAdditionalSpawnData, IInventory {
@ -85,9 +88,6 @@ public class EntityRobot extends EntityRobotBase implements
private double mjStored;
private IBox areaToWork;
private long areaResetDate;
public EntityRobot(World world, NBTTagCompound boardNBT) {
this(world);
@ -656,14 +656,18 @@ public class EntityRobot extends EntityRobotBase implements
}
}
@Override
public void workInArea(IBox box) {
areaToWork = box;
areaResetDate = worldObj.getTotalWorldTime() + 5;
}
@Override
public IBox getAreaToWork() {
return areaToWork;
for (ActionSlot s : new ActionIterator(linkedDockingStation.pipe.pipe)) {
if (s.action instanceof ActionRobotWorkInArea) {
IBox box = ActionRobotWorkInArea.getArea(s);
if (box != null) {
return box;
}
}
}
return null;
}
}

View file

@ -20,6 +20,7 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.filters.OreStackFilter;
import buildcraft.core.robots.AIRobotFetchAndEquipItemStack;
import buildcraft.core.robots.AIRobotGotoRandomGroundBlock;
import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotPlantSaple;
import buildcraft.core.robots.IBlockFilter;
@ -53,7 +54,17 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoRandomGroundBlock) {
startDelegateAI(new AIRobotPlantSaple(robot, ((AIRobotGotoRandomGroundBlock) ai).blockFound));
AIRobotGotoRandomGroundBlock gotoBlock = (AIRobotGotoRandomGroundBlock) ai;
if (((AIRobotGotoRandomGroundBlock) ai).blockFound == null) {
startDelegateAI(new AIRobotGotoSleep(robot));
} else {
startDelegateAI(new AIRobotPlantSaple(robot, ((AIRobotGotoRandomGroundBlock) ai).blockFound));
}
} else if (ai instanceof AIRobotFetchAndEquipItemStack) {
if (robot.getItemInUse() == null) {
startDelegateAI(new AIRobotGotoSleep(robot));
}
}
}

View file

@ -12,7 +12,7 @@ import java.util.Locale;
import buildcraft.core.utils.StringUtils;
public class ActionMachineControl extends BCAction {
public class ActionMachineControl extends BCActionPassive {
public enum Mode {

View file

@ -15,7 +15,7 @@ import buildcraft.api.gates.IGate;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
public class ActionPipeClose extends BCAction {
public class ActionPipeClose extends BCActionActive {
public ActionPipeClose() {
super("buildcraft:pipe.close");

View file

@ -9,7 +9,7 @@
package buildcraft.core.triggers;
public class ActionRedstoneOutput extends BCAction {
public class ActionRedstoneOutput extends BCActionPassive {
public ActionRedstoneOutput() {
super("buildcraft:redstone.output", "buildcraft.redstone.output");

View file

@ -0,0 +1,24 @@
/**
* 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.triggers;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
public abstract class BCActionActive extends BCStatement implements IAction {
public BCActionActive(String... uniqueTag) {
super(uniqueTag);
}
@Override
public IActionParameter createParameter(int index) {
return null;
}
}

View file

@ -12,9 +12,9 @@ import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
public abstract class BCAction extends BCStatement implements IAction {
public abstract class BCActionPassive extends BCStatement implements IAction {
public BCAction(String... uniqueTag) {
public BCActionPassive(String... uniqueTag) {
super(uniqueTag);
}
@ -24,6 +24,6 @@ public abstract class BCAction extends BCStatement implements IAction {
}
@Override
public void actionActivate(IGate gate, IActionParameter[] parameters) {
public final void actionActivate(IGate gate, IActionParameter[] parameters) {
}
}

View file

@ -23,14 +23,14 @@ import buildcraft.core.ItemMapLocation;
import buildcraft.core.robots.AIRobotGoAndLinkToDock;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionActive;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe;
public class ActionRobotGoToStation extends BCAction {
public class ActionRobotGotoStation extends BCActionActive {
public ActionRobotGoToStation() {
public ActionRobotGotoStation() {
super("buildcraft:robot.goto_station");
}

View file

@ -0,0 +1,31 @@
/**
* 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.silicon.statements;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
public class ActionRobotWakeUp extends BCActionPassive {
public ActionRobotWakeUp() {
super("buildcraft:robot.wakeup");
}
@Override
public String getDescription() {
return StringUtils.localize("gate.action.robot.wakeup");
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_wakeup");
}
}

View file

@ -11,20 +11,15 @@ package buildcraft.silicon.statements;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IBox;
import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.core.ItemMapLocation;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.gates.ActionSlot;
public class ActionRobotWorkInArea extends BCAction {
public class ActionRobotWorkInArea extends BCActionPassive {
public ActionRobotWorkInArea() {
super("buildcraft:robot.work_in_area");
@ -40,34 +35,18 @@ public class ActionRobotWorkInArea extends BCAction {
icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_in_area");
}
@Override
public void actionActivate(IGate gate, IActionParameter[] parameters) {
if (parameters[0] == null) {
return;
public static IBox getArea(ActionSlot slot) {
if (slot.parameters[0] == null) {
return null;
}
ItemStack stack = ((ActionParameterItemStack) parameters[0]).getItemStackToDraw();
ItemStack stack = ((ActionParameterItemStack) slot.parameters[0]).getItemStackToDraw();
if (!(stack.getItem() instanceof ItemMapLocation)) {
return;
return null;
}
IBox box = ItemMapLocation.getBlox(stack);
if (box == null) {
return;
}
Pipe<?> pipe = (Pipe<?>) gate.getPipe();
TileGenericPipe tile = pipe.container;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
DockingStation station = tile.getStation(d);
if (station != null && station.linked() != null) {
station.linked().workInArea(box);
}
}
return ItemMapLocation.getBox(stack);
}
@Override

View file

@ -16,11 +16,11 @@ import net.minecraft.item.ItemStack;
import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionActive;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
public class ActionStationProvideItems extends BCAction {
public class ActionStationProvideItems extends BCActionActive {
public ActionStationProvideItems() {
super("buildcraft:station.provide_items");

View file

@ -16,11 +16,11 @@ import net.minecraft.item.ItemStack;
import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionActive;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
public class ActionStationRequestItems extends BCAction {
public class ActionStationRequestItems extends BCActionActive {
public ActionStationRequestItems() {
super("buildcraft:station.request_items");

View file

@ -44,6 +44,7 @@ public class RobotsActionProvider implements IActionProvider {
result.add(BuildCraftSilicon.actionRobotGotoStation);
result.add(BuildCraftSilicon.actionRobotWorkInArea);
result.add(BuildCraftSilicon.actionRobotWakeUp);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (((TileGenericPipe) pipe).getTile(dir) instanceof IInventory) {

View file

@ -0,0 +1,54 @@
/**
* 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.silicon.statements;
import java.util.Collection;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerProvider;
import buildcraft.api.transport.IPipeTile;
import buildcraft.transport.TileGenericPipe;
public class RobotsTriggerProvider implements ITriggerProvider {
@Override
public Collection<ITrigger> getPipeTriggers(IPipeTile pipe) {
LinkedList<ITrigger> result = new LinkedList<ITrigger>();
boolean stationFound = false;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (((TileGenericPipe) pipe).getStation(dir) != null) {
stationFound = true;
break;
}
}
if (!stationFound) {
return result;
}
result.add(BuildCraftSilicon.triggerRobotSleep);
return result;
}
@Override
public Collection<ITrigger> getNeighborTriggers(Block block, TileEntity tile) {
return null;
}
}

View file

@ -0,0 +1,60 @@
/**
* 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.silicon.statements;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.robots.AIRobotSleep;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe;
public class TriggerRobotSleep extends BCTrigger {
public TriggerRobotSleep() {
super("buildcraft:robot.sleep");
}
@Override
public String getDescription() {
return StringUtils.localize("gate.trigger.robot.sleep");
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_robot_sleep");
}
@Override
public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) {
Pipe<?> pipe = (Pipe<?>) gate.getPipe();
TileGenericPipe tile = pipe.container;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
DockingStation station = tile.getStation(d);
if (station != null && station.linked() != null) {
EntityRobot robot = (EntityRobot) station.linked();
if (robot.mainAI.getActiveAI() instanceof AIRobotSleep) {
return true;
}
}
}
return false;
}
}

View file

@ -0,0 +1,111 @@
/**
* 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.transport.gates;
import java.util.Iterator;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.transport.ActionActiveState;
import buildcraft.transport.Gate;
import buildcraft.transport.Pipe;
public class ActionIterator implements Iterable<ActionSlot> {
private Pipe pipe;
public ActionIterator(Pipe iPipe) {
pipe = iPipe;
}
@Override
public Iterator<ActionSlot> iterator() {
return new It();
}
private class It implements Iterator<ActionSlot> {
private ForgeDirection curDir = ForgeDirection.values()[0];
private int index = 0;
private ActionSlot next;
public It() {
while (!isValid()) {
if (index < Gate.MAX_STATEMENTS - 1) {
index++;
} else if (curDir != ForgeDirection.UNKNOWN) {
index = 0;
curDir = ForgeDirection.values()[curDir.ordinal() + 1];
} else {
break;
}
}
if (isValid()) {
next = new ActionSlot();
next.action = pipe.gates[curDir.ordinal()].actions[index];
next.parameters = pipe.gates[curDir.ordinal()].actionParameters[index];
}
}
@Override
public boolean hasNext() {
return next != null;
}
@Override
public ActionSlot next() {
ActionSlot result = next;
while (true) {
if (index < Gate.MAX_STATEMENTS - 1) {
index++;
} else if (curDir != ForgeDirection.UNKNOWN) {
index = 0;
curDir = ForgeDirection.values()[curDir.ordinal() + 1];
} else {
break;
}
}
if (isValid()) {
next = new ActionSlot();
next.action = pipe.gates[curDir.ordinal()].actions[index];
next.parameters = pipe.gates[curDir.ordinal()].actionParameters[index];
} else {
next = null;
}
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported.");
}
private boolean isValid() {
if (curDir == ForgeDirection.UNKNOWN) {
return false;
}
Gate gate = pipe.gates[curDir.ordinal()];
if (gate == null) {
return false;
}
if (gate.actions[index] == null || gate.actionsState[index] != ActionActiveState.Activated) {
return false;
}
return true;
}
};
}

View file

@ -0,0 +1,17 @@
/**
* 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.transport.gates;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
public class ActionSlot {
public IAction action;
public IActionParameter[] parameters;
}

View file

@ -10,10 +10,10 @@ package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
public class ActionEnergyPulsar extends BCAction {
public class ActionEnergyPulsar extends BCActionPassive {
public ActionEnergyPulsar() {
super("buildcraft:pulsar.constant", "buildcraft.pulser.constant");

View file

@ -12,11 +12,11 @@ import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils;
public class ActionExtractionPreset extends BCAction {
public class ActionExtractionPreset extends BCActionPassive {
public final EnumColor color;

View file

@ -12,11 +12,11 @@ import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils;
public class ActionPipeColor extends BCAction {
public class ActionPipeColor extends BCActionPassive {
public final EnumColor color;

View file

@ -16,9 +16,9 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
public class ActionPipeDirection extends BCAction {
public class ActionPipeDirection extends BCActionPassive {
public final ForgeDirection direction;

View file

@ -12,10 +12,10 @@ import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.transport.pipes.PipePowerIron.PowerMode;
public class ActionPowerLimiter extends BCAction {
public class ActionPowerLimiter extends BCActionPassive {
public final PowerMode limit;

View file

@ -14,10 +14,10 @@ import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
public class ActionRedstoneFaderOutput extends BCAction {
public class ActionRedstoneFaderOutput extends BCActionPassive {
public final int level;

View file

@ -13,12 +13,12 @@ import java.util.Locale;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionActive;
import buildcraft.core.triggers.StatementIconProvider;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate;
public class ActionSignalOutput extends BCAction {
public class ActionSignalOutput extends BCActionActive {
public PipeWire color;

View file

@ -10,10 +10,10 @@ package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.StringUtils;
public class ActionSingleEnergyPulse extends BCAction {
public class ActionSingleEnergyPulse extends BCActionPassive {
public ActionSingleEnergyPulse() {
super("buildcraft:pulsar.single", "buildcraft.pulser.single");