try to improve unstucking logic, fix #3075

This commit is contained in:
asiekierka 2015-10-15 17:27:26 +02:00
parent fefead843b
commit b7cf71a7dd
4 changed files with 31 additions and 10 deletions

View file

@ -0,0 +1,4 @@
Bugs fixed:
* [#3075] Rare crash in AIRobotGoAndLinkToDock (asie)
* Robot unstucking issues (asie)

View file

@ -68,6 +68,7 @@ import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IZone;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.events.RobotEvent;
@ -120,7 +121,7 @@ public class EntityRobot extends EntityRobotBase implements
public float itemActiveStage = 0;
public long lastUpdateTime = 0;
private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(20);
private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(10);
private boolean isMovingOutOfStuck;
private DockingStation currentDockingStation;
@ -354,7 +355,18 @@ public class EntityRobot extends EntityRobotBase implements
}
if (expensiveVerificationsTracker.markTimeIfDelay(worldObj)) {
int collisions = worldObj.getCollidingBoundingBoxes(this, getBoundingBox()).size();
int collisions = 0;
int bx = (int) Math.floor(posX);
int by = (int) Math.floor(posY);
int bz = (int) Math.floor(posZ);
if (!BuildCraftAPI.isSoftBlock(worldObj, bx, by, bz)) {
List clist = new ArrayList();
worldObj.getBlock(bx, by, bz).addCollisionBoxesToList(worldObj, bx, by, bz, getBoundingBox(), clist, this);
collisions = clist.size();
}
if (collisions > 0) {
isMovingOutOfStuck = true;

View file

@ -76,10 +76,12 @@ public class AIRobotGoAndLinkToDock extends AIRobot {
public void writeSelfToNBT(NBTTagCompound nbt) {
super.writeSelfToNBT(nbt);
NBTTagCompound indexNBT = new NBTTagCompound();
station.index().writeTo(indexNBT);
nbt.setTag("stationIndex", indexNBT);
nbt.setByte("stationSide", (byte) station.side().ordinal());
if (station != null && station.index() != null) {
NBTTagCompound indexNBT = new NBTTagCompound();
station.index().writeTo(indexNBT);
nbt.setTag("stationIndex", indexNBT);
nbt.setByte("stationSide", (byte) station.side().ordinal());
}
}
@Override

View file

@ -31,20 +31,23 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
targettedItems.clear();
}
@Override
public void update() {
private void fetchNewItem() {
startDelegateAI(new AIRobotFetchItem(robot, 250, ActionRobotFilter.getGateFilter(robot
.getLinkedStation()), robot.getZoneToWork()));
}
@Override
public void update() {
fetchNewItem();
}
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotFetchItem) {
if (ai.success()) {
// if we find an item - that may have been cancelled.
// let's try to get another one
startDelegateAI(new AIRobotFetchItem(robot, 250, ActionRobotFilter.getGateFilter(robot
.getLinkedStation()), robot.getZoneToWork()));
fetchNewItem();
} else if (robot.containsItems()) {
startDelegateAI(new AIRobotGotoStationAndUnload(robot));
} else {