Skip to content

Commit f1f24ef

Browse files
committed
Merge branch 'main' of https://github.com/cakeGit/sable
2 parents c9f08fa + 5872cc6 commit f1f24ef

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/api/physics/callback/BlockSubLevelCollisionCallback.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,42 @@ public interface BlockSubLevelCollisionCallback {
1818
default double[] onCollision(final int x,
1919
final int y,
2020
final int z,
21-
final double x1,
22-
final double y1,
23-
final double z1,
21+
final double xWorld,
22+
final double yWorld,
23+
final double zWorld,
24+
final int xOther,
25+
final int yOther,
26+
final int zOther,
27+
final double xWorldOther,
28+
final double yWorldOther,
29+
final double zWorldOther,
2430
final double impactVelocity) {
25-
final CollisionResult result = this.sable$onCollision(new BlockPos(x, y, z), new Vector3d(x1, y1, z1), impactVelocity);
31+
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);
2632
final Vector3dc motion = result.tangentMotion;
2733

2834
// TODO: this is stupid and moronic to pass through the removal as a double lmao, let's not do that in the future
2935
return new double[]{motion.x(), motion.y(), motion.z(), result.removeCollision ? 1.0 : 0.0};
3036
}
3137

32-
CollisionResult sable$onCollision(BlockPos blockPos, Vector3d pos, double impactVelocity);
38+
/**
39+
* Called when a collision occurs between two blocks, from JNI / pipeline implementations.
40+
* <p>
41+
* Legacy onCollision method for back-compatibility with older pipeline implementations.
42+
* It is preferred you implement the fully qualified version {@link #sable$onCollision(BlockPos, Vector3d, BlockPos, Vector3d, double)} for new implementations.
43+
* <p>
44+
* Ignored if the fully qualified version is implemented.
45+
* */
46+
@Deprecated
47+
default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final double impactVelocity) {
48+
return CollisionResult.NONE;
49+
}
50+
51+
/**
52+
* Called when a collision occurs between two blocks, from JNI / pipeline implementations.
53+
* */
54+
default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final BlockPos otherBlockPos, final Vector3d otherPos, final double impactVelocity) {
55+
return this.sable$onCollision(blockPos, pos, impactVelocity);
56+
}
3357

3458
record CollisionResult(Vector3dc tangentMotion, boolean removeCollision) {
3559
public static final CollisionResult NONE = new CollisionResult(JOMLConversion.ZERO, false);
Binary file not shown.

common/src/main/rust/rapier/src/hooks.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ impl PhysicsHooks for SablePhysicsHooks {
7373
collider_a,
7474
Some(level_collider_a),
7575
&contact.point,
76+
collider_b.position(),
77+
level_collider_b,
7678
velocity,
7779
manifold_index,
7880
true,
@@ -89,6 +91,8 @@ impl PhysicsHooks for SablePhysicsHooks {
8991
collider_b,
9092
Some(level_collider_b),
9193
&contact.point,
94+
collider_a.position(),
95+
level_collider_a,
9296
velocity,
9397
manifold_index,
9498
false,
@@ -144,6 +148,8 @@ fn handle_block_params(
144148
_collider: &Collider,
145149
level_collider: Option<&LevelCollider>,
146150
global_point: &Vector,
151+
other_isometry: &Pose,
152+
other_level_collider: Option<&LevelCollider>,
147153
velocity: Real,
148154
manifold_index: usize,
149155
body_a: bool,
@@ -152,6 +158,7 @@ fn handle_block_params(
152158
let scene = get_scene_mut(level_collider.unwrap().scene_id);
153159

154160
let collider_info = level_collider.and_then(|lc| lc.id.map(|id| &scene.level_colliders[&(id)]));
161+
let other_collider_info = other_level_collider.and_then(|lc| lc.id.map(|id| &scene.level_colliders[&(id)]));
155162

156163
let mut tangent_velo: Vector = Vector::ZERO;
157164

@@ -175,6 +182,12 @@ fn handle_block_params(
175182
manifold_info.pos_b
176183
};
177184

185+
let other_block_coord = if body_a {
186+
manifold_info.pos_b
187+
} else {
188+
manifold_info.pos_a
189+
};
190+
178191
let block_id = if body_a {
179192
manifold_info.col_a as u32
180193
} else {
@@ -186,6 +199,11 @@ fn handle_block_params(
186199
let block_coord_d: Vector3<f64> =
187200
Vector3::new(local.x as f64, local.y as f64, local.z as f64) + center_of_mass;
188201

202+
let other_center_of_mass = other_collider_info.map_or(Vector3::zeros(), |b| b.center_of_mass.unwrap());
203+
let other_local = other_isometry.inverse_transform_point(*global_point);
204+
let other_block_coord_d: Vector3<f64> =
205+
Vector3::new(other_local.x as f64, other_local.y as f64, other_local.z as f64) + other_center_of_mass;
206+
189207
if block_id == 0 {
190208
return (tangent_velo, false, 1.0, 0.0);
191209
}
@@ -228,6 +246,12 @@ fn handle_block_params(
228246
JValue::Double(block_coord_d.x),
229247
JValue::Double(block_coord_d.y),
230248
JValue::Double(block_coord_d.z),
249+
JValue::Int(other_block_coord.x as jint),
250+
JValue::Int(other_block_coord.y as jint),
251+
JValue::Int(other_block_coord.z as jint),
252+
JValue::Double(other_block_coord_d.x),
253+
JValue::Double(other_block_coord_d.y),
254+
JValue::Double(other_block_coord_d.z),
231255
JValue::Double(velocity as jdouble),
232256
];
233257

common/src/main/rust/rapier/src/voxel_collider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_new
7171
env.get_method_id(
7272
class,
7373
String::from("onCollision"),
74-
String::from("(IIIDDDD)[D"),
74+
String::from("(IIIDDDIIIDDDD)[D"),
7575
)
7676
.unwrap(),
7777
);

0 commit comments

Comments
 (0)