allow filtering robots by wearables, close #2811

This commit is contained in:
Adrian 2015-06-17 16:31:16 +02:00
parent 1761250322
commit 0bef77199b
2 changed files with 17 additions and 11 deletions

View file

@ -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,10 +73,18 @@ public class ActionStationForbidRobot extends BCStatement implements IActionInte
if (p != null) {
ItemStack stack = p.getItemStack();
if (stack != null && stack.getItem() instanceof ItemRobot) {
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;
}
}
}
}
}
}

View file

@ -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<RedstoneBoardNBT<?>> 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 {