Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions common/src/main/resources/sable.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"game_test.TestCommandMixin",
"impact.BeehiveBlockMixin",
"impact.BellBlockMixin",
"impact.StainedGlassBlockMixin",
"impact.TntBlockMixin",
"interaction_distance.EntityMixin",
"interaction_distance.PlayerMixin",
Expand Down
24 changes: 24 additions & 0 deletions common/src/main/rust/rapier/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -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 {
Expand All @@ -186,6 +199,11 @@ fn handle_block_params(
let block_coord_d: Vector3<f64> =
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<f64> =
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);
}
Expand Down Expand Up @@ -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),
];

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/rust/rapier/src/voxel_collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
Loading