Skip to content

Commit 0e5566a

Browse files
author
=
committed
a null check here can't hurt, right?
1 parent 7c95d2a commit 0e5566a

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/sw/world/interfaces/HasSpin.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,31 @@ default float getForce() {
8282
* @return The current inertia of this block.
8383
*/
8484
default float getInertia() {
85-
return spinConfig().inertia / getRatio();
85+
return spin() != null ? spinConfig().inertia / getRatio() : 0f;
8686
}
8787
/**
8888
* @return The current ratio of this block relative to the whole graph.
8989
*/
9090
default float getRatio() {
91-
return spinGraph().ratios.get(this, 1);
92-
}
93-
/**
94-
* @return The same as the non relative counterparts, but according to a reference graph. For disconnected builds.
95-
*/
96-
default float getRelativeForce(SpinGraph to) {
97-
return 0;
98-
}
99-
default float getRelativeTargetSpeed(SpinGraph to) {
100-
return 0;
91+
return spin() != null ? spinGraph().ratios.get(this, 1) : 1f;
10192
}
10293
/**
10394
* Returns the resistance that this build applies on the system.
10495
*/
10596
default float getResistance() {
106-
return spinConfig().resistance / getRatio();
97+
return spin() != null ? spinConfig().resistance / getRatio() : 0f;
10798
}
10899
/**
109100
* @return The current rotation of this system scaled by this build's ratio
110101
*/
111102
default float getRotation() {
112-
return spinGraph().rotation / getRatio();
103+
return spin() != null ? spinGraph().rotation / getRatio() : 0f;
113104
}
114105
/**
115106
* @return The current speed of this system scaled by the ratio.
116107
*/
117108
default float getSpeed() {
118-
return spinGraph().speed / getRatio();
109+
return spin() != null ? spinGraph().speed / getRatio() : 0f;
119110
}
120111
/**
121112
* Returns the speed that this block should try to reach.

0 commit comments

Comments
 (0)