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.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.BCLog; import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IZone; import buildcraft.api.core.IZone;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.events.RobotEvent; import buildcraft.api.events.RobotEvent;
@ -120,7 +121,7 @@ public class EntityRobot extends EntityRobotBase implements
public float itemActiveStage = 0; public float itemActiveStage = 0;
public long lastUpdateTime = 0; public long lastUpdateTime = 0;
private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(20); private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(10);
private boolean isMovingOutOfStuck; private boolean isMovingOutOfStuck;
private DockingStation currentDockingStation; private DockingStation currentDockingStation;
@ -354,7 +355,18 @@ public class EntityRobot extends EntityRobotBase implements
} }
if (expensiveVerificationsTracker.markTimeIfDelay(worldObj)) { 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) { if (collisions > 0) {
isMovingOutOfStuck = true; isMovingOutOfStuck = true;

View file

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

View file

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