From 0bef77199bd1d12e72f89b0b326af287b2ac9c05 Mon Sep 17 00:00:00 2001 From: Adrian Date: Wed, 17 Jun 2015 16:31:16 +0200 Subject: [PATCH] allow filtering robots by wearables, close #2811 --- .../statements/ActionStationForbidRobot.java | 16 +++++++++++++--- .../statements/StatementParameterRobot.java | 12 ++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/common/buildcraft/robotics/statements/ActionStationForbidRobot.java b/common/buildcraft/robotics/statements/ActionStationForbidRobot.java index 1bf74a31..53dd15d0 100755 --- a/common/buildcraft/robotics/statements/ActionStationForbidRobot.java +++ b/common/buildcraft/robotics/statements/ActionStationForbidRobot.java @@ -17,8 +17,10 @@ import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.StatementSlot; +import buildcraft.core.lib.inventory.StackHelper; import buildcraft.core.lib.utils.StringUtils; import buildcraft.core.statements.BCStatement; +import buildcraft.robotics.EntityRobot; import buildcraft.robotics.ItemRobot; public class ActionStationForbidRobot extends BCStatement implements IActionInternal { @@ -71,9 +73,17 @@ public class ActionStationForbidRobot extends BCStatement implements IActionInte if (p != null) { ItemStack stack = p.getItemStack(); - if (stack != null && stack.getItem() instanceof ItemRobot) { - if (ItemRobot.getRobotNBT(stack) == robot.getBoard().getNBTHandler()) { - return true; + if (stack != null) { + if (stack.getItem() instanceof ItemRobot) { + if (ItemRobot.getRobotNBT(stack) == robot.getBoard().getNBTHandler()) { + return true; + } + } else if (robot instanceof EntityRobot) { + for (ItemStack target : ((EntityRobot) robot).getWearables()) { + if (target != null && StackHelper.isMatchingItem(stack, target, true, true)) { + return true; + } + } } } } diff --git a/common/buildcraft/robotics/statements/StatementParameterRobot.java b/common/buildcraft/robotics/statements/StatementParameterRobot.java index d31e0c0d..33a4a24f 100644 --- a/common/buildcraft/robotics/statements/StatementParameterRobot.java +++ b/common/buildcraft/robotics/statements/StatementParameterRobot.java @@ -22,25 +22,21 @@ 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 { + if (stack == null && (this.stack == null || this.stack.getItem() instanceof ItemRobot)) { RedstoneBoardRobotNBT nextBoard = getNextBoard(mouse); if (nextBoard != null) { this.stack = ItemRobot.createRobotStack(nextBoard, 0); } else { this.stack = null; } + } else { + super.onClick(source, stmt, stack, mouse); } } private RedstoneBoardRobotNBT getNextBoard(StatementMouseClick mouse) { Collection> boards = RedstoneBoardRegistry.instance.getAllBoardNBTs(); - if (this.stack == null) { + if (this.stack == null || !(this.stack.getItem() instanceof ItemRobot)) { if (mouse.getButton() == 0) { return (RedstoneBoardRobotNBT) Iterables.getFirst(boards, null); } else {