Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions common/src/main/java/dev/ryanhcode/sable/SableCommonEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ public static void handleBlockChange(final ServerLevel level, final LevelChunk c
if (plotChunk != null) {
final LevelPlot plot = container.getPlot(chunkPos);
final BlockPos blockPos = new BlockPos(x, y, z);
final SubLevel subLevel = plot.getSubLevel();

if (subLevel.isRemoved()) {
return;
}

plotChunk.handleBlockChange(localX, y, localZ, oldState, newState);
plot.updateBoundingBox();
plot.expandIfNecessary(blockPos);

final SubLevel subLevel = plot.getSubLevel();

final WaterOcclusionContainer<?> waterOcclusionContainer = WaterOcclusionContainer.getContainer(level);

if (waterOcclusionContainer != null) {
Expand All @@ -78,10 +81,6 @@ public static void handleBlockChange(final ServerLevel level, final LevelChunk c
heatMapManager.onSolidRemoved(blockPos);
}
}

if (subLevel.isRemoved()) {
return;
}
}

final int idx = chunk.getSectionIndex(y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ public void removeSubLevel(final int x, final int z, final SubLevelRemovalReason
throw new IllegalStateException("No sub-level at " + x + ", " + z);
}

subLevel.markRemoved();
this.observers.forEach(observer -> observer.onSubLevelRemoved(subLevel, reason));
subLevel.onRemove();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public void add(final ServerSubLevel subLevel, final Pose3dc pose) {

final int id = Rapier3D.getID(subLevel);
Rapier3D.createSubLevel(this.sceneId, id, new double[]{pos.x(), pos.y(), pos.z(), rot.x(), rot.y(), rot.z(), rot.w()});
this.activeSubLevels.put(id, subLevel);

subLevel.updateMergedMassData(1.0f);
final Vector3dc centerOfMass = subLevel.getMassTracker().getCenterOfMass();
Expand All @@ -328,17 +329,17 @@ public void add(final ServerSubLevel subLevel, final Pose3dc pose) {

this.onStatsChanged(subLevel);
}

this.activeSubLevels.put(Rapier3D.getID(subLevel), subLevel);
}

/**
* Removes a {@link SubLevel} from the physics pipeline.
*/
@Override
public void remove(final ServerSubLevel subLevel) {
Rapier3D.removeSubLevel(this.sceneId, Rapier3D.getID(subLevel));
this.activeSubLevels.remove(Rapier3D.getID(subLevel));
final int id = Rapier3D.getID(subLevel);
if (this.activeSubLevels.remove(id) != null) {
Rapier3D.removeSubLevel(this.sceneId, id);
}
}

/**
Expand Down Expand Up @@ -529,6 +530,10 @@ public void handleBlockChange(final SectionPos sectionPos, final LevelChunkSecti

@Override
public void onStatsChanged(@NotNull final ServerSubLevel serverSubLevel) {
if (serverSubLevel.isRemoved() || !this.activeSubLevels.containsKey(Rapier3D.getID(serverSubLevel))) {
return;
}

final BoundingBox3ic plotBounds = serverSubLevel.getPlot().getBoundingBox();

final int id = Rapier3D.getID(serverSubLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ public void updateMassDataFromBlockChange(final SubLevel subLevel, final BlockPo

if (notifyPipeline) {
serverSubLevel.updateMergedMassData((float) this.getPartialPhysicsTick());
this.pipeline.onStatsChanged(serverSubLevel);
}
}
}
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions common/src/main/rust/rapier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_ste
}
}


#[unsafe(no_mangle)]
pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_getPose<'local>(
env: JNIEnv<'local>,
Expand Down