Skip to content
This repository was archived by the owner on Aug 31, 2026. It is now read-only.

Commit 6680fd7

Browse files
committed
refactor: ask whether a world IS hyperspace, not which id it has
- replace the side-aware id accessor with a predicate - fold the null check and the comparison into that one question - drop the client-side delegate, the sky asks the world directly - keep the raw id for the one caller that sends it on the wire
1 parent 6653bb9 commit 6680fd7

5 files changed

Lines changed: 26 additions & 47 deletions

File tree

‎src/main/java/zmaster587/advancedRocketry/client/render/planet/BoundarySky.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void render(float partialTicks, WorldClient world, Minecraft mc) {
148148
// the jump phase from — and not the seat the viewer happens to be on. Keyed on the seat, a
149149
// crew member who stood up mid-flight got a cell's descent ring in the transit corridor and
150150
// no corridor at all, which reads as the flight having stopped.
151-
if (HyperspaceTunnel.isHyperspace(world)) {
151+
if (zmaster587.advancedRocketry.space.HyperspaceWorld.isHyperspace(world)) {
152152
HyperspaceTunnel.render(partialTicks, world);
153153
GlStateManager.enableTexture2D();
154154
restoreState();

‎src/main/java/zmaster587/advancedRocketry/client/render/planet/HyperspaceTunnel.java‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,6 @@ private HyperspaceTunnel() {
5252
*/
5353
public static volatile long framesDrawn = 0L;
5454

55-
/**
56-
* Whether {@code world} is hyperspace, i.e. whether this frame is being drawn during a jump.
57-
*
58-
* <p><b>The corridor is a property of the WORLD, not of what the viewer is sitting on.</b> It
59-
* used to be read off the jump phase published on the seat dummy, which answers 0 for anyone
60-
* riding nothing — so a crew member who stood up mid-flight lost the corridor, and with it the
61-
* only thing in hyperspace that says the ship is moving (no bodies are synced there and the
62-
* descent ring is suppressed). An empty, motionless sky reads as the flight having stopped. The
63-
* posture was never the question; being in hyperspace is, and that is the same primary fact the
64-
* server derives the phase from.</p>
65-
*
66-
* <p>The id comes from {@code PacketSlotDimSync}: a remote client cannot derive it, since
67-
* hyperspace is registered server-side. Until it arrives {@link HyperspaceWorld#dimId()} is
68-
* {@link Integer#MIN_VALUE}, which no real dimension id can equal, so an unsynced client draws
69-
* no corridor rather than drawing one everywhere.</p>
70-
*/
71-
public static boolean isHyperspace(net.minecraft.world.World world) {
72-
int hyper = HyperspaceWorld.dimIdFor(world);
73-
return world != null && hyper != Integer.MIN_VALUE
74-
&& world.provider.getDimension() == hyper;
75-
}
76-
7755
/**
7856
* Which way the SHIP is pointing, as {@code {yaw, pitch}} in degrees — the corridor's axis.
7957
*

‎src/main/java/zmaster587/advancedRocketry/space/HyperspaceWorld.java‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ public static WorldServer getIfLoaded() {
104104
* {@link #register()} minted, so a caller reasoning about worlds this JVM is simulating is
105105
* reading the fact rather than a report of one.
106106
*
107-
* <p>Client-side code must not call this. Both ids live in JVM-global statics, so a client that
108-
* hosted a single-player world earlier in the same launch still has one — and it names a world
109-
* that is gone, not the server it is now connected to. Use {@link #dimIdFor(World)}, which picks
110-
* by the side the world is on rather than by the caller's belief about where it runs.</p>
107+
* <p>It exists for the one caller that needs the NUMBER rather than the answer: the slot-dim sync
108+
* packet, which sends it. Anything asking whether a world IS hyperspace wants
109+
* {@link #isHyperspace(World)} instead — both ids live in JVM-global statics, and a client that
110+
* hosted a single-player world earlier in the same launch still has one of them, naming a world
111+
* that is gone rather than the server it is now connected to.</p>
111112
*/
112113
public static int dimId() {
113114
return dimId;
@@ -126,20 +127,23 @@ public static int dimId() {
126127
private static int adoptedDimId = Integer.MIN_VALUE;
127128

128129
/**
129-
* Which dimension hyperspace is, asked for the side {@code world} is on: the local registration
130-
* on a server, the id the connected server reported on a client. {@link Integer#MIN_VALUE} when
131-
* that side does not know, which no real dimension id equals - so an unsynced client answers
132-
* "nowhere" rather than "everywhere".
130+
* Is {@code world} hyperspace?
133131
*
134-
* <p>The side is a property of the world, not something a call site should be trusted to know
135-
* about itself: a tile entity, a world provider and a sky renderer all run on both, and each of
136-
* them holds the world it is asking about.</p>
132+
* <p>Asked as one question rather than handed out as an id, because the id alone is not an
133+
* answer: which dimension hyperspace is depends on the SIDE, and the side is a property of the
134+
* world, not something a call site should be trusted to know about itself — a tile entity, a
135+
* world provider and a sky renderer all run on both. A server compares against the registration
136+
* it made; a client against what its server reported, and against nothing else.</p>
137+
*
138+
* <p>False whenever this side does not know yet: an unsynced client says "not here" everywhere
139+
* rather than picking a dimension at random. {@code null} is not hyperspace either.</p>
137140
*/
138-
public static int dimIdFor(World world) {
141+
public static boolean isHyperspace(World world) {
139142
if (world == null) {
140-
return dimId;
143+
return false;
141144
}
142-
return world.isRemote ? adoptedDimId : dimId;
145+
int hyper = world.isRemote ? adoptedDimId : dimId;
146+
return hyper != Integer.MIN_VALUE && world.provider.getDimension() == hyper;
143147
}
144148

145149
/** Learn the server's hyperspace dim id. {@link Integer#MIN_VALUE} means "none yet" — ignored. */

‎src/main/java/zmaster587/advancedRocketry/tile/TileAdvancedFlightComputer.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ public void update() {
335335
// The single source of this gate is the ship's presence in the shared hyperspace world:
336336
// ships exist there exactly while parked mid-transit. Deliberate-exit and the exit-warning
337337
// channel stay OUTSIDE this gate when they land — they are the survival path mid-transit.
338-
int hyperDim = zmaster587.advancedRocketry.space.HyperspaceWorld.dimIdFor(world);
339-
if (hyperDim != Integer.MIN_VALUE && world.provider.getDimension() == hyperDim) {
338+
if (zmaster587.advancedRocketry.space.HyperspaceWorld.isHyperspace(world)) {
340339
commandedVelocity = null;
341340
commandedAngVel = null;
342341
targetAttitude = null;
@@ -709,9 +708,7 @@ public zmaster587.advancedRocketry.space.ShipTransitManager.Phase getHudTransitP
709708
// Asking the transit registry first would make the readout depend on the ship being findable
710709
// under the id the registry happens to use, and a pilot who is demonstrably in hyperspace
711710
// would then be told nothing at all.
712-
int hyperDim = zmaster587.advancedRocketry.space.HyperspaceWorld.dimIdFor(world);
713-
if (world == null || hyperDim == Integer.MIN_VALUE
714-
|| world.provider.getDimension() != hyperDim) {
711+
if (!zmaster587.advancedRocketry.space.HyperspaceWorld.isHyperspace(world)) {
715712
return zmaster587.advancedRocketry.space.ShipTransitManager.Phase.NONE;
716713
}
717714
// In hyperspace for certain. The registry only REFINES that into departing/arriving; when it

‎src/test/java/zmaster587/advancedRocketry/test/unit/HyperspaceDimIdIsAskedPerSideTest.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package zmaster587.advancedRocketry.test.unit;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45

56
import org.junit.After;
67
import org.junit.Before;
@@ -17,7 +18,7 @@
1718
* <p>What is pinned here is the SERVER's answer, which needs no world to express. The client's half -
1819
* that a reader on a remote world picks the told value, and that the telling is forgotten when the
1920
* connection ends - is observable ONLY through a world that reports itself remote, so it belongs to a
20-
* client test and is deliberately not faked here. An assertion routed through {@code dimIdFor(null)}
21+
* client test and is deliberately not faked here. An assertion routed through a world-less call
2122
* would read the server's field and stay green however the client's side behaved.</p>
2223
*/
2324
public class HyperspaceDimIdIsAskedPerSideTest {
@@ -41,11 +42,10 @@ public void whatAServerReportedIsNeverTheServerSideAnswer() {
4142
}
4243

4344
@Test
44-
public void withNoWorldToAskAboutTheAnswerIsThisSidesOwn() {
45+
public void nothingIsHyperspaceWhenThereIsNoWorldToAskAbout() {
4546
HyperspaceWorld.adoptFromServer(45);
4647

47-
assertEquals("a caller with no world in hand is server-side by construction - the client"
48-
+ " always has one - so it gets the local registration, absent here",
49-
Integer.MIN_VALUE, HyperspaceWorld.dimIdFor(null));
48+
assertFalse("a question about no world has one honest answer, and it is not a crash",
49+
HyperspaceWorld.isHyperspace(null));
5050
}
5151
}

0 commit comments

Comments
 (0)