feat: implement scaling between celestial bodies

This commit is contained in:
LordMZTE 2024-08-26 17:08:10 +02:00
parent e33a7d7402
commit 2a178bb9fa
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
6 changed files with 116 additions and 59 deletions

View file

@ -837,14 +837,14 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergy
globalPositionRemoteNew = globalPositionBeacon;
} else if (remoteLocationRequested instanceof VectorI) {
final VectorI vRequest = ((VectorI) remoteLocationRequested).clone();
VectorI vRequest = ((VectorI) remoteLocationRequested).clone();
if (vRequest.y < 0) {
final CelestialObject celestialObjectChild
= CelestialObjectManager.getClosestChild(worldObj, xCoord, zCoord);
if (celestialObjectChild == null) {
reasonJammed = "Not in orbit of a planet";
} else {
vRequest.translate(celestialObjectChild.getEntryOffset());
vRequest = celestialObjectChild.transformEntryVector(vRequest);
globalPositionRemoteNew = new GlobalPosition(
celestialObjectChild.dimensionId,
vRequest.x,
@ -853,7 +853,7 @@ public class TileEntityTransporterCore extends TileEntityAbstractEnergy
);
}
} else if (vRequest.y > 256) {
vRequest.translateBack(celestialObjectLocal.getEntryOffset());
vRequest = celestialObjectLocal.transformExitVector(vRequest);
globalPositionRemoteNew = new GlobalPosition(
celestialObjectLocal.parent.dimensionId,
vRequest.x,

View file

@ -112,7 +112,7 @@ public class CommandSpace extends CommandBase {
commandSender,
String.format(
"§c/space: player %s is in unknown dimension %d.\n§bTry "
+ "specifying an explicit target dimension instead.",
+ "specifying an explicit target dimension instead.",
entityPlayerMP.getCommandSenderName(),
entityPlayerMP.worldObj.provider.dimensionId
)
@ -135,8 +135,8 @@ public class CommandSpace extends CommandBase {
commandSender,
String.format(
"§c/space: player %s can't go to %s.\n§cThis is a "
+ "virtual celestial object.\n§bTry specifying an "
+ "explicit target dimension instead.",
+ "virtual celestial object.\n§bTry specifying an "
+ "explicit target dimension instead.",
entityPlayerMP.getCommandSenderName(),
celestialObjectChild.getDisplayName()
)
@ -144,10 +144,12 @@ public class CommandSpace extends CommandBase {
continue;
} else {
dimensionIdTarget = celestialObjectChild.dimensionId;
final VectorI vEntry = celestialObjectChild.getEntryOffset();
xTarget += vEntry.x;
yTarget += vEntry.y;
zTarget += vEntry.z;
final VectorI vEntry = celestialObjectChild.transformEntryVector(
new VectorI(xTarget, yTarget, zTarget)
);
xTarget = vEntry.x;
yTarget = vEntry.y;
zTarget = vEntry.z;
}
} else {
// on a planet => move to space
@ -157,10 +159,12 @@ public class CommandSpace extends CommandBase {
} else {
dimensionIdTarget = celestialObjectCurrent.parent.dimensionId;
final VectorI vEntry = celestialObjectCurrent.getEntryOffset();
xTarget -= vEntry.x;
yTarget -= vEntry.y;
zTarget -= vEntry.z;
final VectorI vEntry = celestialObjectCurrent.transformExitVector(
new VectorI(xTarget, yTarget, zTarget)
);
xTarget = vEntry.x;
yTarget = vEntry.y;
zTarget = vEntry.z;
}
}
@ -170,10 +174,12 @@ public class CommandSpace extends CommandBase {
&& celestialObjectCurrent.parent != null
&& celestialObjectCurrent.parent.dimensionId
== dimensionIdTarget) { // moving to parent explicitly
final VectorI vEntry = celestialObjectCurrent.getEntryOffset();
xTarget -= vEntry.x;
yTarget -= vEntry.y;
zTarget -= vEntry.z;
final VectorI vEntry = celestialObjectCurrent.transformExitVector(
new VectorI(xTarget, yTarget, zTarget)
);
xTarget = vEntry.x;
yTarget = vEntry.y;
zTarget = vEntry.z;
} else {
final CelestialObject celestialObjectChild
= CelestialObjectManager.getClosestChild(
@ -184,10 +190,12 @@ public class CommandSpace extends CommandBase {
if (celestialObjectChild != null
&& celestialObjectChild.dimensionId
== dimensionIdTarget) { // moving to child explicitly
final VectorI vEntry = celestialObjectChild.getEntryOffset();
xTarget += vEntry.x;
yTarget += vEntry.y;
zTarget += vEntry.z;
final VectorI vEntry = celestialObjectChild.transformEntryVector(
new VectorI(xTarget, yTarget, zTarget)
);
xTarget = vEntry.x;
yTarget = vEntry.y;
zTarget = vEntry.z;
}
}
}
@ -270,6 +278,6 @@ public class CommandSpace extends CommandBase {
@Override
public String getCommandUsage(final ICommandSender commandSender) {
return "/space (<playerName>) "
+ "([overworld|nether|end|theend|space|hyper|hyperspace|<dimensionId>])";
+ "([overworld|nether|end|theend|space|hyper|hyperspace|<dimensionId>])";
}
}

View file

@ -15,6 +15,8 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
import javax.vecmath.Matrix3d;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
@ -302,7 +304,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
if (listElements.size() > 1) {
throw new InvalidXmlException(String.format(
"Celestial object %s dimension can only have up to one provider "
+ "element",
+ "element",
id
));
}
@ -486,8 +488,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
} catch (final Exception exception) {
WarpDrive.logger.error(
"Invalid gravity value, expecting none, legacySpace, legacyHyperspace, "
+ "normal or a positive double. Found: "
+ stringGravity
+ "normal or a positive double. Found: " + stringGravity
);
exception.printStackTrace();
return 1.0D;
@ -605,6 +606,39 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
);
}
public VectorI transformEntryVector(VectorI vec) {
vec = vec.clone().translate(new VectorI(
this.dimensionCenterX - this.parentCenterX,
0,
this.dimensionCenterZ - this.parentCenterZ
));
return new VectorI(
this.borderRadiusX * vec.x / this.orbitRadiusX,
vec.y,
this.borderRadiusZ * vec.z / this.orbitRadiusZ
);
}
public VectorI transformExitVector(VectorI vec) {
new VectorI(
this.orbitRadiusX * vec.x / this.borderRadiusX,
vec.y,
this.orbitRadiusZ * vec.z / this.borderRadiusZ
)
.translateBack(new VectorI(
this.dimensionCenterX - this.parentCenterX,
0,
this.dimensionCenterZ - this.parentCenterZ
));
return new VectorI(
this.orbitRadiusX * vec.x / this.borderRadiusX,
vec.y,
this.orbitRadiusZ * vec.z / this.borderRadiusZ
);
}
@Override
public AxisAlignedBB getWorldBorderArea() {
return AxisAlignedBB.getBoundingBox(
@ -904,7 +938,7 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
} else {
return String.format(
"CelestialObject %s [Dimension %d @ %d %d Border(%d %d) %s provider %s "
+ "gravity %.3f isBreathable %s]",
+ "gravity %.3f isBreathable %s]",
id,
dimensionId,
dimensionCenterX,
@ -1091,4 +1125,4 @@ public class CelestialObject implements Cloneable, IStringSerializable, ICelesti
return tagCompound;
}
}
}
}

View file

@ -50,7 +50,7 @@ public class StarMapRegistry {
if (!Commons.isSafeThread()) {
WarpDrive.logger.error(String.format(
"Non-threadsafe call to StarMapRegistry:updateInRegistry outside main "
+ "thread, for %s",
+ "thread, for %s",
tileEntity
));
}
@ -535,7 +535,7 @@ public class StarMapRegistry {
if (!isExceptionReported) {
WarpDrive.logger.info(String.format(
"Unable to check non-loaded chunks for star map "
+ "entry %s",
+ "entry %s",
registryItem
));
exception.printStackTrace();

View file

@ -424,8 +424,8 @@ public class JumpSequencer extends AbstractSequencer {
if (chunkCount > sourceWorldTicket.getMaxChunkListDepth()) {
reason.append(String.format(
"Ship is extending over %d chunks in source world. Max is "
+ "currently set to %d in config/forgeChunkLoading.cfg. "
+ "Aborting.",
+ "currently set to %d in config/forgeChunkLoading.cfg. "
+ "Aborting.",
(maxX - minX + 1) * (maxZ - minZ + 1),
sourceWorldTicket.getMaxChunkListDepth()
));
@ -473,8 +473,8 @@ public class JumpSequencer extends AbstractSequencer {
if (chunkCount > targetWorldTicket.getMaxChunkListDepth()) {
reason.append(String.format(
"Ship is extending over %d chunks in target world. Max is "
+ "currently set to %d in config/forgeChunkLoading.cfg. "
+ "Aborting.",
+ "currently set to %d in config/forgeChunkLoading.cfg. "
+ "Aborting.",
(maxX - minX + 1) * (maxZ - minZ + 1),
targetWorldTicket.getMaxChunkListDepth()
));
@ -686,7 +686,7 @@ public class JumpSequencer extends AbstractSequencer {
LocalProfiler.stop();
final String msg = String.format(
"Ship is too big for a planet (max is %d blocks while ship is %d "
+ "blocks)",
+ "blocks)",
WarpDriveConfig.SHIP_VOLUME_MAX_ON_PLANET_SURFACE,
ship.actualMass
);
@ -802,9 +802,8 @@ public class JumpSequencer extends AbstractSequencer {
// cancel jump
final String msg;
if (firstAdjustmentReason == null || firstAdjustmentReason.isEmpty()) {
msg
= "Source and target areas are overlapping, jump aborted! Try "
+ "increasing jump distance...";
msg = "Source and target areas are overlapping, jump aborted! Try "
+ "increasing jump distance...";
} else {
msg = firstAdjustmentReason
+ "\nNot enough space after adjustment, jump aborted!";
@ -928,7 +927,8 @@ public class JumpSequencer extends AbstractSequencer {
// case GATE_ACTIVATING:
// ship.messageToAllPlayersOnShip(String.format("Jumping to coordinates
// (%d %d %d)!", destX, destY, destZ)); break;
// (%d %d %d)!", destX,
// destY, destZ)); break;
case INSTANTIATE:
case RESTORE:
@ -993,7 +993,7 @@ public class JumpSequencer extends AbstractSequencer {
if (celestialObject == null) {
reason.append(String.format(
"Unable to reach space from this location!\nThere's no celestial "
+ "object defined for current dimension %s (%d).",
+ "object defined for current dimension %s (%d).",
sourceWorld.provider.getDimensionName(),
sourceWorld.provider.dimensionId
));
@ -1009,7 +1009,7 @@ public class JumpSequencer extends AbstractSequencer {
reason.append(String.format(
"Ship is outside any solar system, unable to reach space!\n"
+ "Closest transition area is ~%d m away (%d %d %d) to (%d "
+ "%d %d).",
+ "%d %d).",
(int) Math.sqrt(distanceSquared),
(int) axisAlignedBB.minX,
(int) axisAlignedBB.minY,
@ -1035,7 +1035,10 @@ public class JumpSequencer extends AbstractSequencer {
}
// update movement vector
final VectorI vEntry = celestialObject.getEntryOffset();
VectorI shipvec
= new VectorI(this.ship.coreX, this.ship.coreY, this.ship.coreZ);
final VectorI vEntry
= celestialObject.transformEntryVector(shipvec).subtract(shipvec);
moveX = vEntry.x;
moveZ = vEntry.z;
} break;
@ -1045,7 +1048,7 @@ public class JumpSequencer extends AbstractSequencer {
if (celestialObjectSource.parent == null) {
reason.append(String.format(
"Unable to reach hyperspace!\nThere's no parent defined for "
+ "current dimension %s (%d).",
+ "current dimension %s (%d).",
sourceWorld.provider.getDimensionName(),
sourceWorld.provider.dimensionId
));
@ -1068,9 +1071,13 @@ public class JumpSequencer extends AbstractSequencer {
}
// update movement vector
final VectorI vEntry = celestialObjectSource.getEntryOffset();
moveX = -vEntry.x;
moveZ = -vEntry.z;
VectorI shipvec
= new VectorI(this.ship.coreX, this.ship.coreY, this.ship.coreZ);
final VectorI vEntry
= celestialObjectSource.transformExitVector(shipvec).subtract(shipvec
);
moveX = vEntry.x;
moveZ = vEntry.z;
} break;
case PLANET_TAKEOFF: {
@ -1078,7 +1085,7 @@ public class JumpSequencer extends AbstractSequencer {
if (celestialObjectSource.parent == null) {
reason.append(String.format(
"Unable to take off!\nThere's no parent defined for current "
+ "dimension %s (%d).",
+ "dimension %s (%d).",
sourceWorld.provider.getDimensionName(),
sourceWorld.provider.dimensionId
));
@ -1096,7 +1103,7 @@ public class JumpSequencer extends AbstractSequencer {
reason.append(String.format(
"Ship is outside planet border, unable to reach space!\n"
+ "Closest transition area is ~%d m away (%d %d %d) to (%d "
+ "%d %d).",
+ "%d %d).",
(int) Math.sqrt(distanceSquared),
(int) axisAlignedBB.minX,
(int) axisAlignedBB.minY,
@ -1122,9 +1129,13 @@ public class JumpSequencer extends AbstractSequencer {
}
// update movement vector
final VectorI vEntry = celestialObjectSource.getEntryOffset();
moveX = -vEntry.x;
moveZ = -vEntry.z;
VectorI shipvec
= new VectorI(this.ship.coreX, this.ship.coreY, this.ship.coreZ);
final VectorI vEntry
= celestialObjectSource.transformExitVector(shipvec).subtract(shipvec
);
moveX = vEntry.x;
moveZ = vEntry.z;
} break;
case PLANET_LANDING: {
@ -1164,7 +1175,8 @@ public class JumpSequencer extends AbstractSequencer {
if (celestialObject.isVirtual()) {
reason.append(String.format(
"Sorry, we can't go to %s. This is a virtual celestial object. "
+ "It's either a decorative planet or a server misconfiguration",
+ "It's either a decorative planet or a server "
+ "misconfiguration",
celestialObject.getDisplayName()
));
return false;
@ -1177,14 +1189,17 @@ public class JumpSequencer extends AbstractSequencer {
if (targetWorld == null) {
reason.append(String.format(
"Sorry, we can't land here. Dimension %d isn't defined. It might "
+ "be a decorative planet or a server misconfiguration",
+ "be a decorative planet or a server misconfiguration",
celestialObject.dimensionId
));
return false;
}
// update movement vector
final VectorI vEntry = celestialObject.getEntryOffset();
VectorI shipvec
= new VectorI(this.ship.coreX, this.ship.coreY, this.ship.coreZ);
final VectorI vEntry
= celestialObject.transformEntryVector(shipvec).subtract(shipvec);
moveX = vEntry.x;
moveZ = vEntry.z;
} break;
@ -1668,7 +1683,7 @@ public class JumpSequencer extends AbstractSequencer {
if (WarpDriveConfig.LOGGING_JUMP && countBefore != countAfter) {
WarpDrive.logger.info(String.format(
"Removing TE duplicates: tileEntities in target world after jump, "
+ "cleanup %d -> %d",
+ "cleanup %d -> %d",
countBefore,
countAfter
));
@ -2163,7 +2178,7 @@ public class JumpSequencer extends AbstractSequencer {
if (WarpDriveConfig.LOGGING_JUMP) {
WarpDrive.logger.warn(String.format(
"Removing TE duplicates: detected duplicate in %s @ %d %d "
+ "%d: %s vs %s",
+ "%d: %s vs %s",
o1.getWorldObj().provider.getDimensionName(),
o1.xCoord,
o1.yCoord,

View file

@ -196,10 +196,10 @@ public class LivingHandler {
entityLivingBase
));
} else {
final VectorI vEntry = celestialObjectChild.getEntryOffset();
final int xTarget = x + vEntry.x;
final VectorI vEntry = celestialObjectChild.transformEntryVector(new VectorI(x, 0, z));
final int xTarget = vEntry.x;
final int yTarget = worldTarget.getActualHeight() + 5;
final int zTarget = z + vEntry.z;
final int zTarget = vEntry.z;
if (entityLivingBase instanceof EntityPlayerMP) {
final EntityPlayerMP player = (EntityPlayerMP) entityLivingBase;