Fixed invalid ship bounding box dimension when loading ship core
Note: this also fixes offline avatar not always spawning when restricted to ships
This commit is contained in:
parent
b40a16f673
commit
d813a58eba
3 changed files with 81 additions and 70 deletions
|
@ -437,6 +437,15 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
|
||||||
return Commons.removeFormatting( getStatusHeader().getUnformattedText() );
|
return Commons.removeFormatting( getStatusHeader().getUnformattedText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInternalStatus() {
|
||||||
|
return String.format("%s\n"
|
||||||
|
+ "NBT %s\n"
|
||||||
|
+ "isConstructed %s isFirstTick %s isDirty %s",
|
||||||
|
this,
|
||||||
|
writeToNBT(new NBTTagCompound()),
|
||||||
|
isConstructed, isFirstTick, isDirty );
|
||||||
|
}
|
||||||
|
|
||||||
// upgrade system
|
// upgrade system
|
||||||
public static class UpgradeSlot {
|
public static class UpgradeSlot {
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
// persistent properties
|
// persistent properties
|
||||||
private int front, right, up;
|
private int front, right, up;
|
||||||
private int back, left, down;
|
private int back, left, down;
|
||||||
private boolean isResized = true;
|
|
||||||
|
|
||||||
private int moveFront = 0;
|
private int moveFront = 0;
|
||||||
private int moveUp = 0;
|
private int moveUp = 0;
|
||||||
|
@ -54,23 +53,6 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
super.update();
|
|
||||||
|
|
||||||
if (world.isRemote) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update bounding box
|
|
||||||
if (isResized) {
|
|
||||||
if (WarpDriveConfig.LOGGING_JUMPBLOCKS) {
|
|
||||||
WarpDrive.logger.info(String.format("%s was resized, updating...", this));
|
|
||||||
}
|
|
||||||
updateAfterResize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(@Nonnull final NBTTagCompound tagCompound) {
|
public void readFromNBT(@Nonnull final NBTTagCompound tagCompound) {
|
||||||
super.readFromNBT(tagCompound);
|
super.readFromNBT(tagCompound);
|
||||||
|
@ -175,7 +157,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setFront(final int front) {
|
private void setFront(final int front) {
|
||||||
this.front = front;
|
this.front = front;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getRight() {
|
protected int getRight() {
|
||||||
|
@ -184,7 +166,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setRight(final int right) {
|
private void setRight(final int right) {
|
||||||
this.right = right;
|
this.right = right;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getUp() {
|
protected int getUp() {
|
||||||
|
@ -193,7 +175,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setUp(final int up) {
|
private void setUp(final int up) {
|
||||||
this.up = up;
|
this.up = up;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getBack() {
|
protected int getBack() {
|
||||||
|
@ -202,7 +184,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setBack(final int back) {
|
private void setBack(final int back) {
|
||||||
this.back = back;
|
this.back = back;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getLeft() {
|
protected int getLeft() {
|
||||||
|
@ -211,7 +193,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setLeft(final int left) {
|
private void setLeft(final int left) {
|
||||||
this.left = left;
|
this.left = left;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getDown() {
|
protected int getDown() {
|
||||||
|
@ -220,11 +202,7 @@ public abstract class TileEntityAbstractShipController extends TileEntityAbstrac
|
||||||
|
|
||||||
private void setDown(final int down) {
|
private void setDown(final int down) {
|
||||||
this.down = down;
|
this.down = down;
|
||||||
isResized = true;
|
markDirtyParameters();
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateAfterResize() {
|
|
||||||
isResized = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VectorI getMovement() {
|
protected VectorI getMovement() {
|
||||||
|
|
|
@ -624,7 +624,59 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doUpdateParameters(final boolean isDirty) {
|
protected void doUpdateParameters(final boolean isDirty) {
|
||||||
// no operation
|
// compute dimensions in game coordinates
|
||||||
|
final int old_minX = minX, old_maxX = maxX;
|
||||||
|
final int old_minY = minY, old_maxY = maxY;
|
||||||
|
final int old_minZ = minZ, old_maxZ = maxZ;
|
||||||
|
if (facing.getXOffset() == 1) {
|
||||||
|
minX = pos.getX() - getBack();
|
||||||
|
maxX = pos.getX() + getFront();
|
||||||
|
minZ = pos.getZ() - getLeft();
|
||||||
|
maxZ = pos.getZ() + getRight();
|
||||||
|
} else if (facing.getXOffset() == -1) {
|
||||||
|
minX = pos.getX() - getFront();
|
||||||
|
maxX = pos.getX() + getBack();
|
||||||
|
minZ = pos.getZ() - getRight();
|
||||||
|
maxZ = pos.getZ() + getLeft();
|
||||||
|
} else if (facing.getZOffset() == 1) {
|
||||||
|
minZ = pos.getZ() - getBack();
|
||||||
|
maxZ = pos.getZ() + getFront();
|
||||||
|
minX = pos.getX() - getRight();
|
||||||
|
maxX = pos.getX() + getLeft();
|
||||||
|
} else if (facing.getZOffset() == -1) {
|
||||||
|
minZ = pos.getZ() - getFront();
|
||||||
|
maxZ = pos.getZ() + getBack();
|
||||||
|
minX = pos.getX() - getLeft();
|
||||||
|
maxX = pos.getX() + getRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
minY = pos.getY() - getDown();
|
||||||
|
maxY = pos.getY() + getUp();
|
||||||
|
|
||||||
|
// recover in case of cache failure
|
||||||
|
boolean isDirty2 = false;
|
||||||
|
if ( minX != old_minX || maxX != old_maxX
|
||||||
|
|| minY != old_minY || maxY != old_maxY
|
||||||
|
|| minZ != old_minZ || maxZ != old_maxZ ) {
|
||||||
|
if (!isDirty) {
|
||||||
|
WarpDrive.logger.error(String.format("Dimensions changed but not dirty, please report this to mod author!\n%s",
|
||||||
|
getInternalStatus() ));
|
||||||
|
isDirty2 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update dimensions to client
|
||||||
|
if (!isDirty) {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// request new ship scan
|
||||||
|
if (isDirty || isDirty2) {
|
||||||
|
shipMass = 0;
|
||||||
|
shipVolume = 0;
|
||||||
|
cache_aabbArea = null;
|
||||||
|
timeLastShipScanDone = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makePlayersOnShipDrunk(final int tickDuration) {
|
private void makePlayersOnShipDrunk(final int tickDuration) {
|
||||||
|
@ -651,7 +703,7 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
|
||||||
WarpDrive.logger.warn(this + " No player given to summonOwnerOnDeploy()");
|
WarpDrive.logger.warn(this + " No player given to summonOwnerOnDeploy()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updateAfterResize();
|
doUpdateParameters(false);
|
||||||
if (!isAssemblyValid) {
|
if (!isAssemblyValid) {
|
||||||
Commons.addChatMessage(entityPlayerMP, new WarpDriveText(Commons.getStyleHeader(), !name.isEmpty() ? name : "ShipCore")
|
Commons.addChatMessage(entityPlayerMP, new WarpDriveText(Commons.getStyleHeader(), !name.isEmpty() ? name : "ShipCore")
|
||||||
.appendSibling(textValidityIssues));
|
.appendSibling(textValidityIssues));
|
||||||
|
@ -717,46 +769,6 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
|
||||||
Commons.moveEntity(player, world, new Vector3(blockPos.getX() + 0.5D, blockPos.getY(), blockPos.getZ() + 0.5D));
|
Commons.moveEntity(player, world, new Vector3(blockPos.getX() + 0.5D, blockPos.getY(), blockPos.getZ() + 0.5D));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateAfterResize() {
|
|
||||||
super.updateAfterResize();
|
|
||||||
shipMass = 0;
|
|
||||||
shipVolume = 0;
|
|
||||||
|
|
||||||
// compute dimensions in game coordinates
|
|
||||||
if (facing.getXOffset() == 1) {
|
|
||||||
minX = pos.getX() - getBack();
|
|
||||||
maxX = pos.getX() + getFront();
|
|
||||||
minZ = pos.getZ() - getLeft();
|
|
||||||
maxZ = pos.getZ() + getRight();
|
|
||||||
} else if (facing.getXOffset() == -1) {
|
|
||||||
minX = pos.getX() - getFront();
|
|
||||||
maxX = pos.getX() + getBack();
|
|
||||||
minZ = pos.getZ() - getRight();
|
|
||||||
maxZ = pos.getZ() + getLeft();
|
|
||||||
} else if (facing.getZOffset() == 1) {
|
|
||||||
minZ = pos.getZ() - getBack();
|
|
||||||
maxZ = pos.getZ() + getFront();
|
|
||||||
minX = pos.getX() - getRight();
|
|
||||||
maxX = pos.getX() + getLeft();
|
|
||||||
} else if (facing.getZOffset() == -1) {
|
|
||||||
minZ = pos.getZ() - getFront();
|
|
||||||
maxZ = pos.getZ() + getBack();
|
|
||||||
minX = pos.getX() - getLeft();
|
|
||||||
maxX = pos.getX() + getRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
minY = pos.getY() - getDown();
|
|
||||||
maxY = pos.getY() + getUp();
|
|
||||||
cache_aabbArea = null;
|
|
||||||
|
|
||||||
// update dimensions to client
|
|
||||||
markDirty();
|
|
||||||
|
|
||||||
// request new ship scan
|
|
||||||
timeLastShipScanDone = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validateShipMovementParameters(final WarpDriveText reason) {
|
private boolean validateShipMovementParameters(final WarpDriveText reason) {
|
||||||
shipMovementType = EnumShipMovementType.compute(world, pos.getX(), minY, maxY, pos.getZ(), commandCurrent, getMovement().y, reason);
|
shipMovementType = EnumShipMovementType.compute(world, pos.getX(), minY, maxY, pos.getZ(), commandCurrent, getMovement().y, reason);
|
||||||
if (shipMovementType == null) {
|
if (shipMovementType == null) {
|
||||||
|
@ -1101,6 +1113,18 @@ public class TileEntityShipCore extends TileEntityAbstractShipController impleme
|
||||||
.appendSibling(new TextComponentTranslation(showBoundingBox ? "tile.warpdrive.movement.ship_core.bounding_box.enabled" : "tile.warpdrive.movement.ship_core.bounding_box.disabled"));
|
.appendSibling(new TextComponentTranslation(showBoundingBox ? "tile.warpdrive.movement.ship_core.bounding_box.enabled" : "tile.warpdrive.movement.ship_core.bounding_box.disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInternalStatus() {
|
||||||
|
return String.format("%s\n"
|
||||||
|
+ "max %d %d %d min %d %d %d mass %d volume %d aabb %s\n"
|
||||||
|
+ "state %s command %s shipMovementType %s timeLastShipScanDone %d shipScanner %s shipMovementCosts %s\n"
|
||||||
|
+ "distanceSquared %d isCooldownReported %s isMotionSicknessApplied %s isSoundPlayed %s isWarmupReported %s randomWarmupAddition_ticks %d\n",
|
||||||
|
super.getInternalStatus(),
|
||||||
|
maxX, maxY, maxZ, minX, minY, minZ, shipMass, shipVolume, cache_aabbArea,
|
||||||
|
stateCurrent, commandCurrent, shipMovementType, timeLastShipScanDone, shipScanner, shipMovementCosts,
|
||||||
|
distanceSquared, isCooldownReported, isMotionSicknessApplied, isSoundPlayed, isWarmupReported, randomWarmupAddition_ticks );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean energy_canInput(final EnumFacing from) {
|
public boolean energy_canInput(final EnumFacing from) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue