From 72d4ad5adaf47c0a0b9fcffc9ccf16ee0271222b Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Fri, 5 Jun 2015 21:47:20 -0300 Subject: [PATCH] add the ability to scroll through the parameters of the Forbid/Force robot --- buildcraft_resources/changelog/7.0.6 | 1 + common/buildcraft/BuildCraftRobotics.java | 4 +- .../core/crops/CropHandlerPlantable.java | 1 - .../statements/ActionStationForbidRobot.java | 3 +- .../statements/StatementParameterRobot.java | 70 +++++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 common/buildcraft/robotics/statements/StatementParameterRobot.java diff --git a/buildcraft_resources/changelog/7.0.6 b/buildcraft_resources/changelog/7.0.6 index f4affd64..23d19c91 100644 --- a/buildcraft_resources/changelog/7.0.6 +++ b/buildcraft_resources/changelog/7.0.6 @@ -8,6 +8,7 @@ Additions: * Container item support for the Stamping Table (asie) * Packagers only allow items relevant to the recipe to be inserted (asie) * Builders now light up when working (asie) +* Add the ability to scroll through the parameters of the Forbid/Force robot (hea3ven) Improvements: diff --git a/common/buildcraft/BuildCraftRobotics.java b/common/buildcraft/BuildCraftRobotics.java index cc119d7a..f85cec70 100644 --- a/common/buildcraft/BuildCraftRobotics.java +++ b/common/buildcraft/BuildCraftRobotics.java @@ -142,6 +142,7 @@ import buildcraft.robotics.statements.ActionStationRequestItems; import buildcraft.robotics.statements.ActionStationRequestItemsMachine; import buildcraft.robotics.statements.RobotsActionProvider; import buildcraft.robotics.statements.RobotsTriggerProvider; +import buildcraft.robotics.statements.StatementParameterRobot; import buildcraft.robotics.statements.TriggerRobotInStation; import buildcraft.robotics.statements.TriggerRobotLinked; import buildcraft.robotics.statements.TriggerRobotSleep; @@ -175,7 +176,7 @@ public class BuildCraftRobotics extends BuildCraftMod { public static IActionInternal actionStationAcceptFluids = new ActionStationAcceptFluids(); public static IActionInternal actionStationProvideFluids = new ActionStationProvideFluids(); public static IActionInternal actionStationForceRobot = new ActionStationForbidRobot(true); - public static IActionInternal actionStationForbidRobot = new ActionStationForbidRobot(true); + public static IActionInternal actionStationForbidRobot = new ActionStationForbidRobot(false); public static IActionInternal actionStationAcceptItems = new ActionStationAcceptItems(); public static IActionInternal actionStationMachineRequestItems = new ActionStationRequestItemsMachine(); @@ -248,6 +249,7 @@ public class BuildCraftRobotics extends BuildCraftMod { RedstoneBoardRegistry.instance.registerBoardType(new BCBoardNBT("buildcraft:boardRobotBuilder", "builder", BoardRobotBuilder.class, "yellow"), 512000); } + StatementManager.registerParameterClass(StatementParameterRobot.class); StatementManager.registerActionProvider(new RobotsActionProvider()); StatementManager.registerTriggerProvider(new RobotsTriggerProvider()); } diff --git a/common/buildcraft/core/crops/CropHandlerPlantable.java b/common/buildcraft/core/crops/CropHandlerPlantable.java index e1d61b0a..be39799e 100644 --- a/common/buildcraft/core/crops/CropHandlerPlantable.java +++ b/common/buildcraft/core/crops/CropHandlerPlantable.java @@ -5,7 +5,6 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockDoublePlant; -import net.minecraft.block.BlockFlower; import net.minecraft.block.BlockMelon; import net.minecraft.block.BlockMushroom; import net.minecraft.block.BlockTallGrass; diff --git a/common/buildcraft/robotics/statements/ActionStationForbidRobot.java b/common/buildcraft/robotics/statements/ActionStationForbidRobot.java index 7dd1249f..1bf74a31 100755 --- a/common/buildcraft/robotics/statements/ActionStationForbidRobot.java +++ b/common/buildcraft/robotics/statements/ActionStationForbidRobot.java @@ -16,7 +16,6 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; -import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.statements.StatementSlot; import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.statements.BCStatement; @@ -52,7 +51,7 @@ public class ActionStationForbidRobot extends BCStatement implements IActionInte @Override public IStatementParameter createParameter(int index) { - return new StatementParameterItemStack(); + return new StatementParameterRobot(); } public static boolean isForbidden(DockingStation station, EntityRobotBase robot) { diff --git a/common/buildcraft/robotics/statements/StatementParameterRobot.java b/common/buildcraft/robotics/statements/StatementParameterRobot.java new file mode 100644 index 00000000..d31e0c0d --- /dev/null +++ b/common/buildcraft/robotics/statements/StatementParameterRobot.java @@ -0,0 +1,70 @@ +package buildcraft.robotics.statements; + +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +import net.minecraft.item.ItemStack; + +import buildcraft.api.boards.RedstoneBoardNBT; +import buildcraft.api.boards.RedstoneBoardRegistry; +import buildcraft.api.boards.RedstoneBoardRobotNBT; +import buildcraft.api.statements.IStatement; +import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.StatementMouseClick; +import buildcraft.api.statements.StatementParameterItemStack; +import buildcraft.robotics.ItemRobot; + +public class StatementParameterRobot extends StatementParameterItemStack { + + @Override + public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, + StatementMouseClick mouse) { + if (stack != null) { + if (stack.getItem() instanceof ItemRobot) { + super.onClick(source, stmt, stack, mouse); + } else { + this.stack = null; + } + } else { + RedstoneBoardRobotNBT nextBoard = getNextBoard(mouse); + if (nextBoard != null) { + this.stack = ItemRobot.createRobotStack(nextBoard, 0); + } else { + this.stack = null; + } + } + } + + private RedstoneBoardRobotNBT getNextBoard(StatementMouseClick mouse) { + Collection> boards = RedstoneBoardRegistry.instance.getAllBoardNBTs(); + if (this.stack == null) { + if (mouse.getButton() == 0) { + return (RedstoneBoardRobotNBT) Iterables.getFirst(boards, null); + } else { + return (RedstoneBoardRobotNBT) Iterables.getLast(boards, null); + } + } else { + if (mouse.getButton() > 0) { + boards = Lists.reverse((List>) boards); + } + boolean found = false; + for (RedstoneBoardNBT boardNBT : boards) { + if (found) { + return (RedstoneBoardRobotNBT) boardNBT; + } else if (ItemRobot.getRobotNBT(this.stack) == boardNBT) { + found = true; + } + } + return null; + } + } + + @Override + public String getUniqueTag() { + return "buildcraft:robot"; + } + +}