Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
A trident's impact hook gets the hit location, not the start or the backed-off stop
Federico Taglianic50a0813b39b
diff --git a/crates/horizon-client/src/arrows.rs b/crates/horizon-client/src/arrows.rsindex ab81920f3..f7676927a 100644--- a/crates/horizon-client/src/arrows.rs+++ b/crates/horizon-client/src/arrows.rs@@ -403,6 +403,18 @@ pub fn clip_block_stop(collision: &BlockCollisionRegistry<'_>,from: Vec3,movement: Vec3,+) -> Option<(Vec3, BlockPos, [i32; 3])> {+ let (location, block, normal) = clip_block_hit(world, facts, collision, from, movement)?;+ Some((back_off(location, movement), block, normal))+}+/// The clip of `clip_block_stop` before the back-off: the hit location (what a+/// `BlockHitResult` carries), the block and the normal of the face.+pub fn clip_block_hit(+ world: &World,+ facts: &BlockFacts,+ collision: &BlockCollisionRegistry<'_>,+ from: Vec3,+ movement: Vec3,) -> Option<(Vec3, BlockPos, [i32; 3])> {let to = Vec3::new(from.x + movement.x,@@ -426,11 +438,7 @@ pub fn clip_block_stop(}).ok().flatten()?;- Some((- back_off(hit.location, movement),- hit.block,- hit.direction.normal(),- ))+ Some((hit.location, hit.block, hit.direction.normal()))}/// `AbstractArrow.onHitBlock`'s back-off: vanilla scales `(double) 0.05f` by/// `Math.signum` per axis, whose value at zero is zero (not Rust's -1.0).diff --git a/crates/horizon-client/src/game/trident.rs b/crates/horizon-client/src/game/trident.rsindex 8c6417061..fb5ad2bb0 100644--- a/crates/horizon-client/src/game/trident.rs+++ b/crates/horizon-client/src/game/trident.rs@@ -5,7 +5,7 @@//! lightning on a hit (`channeling.json`).use super::{Game, view_vector};use horizon_client::{- arrows::{back_off, clip_block_stop},+ arrows::{back_off, clip_block_hit},collisions::SceneCollisions,enchant::EffectContext,items::ItemStack,@@ -606,8 +606,14 @@ impl Game<'_> {}// ProjectileImpactEvent for the mob hit: a canceled one does// nothing, and the trident stays where it would have hit.- let canceled_mob = hit_mob.is_some_and(|(id, _)| {- self.native_trident_impact(t.id, t.guest, Some(id), [0; 3], [0; 3], t.position)+ let canceled_mob = hit_mob.is_some_and(|(id, d)| {+ // `at` is where the movement enters the mob's box.+ let at = Vec3::new(+ t.position.x + t.velocity.x * d,+ t.position.y + t.velocity.y * d,+ t.position.z + t.velocity.z * d,+ );+ self.native_trident_impact(t.id, t.guest, Some(id), [0; 3], [0; 3], at)});if canceled_mob {// No damage, sound or deflection: it flies on.@@ -696,26 +702,23 @@ impl Game<'_> {// `AbstractArrow.onHitBlock` on a hit.let from = t.position;let flight = t.velocity;- let clip = clip_block_stop(- &self.world,- self.res.facts(),- self.collision,- from,- flight,- );+ let clip =+ clip_block_hit(&self.world, self.res.facts(), self.collision, from, flight);// ProjectileImpactEvent for the block hit: a canceled one// doesn't stick the trident, which stays where it would// have hit, still flying.- let canceled_block = clip.is_some_and(|(stop, block, face)| {+ // The hook's `at` is the clip's hit location, before the back-off.+ let canceled_block = clip.is_some_and(|(at, block, face)| {self.native_trident_impact(t.id,t.guest,None,[block.x, block.y, block.z],face,- stop,+ at,)});+ let clip = clip.map(|(at, block, face)| (back_off(at, flight), block, face));if canceled_block && let Some((stop, _, _)) = clip {t.position = stop;} else if let Some((stop, block, _)) = clip {