diff --git a/api/buildcraft/api/robots/EntityRobotBase.java b/api/buildcraft/api/robots/EntityRobotBase.java index 32741540..b6a04272 100755 --- a/api/buildcraft/api/robots/EntityRobotBase.java +++ b/api/buildcraft/api/robots/EntityRobotBase.java @@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import buildcraft.api.boards.RedstoneBoardRobot; +import buildcraft.api.core.IBox; public abstract class EntityRobotBase extends EntityLiving implements IInventory { @@ -51,4 +52,8 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory public abstract boolean linkToStation(IDockingStation station); + public abstract void workInArea(IBox box); + + public abstract IBox getAreaToWork(); + } diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 69c3b7be..e9ea3ee4 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -5,6 +5,8 @@ buildcraft.boardRobotLumberjack=Lumberjack buildcraft.boardRobotPlanter=Planter buildcraft.boardRobotLeaveCutter=Leave Cutter buildcraft.boardRobotCarrier=Carrier +buildcraft.boardRobotBomber=Bomber +buildcraft.boardRobotKnight=Knight buildcraft.boardDetail.parameters=Parameters buildcraft.boardDetail.range=Range @@ -55,6 +57,7 @@ gate.action.robot.goto_station=Goto Station 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.expansion.fader=Redstone Fader gate.expansion.pulsar=Autarchic Pulsar diff --git a/buildcraft_resources/assets/buildcraft/textures/entities/robot_bomber.png b/buildcraft_resources/assets/buildcraft/textures/entities/robot_bomber.png new file mode 100755 index 00000000..9e8ab945 Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/entities/robot_bomber.png differ diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index e748bb77..b54d6d51 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -40,6 +40,7 @@ import buildcraft.core.Version; import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.robots.RobotIntegrationRecipe; +import buildcraft.core.robots.boards.BoardRobotBomberNBT; import buildcraft.core.robots.boards.BoardRobotCarrierNBT; import buildcraft.core.robots.boards.BoardRobotKnightNBT; import buildcraft.core.robots.boards.BoardRobotLeaveCutterNBT; @@ -66,6 +67,7 @@ import buildcraft.silicon.recipes.AdvancedFacadeRecipe; import buildcraft.silicon.recipes.GateExpansionRecipe; import buildcraft.silicon.recipes.GateLogicSwapRecipe; import buildcraft.silicon.statements.ActionRobotGoToStation; +import buildcraft.silicon.statements.ActionRobotWorkInArea; import buildcraft.silicon.statements.ActionStationProvideItems; import buildcraft.silicon.statements.ActionStationRequestItems; import buildcraft.silicon.statements.RobotsActionProvider; @@ -92,6 +94,7 @@ public class BuildCraftSilicon extends BuildCraftMod { 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(); @@ -132,6 +135,7 @@ public class BuildCraftSilicon extends BuildCraftMod { RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotPlanterNBT.instance, 5); RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotLeaveCutterNBT.instance, 5); RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotKnightNBT.instance, 1); + RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBomberNBT.instance, 1); StatementManager.registerActionProvider(new RobotsActionProvider()); } diff --git a/common/buildcraft/core/ItemMapLocation.java b/common/buildcraft/core/ItemMapLocation.java index 8d0aed89..a23f1bcc 100755 --- a/common/buildcraft/core/ItemMapLocation.java +++ b/common/buildcraft/core/ItemMapLocation.java @@ -27,6 +27,7 @@ import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.core.BlockIndex; +import buildcraft.api.core.IBox; import buildcraft.builders.TileMarker; import buildcraft.builders.TilePathMarker; import buildcraft.core.utils.NBTUtils; @@ -185,6 +186,23 @@ public class ItemMapLocation extends ItemBuildCraft { } } + public static IBox getBlox(ItemStack item) { + NBTTagCompound cpt = NBTUtils.getItemData(item); + + if (cpt.hasKey("kind") && cpt.getByte("kind") == 1) { + int xMin = cpt.getInteger("xMin"); + int yMin = cpt.getInteger("yMin"); + int zMin = cpt.getInteger("zMin"); + int xMax = cpt.getInteger("xMax"); + int yMax = cpt.getInteger("yMax"); + int zMax = cpt.getInteger("zMax"); + + return new Box(xMin, yMin, zMin, xMax, yMax, zMax); + } else { + return null; + } + } + public static ForgeDirection getSide(ItemStack item) { NBTTagCompound cpt = NBTUtils.getItemData(item); diff --git a/common/buildcraft/core/robots/AIRobotLoad.java b/common/buildcraft/core/robots/AIRobotLoad.java index 50a0dbfb..3446b0fc 100755 --- a/common/buildcraft/core/robots/AIRobotLoad.java +++ b/common/buildcraft/core/robots/AIRobotLoad.java @@ -20,11 +20,16 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.InventoryIterator; import buildcraft.core.inventory.Transactor; +import buildcraft.core.inventory.filters.IStackFilter; public class AIRobotLoad extends AIRobot { - public AIRobotLoad(EntityRobotBase iRobot) { + private IStackFilter filter; + + public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) { super(iRobot, 0, 1); + + filter = iFilter; } @Override @@ -48,7 +53,7 @@ public class AIRobotLoad extends AIRobot { for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, dir.getOpposite())) { ItemStack stack = slot.getStackInSlot(); - if (stack != null) { + if (stack != null && filter.matches(stack)) { slot.setStackInSlot(null); robot.setInventorySlotContents(i, stack); break; diff --git a/common/buildcraft/core/robots/EntityRobot.java b/common/buildcraft/core/robots/EntityRobot.java index 1ec0f45f..a4edbfbb 100755 --- a/common/buildcraft/core/robots/EntityRobot.java +++ b/common/buildcraft/core/robots/EntityRobot.java @@ -33,6 +33,7 @@ import buildcraft.api.boards.RedstoneBoardNBT; import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; +import buildcraft.api.core.IBox; import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.DockingStationRegistry; @@ -84,6 +85,9 @@ public class EntityRobot extends EntityRobotBase implements private double mjStored; + private IBox areaToWork; + private long areaResetDate; + public EntityRobot(World world, NBTTagCompound boardNBT) { this(world); @@ -652,4 +656,14 @@ public class EntityRobot extends EntityRobotBase implements } } + @Override + public void workInArea(IBox box) { + areaToWork = box; + areaResetDate = worldObj.getTotalWorldTime() + 5; + } + + @Override + public IBox getAreaToWork() { + return areaToWork; + } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotBomber.java b/common/buildcraft/core/robots/boards/BoardRobotBomber.java new file mode 100755 index 00000000..3fa531a3 --- /dev/null +++ b/common/buildcraft/core/robots/boards/BoardRobotBomber.java @@ -0,0 +1,57 @@ +/** + * 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.boards; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import buildcraft.api.boards.RedstoneBoardRobot; +import buildcraft.api.boards.RedstoneBoardRobotNBT; +import buildcraft.api.robots.AIRobot; +import buildcraft.api.robots.EntityRobotBase; +import buildcraft.core.inventory.filters.ArrayStackFilter; +import buildcraft.core.inventory.filters.IStackFilter; +import buildcraft.core.robots.AIRobotGotoStationToLoad; +import buildcraft.core.robots.AIRobotLoad; + +public class BoardRobotBomber extends RedstoneBoardRobot { + + private static final IStackFilter TNT_FILTER = new ArrayStackFilter(new ItemStack(Blocks.tnt)); + + public BoardRobotBomber(EntityRobotBase iRobot) { + super(iRobot, 0); + } + + @Override + public RedstoneBoardRobotNBT getNBTHandler() { + return BoardRobotBomberNBT.instance; + } + + @Override + public final void update() { + boolean containItems = false; + + for (int i = 0; i < robot.getSizeInventory(); ++i) { + if (robot.getStackInSlot(i) != null) { + containItems = true; + } + } + + if (!containItems) { + startDelegateAI(new AIRobotGotoStationToLoad(robot, TNT_FILTER)); + } + } + + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotGotoStationToLoad) { + startDelegateAI(new AIRobotLoad(robot, TNT_FILTER)); + } + } +} diff --git a/common/buildcraft/core/robots/boards/BoardRobotBomberNBT.java b/common/buildcraft/core/robots/boards/BoardRobotBomberNBT.java new file mode 100755 index 00000000..76bacf98 --- /dev/null +++ b/common/buildcraft/core/robots/boards/BoardRobotBomberNBT.java @@ -0,0 +1,72 @@ +/** + * 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.boards; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +import buildcraft.api.boards.RedstoneBoardRobot; +import buildcraft.api.boards.RedstoneBoardRobotNBT; +import buildcraft.api.robots.EntityRobotBase; +import buildcraft.core.DefaultProps; +import buildcraft.core.utils.StringUtils; + +public final class BoardRobotBomberNBT extends RedstoneBoardRobotNBT { + + public static BoardRobotBomberNBT instance = new BoardRobotBomberNBT(); + + private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", + DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_bomber.png"); + + private IIcon icon; + + @Override + public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) { + return new BoardRobotBomber(robot); + } + + @Override + public ResourceLocation getRobotTexture() { + return TEXTURE; + } + + @Override + public String getID() { + return "buildcraft:boardRobotBomber"; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) { + list.add(StringUtils.localize("buildcraft.boardRobotBomber")); + } + + @Override + public void registerIcons(IIconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcraft:board_red"); + } + + @Override + public IIcon getIcon(NBTTagCompound nbt) { + return icon; + } + + @Override + public void createRandomBoard(NBTTagCompound nbt) { + } + + @Override + public void createDefaultBoard(NBTTagCompound nbt) { + } +} diff --git a/common/buildcraft/core/robots/boards/BoardRobotCarrier.java b/common/buildcraft/core/robots/boards/BoardRobotCarrier.java index ca622930..013b7557 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotCarrier.java +++ b/common/buildcraft/core/robots/boards/BoardRobotCarrier.java @@ -49,7 +49,7 @@ public class BoardRobotCarrier extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotGotoStationToLoad) { - startDelegateAI(new AIRobotLoad(robot)); + startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter())); } else if (ai instanceof AIRobotGoToStationToUnload) { startDelegateAI(new AIRobotUnload(robot)); } diff --git a/common/buildcraft/core/triggers/BCAction.java b/common/buildcraft/core/triggers/BCAction.java index 3007050b..17b1710d 100644 --- a/common/buildcraft/core/triggers/BCAction.java +++ b/common/buildcraft/core/triggers/BCAction.java @@ -26,4 +26,9 @@ public abstract class BCAction extends BCStatement implements IAction { @Override public void actionActivate(IGate gate, IActionParameter[] parameters) { } + + @Override + public IAction rotateLeft() { + return this; + } } diff --git a/common/buildcraft/core/triggers/BCTrigger.java b/common/buildcraft/core/triggers/BCTrigger.java index 67f06937..51881bdc 100644 --- a/common/buildcraft/core/triggers/BCTrigger.java +++ b/common/buildcraft/core/triggers/BCTrigger.java @@ -51,4 +51,9 @@ public abstract class BCTrigger extends BCStatement implements ITrigger { public ITriggerParameter createParameter(int index) { return new TriggerParameterItemStack(); } + + @Override + public ITrigger rotateLeft() { + return this; + } } diff --git a/common/buildcraft/silicon/statements/ActionRobotGoToStation.java b/common/buildcraft/silicon/statements/ActionRobotGoToStation.java index ab7ca723..e705ca59 100755 --- a/common/buildcraft/silicon/statements/ActionRobotGoToStation.java +++ b/common/buildcraft/silicon/statements/ActionRobotGoToStation.java @@ -81,7 +81,7 @@ public class ActionRobotGoToStation extends BCAction { ItemStack item = stackParam.getItemStackToDraw(); if (item.getItem() instanceof ItemMapLocation) { - BlockIndex index = ItemMapLocation.getBlockIndex (item); + BlockIndex index = ItemMapLocation.getBlockIndex(item); if (index != null) { ForgeDirection side = ItemMapLocation.getSide(item); @@ -109,4 +109,5 @@ public class ActionRobotGoToStation extends BCAction { public IActionParameter createParameter(int index) { return new ActionParameterItemStack(); } + } diff --git a/common/buildcraft/silicon/statements/ActionRobotWorkInArea.java b/common/buildcraft/silicon/statements/ActionRobotWorkInArea.java new file mode 100755 index 00000000..135ff81e --- /dev/null +++ b/common/buildcraft/silicon/statements/ActionRobotWorkInArea.java @@ -0,0 +1,90 @@ +/** + * 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.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +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.utils.StringUtils; +import buildcraft.transport.Pipe; +import buildcraft.transport.TileGenericPipe; + +public class ActionRobotWorkInArea extends BCAction { + + private IIcon icon; + + public ActionRobotWorkInArea() { + super("buildcraft:robot.work_in_area"); + } + + @Override + public IIcon getIcon() { + return icon; + } + + @Override + public String getDescription() { + return StringUtils.localize("gate.action.robot.work_in_area"); + } + + @Override + public void registerIcons(IIconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_in_area"); + } + + @Override + public void actionActivate(IGate gate, IActionParameter[] parameters) { + if (parameters[0] == null) { + return; + } + + ItemStack stack = ((ActionParameterItemStack) parameters[0]).getItemStackToDraw(); + + if (!(stack.getItem() instanceof ItemMapLocation)) { + return; + } + + 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); + } + } + } + + @Override + public int maxParameters() { + return 1; + } + + @Override + public IActionParameter createParameter(int index) { + return new ActionParameterItemStack(); + } +} diff --git a/common/buildcraft/silicon/statements/RobotsActionProvider.java b/common/buildcraft/silicon/statements/RobotsActionProvider.java index 79966352..16b4af6d 100755 --- a/common/buildcraft/silicon/statements/RobotsActionProvider.java +++ b/common/buildcraft/silicon/statements/RobotsActionProvider.java @@ -43,6 +43,7 @@ public class RobotsActionProvider implements IActionProvider { } result.add(BuildCraftSilicon.actionRobotGotoStation); + result.add(BuildCraftSilicon.actionRobotWorkInArea); for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { if (((TileGenericPipe) pipe).getTile(dir) instanceof IInventory) {