Skip to content

Commit 7a5df9d

Browse files
committed
hi
1 parent a01bfac commit 7a5df9d

6 files changed

Lines changed: 118 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,30 @@ 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+
default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final double impactVelocity) {
39+
return CollisionResult.NONE;
40+
}
41+
42+
default CollisionResult sable$onCollision(final BlockPos blockPos, final Vector3d pos, final BlockPos otherBlockPos, final Vector3d otherPos, final double impactVelocity) {
43+
return this.sable$onCollision(blockPos, pos, impactVelocity);
44+
}
3345

3446
record CollisionResult(Vector3dc tangentMotion, boolean removeCollision) {
3547
public static final CollisionResult NONE = new CollisionResult(JOMLConversion.ZERO, false);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package dev.ryanhcode.sable.mixin.impact;
2+
3+
import dev.ryanhcode.sable.api.block.BlockWithSubLevelCollisionCallback;
4+
import dev.ryanhcode.sable.api.physics.callback.BlockSubLevelCollisionCallback;
5+
import dev.ryanhcode.sable.physics.callback.DestructiveBlockCallback;
6+
import dev.ryanhcode.sable.physics.callback.ExplosiveBlockCallback;
7+
import net.minecraft.world.level.block.BellBlock;
8+
import net.minecraft.world.level.block.StainedGlassBlock;
9+
import net.minecraft.world.level.block.TntBlock;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
12+
@Mixin(StainedGlassBlock.class)
13+
public abstract class StainedGlassBlockMixin implements BlockWithSubLevelCollisionCallback {
14+
15+
@Override
16+
public BlockSubLevelCollisionCallback sable$getCallback() {
17+
return DestructiveBlockCallback.INSTANCE;
18+
}
19+
20+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package dev.ryanhcode.sable.physics.callback;
2+
3+
import dev.ryanhcode.sable.Sable;
4+
import dev.ryanhcode.sable.api.physics.callback.BlockSubLevelCollisionCallback;
5+
import dev.ryanhcode.sable.api.physics.constraint.PhysicsConstraintHandle;
6+
import dev.ryanhcode.sable.api.physics.handle.RigidBodyHandle;
7+
import dev.ryanhcode.sable.companion.math.JOMLConversion;
8+
import dev.ryanhcode.sable.mixinterface.block_properties.BlockStateExtension;
9+
import dev.ryanhcode.sable.physics.config.block_properties.PhysicsBlockPropertyTypes;
10+
import dev.ryanhcode.sable.sublevel.ServerSubLevel;
11+
import dev.ryanhcode.sable.sublevel.SubLevel;
12+
import dev.ryanhcode.sable.sublevel.system.SubLevelPhysicsSystem;
13+
import net.minecraft.core.BlockPos;
14+
import net.minecraft.server.level.ServerLevel;
15+
import net.minecraft.world.level.block.IceBlock;
16+
import net.minecraft.world.level.block.LeavesBlock;
17+
import net.minecraft.world.level.block.state.BlockState;
18+
import org.joml.Vector3d;
19+
20+
public class DestructiveBlockCallback implements BlockSubLevelCollisionCallback {
21+
22+
public static final DestructiveBlockCallback INSTANCE = new DestructiveBlockCallback();
23+
24+
protected DestructiveBlockCallback() {}
25+
26+
public double getTriggerVelocity() {
27+
return 4.0;
28+
}
29+
30+
@Override
31+
public CollisionResult sable$onCollision(final BlockPos pos, final Vector3d pos1, final BlockPos FUCK, final Vector3d otherposshit, final double impactVelocity) {
32+
final double triggerVelocity = this.getTriggerVelocity();
33+
34+
if (impactVelocity * impactVelocity < triggerVelocity * triggerVelocity) {
35+
return CollisionResult.NONE;
36+
}
37+
38+
final SubLevelPhysicsSystem system = SubLevelPhysicsSystem.getCurrentlySteppingSystem();
39+
final ServerLevel level = system.getLevel();
40+
41+
level.destroyBlock(FUCK, true);
42+
system.wakeUpObjectsAt(FUCK.getX(), FUCK.getY(), FUCK.getZ());
43+
44+
//Get this sublevel, and decrease speed a little bit
45+
final SubLevel subLevel = Sable.HELPER.getContaining(level, pos);
46+
47+
if (subLevel instanceof ServerSubLevel serverSubLevel) {
48+
final RigidBodyHandle handle = system.getPhysicsHandle(serverSubLevel);
49+
system.wakeUpObjectsAt(pos.getX(), pos.getY(), pos.getZ());
50+
handle.applyImpulseAtPoint(JOMLConversion.toJOML(pos.getCenter()), handle.getLinearVelocity(new Vector3d()).mul(-0.01));
51+
}
52+
53+
return new CollisionResult(JOMLConversion.ZERO, true);
54+
}
55+
}

common/src/main/resources/sable.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
"game_test.TestCommandMixin",
170170
"impact.BeehiveBlockMixin",
171171
"impact.BellBlockMixin",
172+
"impact.StainedGlassBlockMixin",
172173
"impact.TntBlockMixin",
173174
"interaction_distance.EntityMixin",
174175
"interaction_distance.PlayerMixin",

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)