From 59c22235bdb82ac40d87fb0cc15b730dfe850f2e Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Tue, 1 Jul 2014 08:52:01 +0200 Subject: [PATCH] fixed loading of picker robot, for #1921 --- .../core/robots/AIRobotFetchItem.java | 19 +++++++++++++++---- .../core/robots/boards/BoardRobotPicker.java | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/common/buildcraft/core/robots/AIRobotFetchItem.java b/common/buildcraft/core/robots/AIRobotFetchItem.java index 2c8b6e00..3cd1107a 100755 --- a/common/buildcraft/core/robots/AIRobotFetchItem.java +++ b/common/buildcraft/core/robots/AIRobotFetchItem.java @@ -23,13 +23,15 @@ import buildcraft.core.robots.boards.BoardRobotPicker; public class AIRobotFetchItem extends AIRobot { public EntityItem target; - public boolean noItemPicked = false; + public boolean itemPickupCancelled = false; private float maxRange; private IStackFilter stackFilter; private int pickTime = -1; private IBox box; + private int targetToLoad = -1; + public AIRobotFetchItem(EntityRobotBase iRobot) { super(iRobot); } @@ -45,7 +47,7 @@ public class AIRobotFetchItem extends AIRobot { @Override public void preempt(AIRobot ai) { if (target != null && target.isDead) { - noItemPicked = true; + itemPickupCancelled = true; terminate(); } } @@ -76,10 +78,20 @@ public class AIRobotFetchItem extends AIRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotGotoBlock) { + if (target == null) { + // This would happen after a load. As we reached the item + // location already, just consider that the item is not there + // anymore and allow user to try to find another one. + itemPickupCancelled = true; + terminate(); + return; + } + if (((AIRobotGotoBlock) ai).unreachable) { robot.unreachableEntityDetected(target); - noItemPicked = true; + itemPickupCancelled = true; terminate(); + return; } } } @@ -140,7 +152,6 @@ public class AIRobotFetchItem extends AIRobot { } else { // No item was found, terminate this AI - noItemPicked = true; terminate(); } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotPicker.java b/common/buildcraft/core/robots/boards/BoardRobotPicker.java index 7d52332e..6cab4960 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPicker.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPicker.java @@ -56,8 +56,9 @@ public class BoardRobotPicker extends RedstoneBoardRobot { if (ai instanceof AIRobotFetchItem) { AIRobotFetchItem fetching = (AIRobotFetchItem) ai; - if (!fetching.noItemPicked && fetching.target != null) { - // if we could get an item, let's try to get another one + if (fetching.itemPickupCancelled || fetching.target != null) { + // if we find an item - that may have been cancelled. + // let's try to get another one startDelegateAI(new AIRobotFetchItem(robot, range, ActionRobotFilter.getGateFilter(robot .getLinkedStation()), robot.getAreaToWork())); } else if (robot.containsItems()) { @@ -80,4 +81,18 @@ public class BoardRobotPicker extends RedstoneBoardRobot { public RedstoneBoardRobotNBT getNBTHandler() { return BoardRobotPickerNBT.instance; } + + @Override + public void writeSelfToNBT(NBTTagCompound nbt) { + super.writeSelfToNBT(nbt); + + nbt.setInteger("range", range); + } + + @Override + public void loadSelfFromNBT(NBTTagCompound nbt) { + super.loadSelfFromNBT(nbt); + + range = nbt.getInteger("range"); + } }