Skip to content

Commit 09614b7

Browse files
committed
Prevent NPE for weightless contraptions
1 parent 2a358df commit 09614b7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

neoforge/src/main/java/dev/ryanhcode/sable/neoforge/mixin/compatibility/create/contraptions/AbstractContraptionEntityMixin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public AbstractContraptionEntityMixin(final EntityType<?> arg, final Level arg2)
9999
if (!this.sable$added && this.level() instanceof final ServerLevel serverLevel) {
100100
this.sable$buildProperties();
101101
this.sable$addToPlot();
102-
this.sable$addToPipeline(serverLevel);
102+
if (this.sable$massTracker.getCenterOfMass() != null) {
103+
this.sable$addToPipeline(serverLevel);
104+
}
103105
this.sable$added = true;
104106
}
105107
}
@@ -164,9 +166,12 @@ public CompoundTag saveWithoutId(final CompoundTag nbt) {
164166

165167
assert this.sable$localBounds != null;
166168
this.sable$massTracker = MassTracker.build(this.sable$blockGetter(), this.sable$localBounds);
167-
final Vector3d temp = this.sable$massTracker.getCenterOfMass().negate(new Vector3d()).add(0.5, 0.5, 0.5);
168-
for (final FloatingBlockCluster cluster : this.sable$floatingClusterContainer.clusters) {
169-
cluster.getBlockData().translateOrigin(temp);
169+
final Vector3dc centerOfMass = this.sable$massTracker.getCenterOfMass();
170+
if (centerOfMass != null) {
171+
final Vector3d temp = centerOfMass.negate(new Vector3d()).add(0.5, 0.5, 0.5);
172+
for (final FloatingBlockCluster cluster : this.sable$floatingClusterContainer.clusters) {
173+
cluster.getBlockData().translateOrigin(temp);
174+
}
170175
}
171176
}
172177

0 commit comments

Comments
 (0)