diff --git a/common/src/main/java/dev/ryanhcode/sable/api/physics/callback/BlockSubLevelCollisionCallback.java b/common/src/main/java/dev/ryanhcode/sable/api/physics/callback/BlockSubLevelCollisionCallback.java index cc2c88c4..2f1345f7 100644 --- a/common/src/main/java/dev/ryanhcode/sable/api/physics/callback/BlockSubLevelCollisionCallback.java +++ b/common/src/main/java/dev/ryanhcode/sable/api/physics/callback/BlockSubLevelCollisionCallback.java @@ -18,18 +18,30 @@ public interface BlockSubLevelCollisionCallback { default double[] onCollision(final int x, final int y, final int z, - final double x1, - final double y1, - final double z1, + final double xWorld, + final double yWorld, + final double zWorld, + final int xOther, + final int yOther, + final int zOther, + final double xWorldOther, + final double yWorldOther, + final double zWorldOther, final double impactVelocity) { - final CollisionResult result = this.sable$onCollision(new BlockPos(x, y, z), new Vector3d(x1, y1, z1), impactVelocity); + final CollisionResult result = this.sable$onCollision(new BlockPos(x, y, z), new Vector3d(xWorld, yWorld, zWorld), new BlockPos(xOther, yOther, zOther), new Vector3d(xWorldOther, yWorldOther, zWorldOther), impactVelocity); final Vector3dc motion = result.tangentMotion; // TODO: this is stupid and moronic to pass through the removal as a double lmao, let's not do that in the future return new double[]{motion.x(), motion.y(), motion.z(), result.removeCollision ? 1.0 : 0.0}; } - CollisionResult sable$onCollision(BlockPos blockPos, Vector3d pos, double impactVelocity); + default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final double impactVelocity) { + return CollisionResult.NONE; + } + + default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final BlockPos otherBlockPos, final Vector3d otherPos, final double impactVelocity) { + return this.sable$onCollision(blockPos, pos, impactVelocity); + } record CollisionResult(Vector3dc tangentMotion, boolean removeCollision) { public static final CollisionResult NONE = new CollisionResult(JOMLConversion.ZERO, false); diff --git a/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z b/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z index 022e3039..f75c094e 100644 Binary files a/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z and b/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z differ diff --git a/common/src/main/resources/sable.mixins.json b/common/src/main/resources/sable.mixins.json index ad2263af..03322c02 100644 --- a/common/src/main/resources/sable.mixins.json +++ b/common/src/main/resources/sable.mixins.json @@ -169,6 +169,7 @@ "game_test.TestCommandMixin", "impact.BeehiveBlockMixin", "impact.BellBlockMixin", + "impact.StainedGlassBlockMixin", "impact.TntBlockMixin", "interaction_distance.EntityMixin", "interaction_distance.PlayerMixin", diff --git a/common/src/main/rust/rapier/src/hooks.rs b/common/src/main/rust/rapier/src/hooks.rs index 0ab3fbdb..1119ca35 100644 --- a/common/src/main/rust/rapier/src/hooks.rs +++ b/common/src/main/rust/rapier/src/hooks.rs @@ -73,6 +73,8 @@ impl PhysicsHooks for SablePhysicsHooks { collider_a, Some(level_collider_a), &contact.point, + collider_b.position(), + level_collider_b, velocity, manifold_index, true, @@ -89,6 +91,8 @@ impl PhysicsHooks for SablePhysicsHooks { collider_b, Some(level_collider_b), &contact.point, + collider_a.position(), + level_collider_a, velocity, manifold_index, false, @@ -144,6 +148,8 @@ fn handle_block_params( _collider: &Collider, level_collider: Option<&LevelCollider>, global_point: &Vector, + other_isometry: &Pose, + other_level_collider: Option<&LevelCollider>, velocity: Real, manifold_index: usize, body_a: bool, @@ -152,6 +158,7 @@ fn handle_block_params( let scene = get_scene_mut(level_collider.unwrap().scene_id); let collider_info = level_collider.and_then(|lc| lc.id.map(|id| &scene.level_colliders[&(id)])); + let other_collider_info = other_level_collider.and_then(|lc| lc.id.map(|id| &scene.level_colliders[&(id)])); let mut tangent_velo: Vector = Vector::ZERO; @@ -175,6 +182,12 @@ fn handle_block_params( manifold_info.pos_b }; + let other_block_coord = if body_a { + manifold_info.pos_b + } else { + manifold_info.pos_a + }; + let block_id = if body_a { manifold_info.col_a as u32 } else { @@ -186,6 +199,11 @@ fn handle_block_params( let block_coord_d: Vector3 = Vector3::new(local.x as f64, local.y as f64, local.z as f64) + center_of_mass; + let other_center_of_mass = other_collider_info.map_or(Vector3::zeros(), |b| b.center_of_mass.unwrap()); + let other_local = other_isometry.inverse_transform_point(*global_point); + let other_block_coord_d: Vector3 = + Vector3::new(other_local.x as f64, other_local.y as f64, other_local.z as f64) + other_center_of_mass; + if block_id == 0 { return (tangent_velo, false, 1.0, 0.0); } @@ -228,6 +246,12 @@ fn handle_block_params( JValue::Double(block_coord_d.x), JValue::Double(block_coord_d.y), JValue::Double(block_coord_d.z), + JValue::Int(other_block_coord.x as jint), + JValue::Int(other_block_coord.y as jint), + JValue::Int(other_block_coord.z as jint), + JValue::Double(other_block_coord_d.x), + JValue::Double(other_block_coord_d.y), + JValue::Double(other_block_coord_d.z), JValue::Double(velocity as jdouble), ]; diff --git a/common/src/main/rust/rapier/src/voxel_collider.rs b/common/src/main/rust/rapier/src/voxel_collider.rs index 2badf7fb..c4b37d0a 100644 --- a/common/src/main/rust/rapier/src/voxel_collider.rs +++ b/common/src/main/rust/rapier/src/voxel_collider.rs @@ -71,7 +71,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_new env.get_method_id( class, String::from("onCollision"), - String::from("(IIIDDDD)[D"), + String::from("(IIIDDDIIIDDDD)[D"), ) .unwrap(), );