Transition planes

Implemented transition planes (only overworld was supported so far)
Fixed atmosphere entry when center in space wasn't on a diagonal
This commit is contained in:
LemADEC 2014-09-22 04:00:06 +02:00
parent 9e6987c842
commit b7526de4e8
2 changed files with 92 additions and 31 deletions

View file

@ -334,35 +334,79 @@ public class EntityJump extends Entity
betweenWorlds = fromSpace || toSpace || isHyperspaceJump;
moveX = moveY = moveZ = 0;
TransitionPlane overworld = WarpDriveConfig.G_TRANSITIONPLANES[0];
if (toSpace) {
if (worldObj.provider.dimensionId == overworld.dimensionId) {
if (!overworld.isValidToSpace(new Vector3(this))) {// invalid transition, cancel transition
LocalProfiler.stop();
String msg = "Ship is outside worldborder, unable to transition to space!";
messageToAllPlayersOnShip(msg);
killEntity(msg);
return;
}
moveX = overworld.spaceCenterX - overworld.dimensionCenterX;
moveZ = overworld.spaceCenterZ - overworld.dimensionCenterZ;
} else {
moveX = 0;
moveZ = 0;
Boolean planeFound = false;
Boolean planeValid = false;
int closestPlaneDistance = Integer.MAX_VALUE;
TransitionPlane closestTransitionPlane = null;
for (int iPlane = 0; (!planeValid) && iPlane < WarpDriveConfig.G_TRANSITIONPLANES.length; iPlane++) {
TransitionPlane transitionPlane = WarpDriveConfig.G_TRANSITIONPLANES[iPlane];
if (worldObj.provider.dimensionId == transitionPlane.dimensionId) {
planeFound = true;
int planeDistance = transitionPlane.isValidToSpace(new Vector3(this));
if (planeDistance == 0) {
planeValid = true;
moveX = transitionPlane.spaceCenterX - transitionPlane.dimensionCenterX;
moveZ = transitionPlane.spaceCenterZ - transitionPlane.dimensionCenterZ;
targetWorld = DimensionManager.getWorld(WarpDriveConfig.G_SPACE_DIMENSION_ID);
} else if (closestPlaneDistance > planeDistance) {
closestPlaneDistance = planeDistance;
closestTransitionPlane = transitionPlane;
}
}
}
targetWorld = DimensionManager.getWorld(WarpDriveConfig.G_SPACE_DIMENSION_ID);
} else if (fromSpace) {
if (!overworld.isValidFromSpace(new Vector3(this))) {// invalid transition, cancel transition
if (!planeFound) {
LocalProfiler.stop();
String msg = "Ship is outside worldborder, unable to transition from space!";
String msg = "Unable to reach space!\nThere's no valid transition plane for current dimension " + worldObj.provider.getDimensionName() + " (" + worldObj.provider.dimensionId + ")";
messageToAllPlayersOnShip(msg);
killEntity(msg);
return;
}
if (!planeValid) {
LocalProfiler.stop();
@SuppressWarnings("null")
String msg = "Ship is outside border, unable to reach space!\nClosest transition plane is ~" + closestPlaneDistance + " m away ("
+ (closestTransitionPlane.dimensionCenterX - closestTransitionPlane.borderSizeX) + ", 250,"
+ (closestTransitionPlane.dimensionCenterZ - closestTransitionPlane.borderSizeZ) + ") to ("
+ (closestTransitionPlane.dimensionCenterX + closestTransitionPlane.borderSizeX) + ", 255,"
+ (closestTransitionPlane.dimensionCenterZ + closestTransitionPlane.borderSizeZ) + ")";
messageToAllPlayersOnShip(msg);
killEntity(msg);
return;
}
} else if (fromSpace) {
Boolean planeFound = false;
int closestPlaneDistance = Integer.MAX_VALUE;
TransitionPlane closestTransitionPlane = null;
for (int iPlane = 0; (!planeFound) && iPlane < WarpDriveConfig.G_TRANSITIONPLANES.length; iPlane++) {
TransitionPlane transitionPlane = WarpDriveConfig.G_TRANSITIONPLANES[iPlane];
int planeDistance = transitionPlane.isValidFromSpace(new Vector3(this));
if (planeDistance == 0) {
planeFound = true;
moveX = transitionPlane.dimensionCenterX - transitionPlane.spaceCenterX;
moveZ = transitionPlane.dimensionCenterZ - transitionPlane.spaceCenterZ;
targetWorld = DimensionManager.getWorld(transitionPlane.dimensionId);
} else if (closestPlaneDistance > planeDistance) {
closestPlaneDistance = planeDistance;
closestTransitionPlane = transitionPlane;
}
}
if (!planeFound) {
LocalProfiler.stop();
String msg = "";
if (closestTransitionPlane == null) {
msg = "No transition plane defined, unable to enter atmosphere!";
} else {
msg = "No planet in range, unable to enter atmosphere!\nClosest transition plane is " + closestPlaneDistance + " m away ("
+ (closestTransitionPlane.dimensionCenterX - closestTransitionPlane.borderSizeX) + ", 250,"
+ (closestTransitionPlane.dimensionCenterZ - closestTransitionPlane.borderSizeZ) + ") to ("
+ (closestTransitionPlane.dimensionCenterX + closestTransitionPlane.borderSizeX) + ", 255,"
+ (closestTransitionPlane.dimensionCenterZ + closestTransitionPlane.borderSizeZ) + ")";
}
messageToAllPlayersOnShip(msg);
killEntity(msg);
return;
}
moveX = overworld.dimensionCenterX - overworld.spaceCenterX;
moveZ = overworld.dimensionCenterZ - overworld.spaceCenterZ;
targetWorld = DimensionManager.getWorld(0);
} else if (isHyperspaceJump && isInHyperSpace) {
targetWorld = DimensionManager.getWorld(WarpDriveConfig.G_SPACE_DIMENSION_ID);
} else if (isHyperspaceJump && isInSpace) {

View file

@ -35,7 +35,7 @@ public class TransitionPlane implements Cloneable
}
/**
* Makes a new copy of this Vector. Prevents variable referencing problems.
* Makes a new copy of this TransitionPlane. Prevents variable referencing problems.
*/
@Override
public TransitionPlane clone() {
@ -43,18 +43,35 @@ public class TransitionPlane implements Cloneable
}
/**
* Compute transition.
* Check if current coordinates allow to take off from this dimension to reach space.
* It's up to caller to verify if this transition plane match current dimension.
*
* @param world
* @return
* @param current position in the dimension
* @return distance to transition borders, 0 if take off is possible
*/
public boolean isValidToSpace(Vector3 currentPosition) {
return ( (Math.abs(currentPosition.x - dimensionCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - dimensionCenterZ) <= borderSizeZ) );
public int isValidToSpace(Vector3 currentPosition) {
if ( (Math.abs(currentPosition.x - dimensionCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - dimensionCenterZ) <= borderSizeZ) ) {
return 0;
}
return (int) Math.sqrt(
Math.pow(Math.max(0D, Math.abs(currentPosition.x - dimensionCenterX) - borderSizeX), 2.0D)
+ Math.pow(Math.max(0D, Math.abs(currentPosition.z - dimensionCenterZ) - borderSizeZ), 2.0D) );
}
public boolean isValidFromSpace(Vector3 currentPosition) {
return ( (Math.abs(currentPosition.x - spaceCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - spaceCenterX) <= borderSizeZ) );
/**
* Check if current space coordinates allow to enter this dimension atmosphere from space.
* It's up to caller to verify if we're actually in space.
*
* @param current position in space
* @return distance to transition borders, 0 if entry is possible
*/
public int isValidFromSpace(Vector3 currentPosition) {
if ( (Math.abs(currentPosition.x - spaceCenterX) <= borderSizeX) && (Math.abs(currentPosition.z - spaceCenterZ) <= borderSizeZ) ) {
return 0;
}
return (int) Math.sqrt(
Math.pow(Math.max(0D, Math.abs(currentPosition.x - spaceCenterX) - borderSizeX), 2.0D)
+ Math.pow(Math.max(0D, Math.abs(currentPosition.z - spaceCenterZ) - borderSizeZ), 2.0D) );
}
public void readFromNBT(NBTTagCompound tag) {