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
The knockback hook test and docs follow the hook's new place
Ludovic Marie6edff5155899
diff --git a/crates/horizon-client/src/game/native_hooks.rs b/crates/horizon-client/src/game/native_hooks.rsindex fd5a9f446..de2f56858 100644--- a/crates/horizon-client/src/game/native_hooks.rs+++ b/crates/horizon-client/src/game/native_hooks.rs@@ -3618,7 +3618,8 @@ impl Game<'_> {}/// `LivingEntity.knockback` is about to push entity `entity` of type `kind`/// (`minecraft:zombie`, `minecraft:player`) `strength` away from the direction (`x`, `z`),- /// after the entity's knockback resistance took its share and before its motion changes+ /// on the raw strength, before the entity's knockback resistance takes its share and its motion+ /// changes/// (docs/native-mods.md, API 125). Vanilla's direction points at the/// source of a hit (the attacker's side), and the entity is pushed the other way. Change/// `strength`, `x` or `z`, or set `canceled`, and the push follows them: canceled, thediff --git a/crates/horizon-client/src/health.rs b/crates/horizon-client/src/health.rsindex 6b6349302..c8d8abaed 100644--- a/crates/horizon-client/src/health.rs+++ b/crates/horizon-client/src/health.rs@@ -1260,14 +1260,15 @@ mod tests {assert_eq!(velocity(&turned), (0.8, 0.4, 0.0));// Numbers that are not finite are put back as the game made them.assert_eq!(velocity(&push(9103, 0.0)), (-0.4, 0.4, 0.0));- // After the resistance: half of 0.4 is what the hook is handed.+ // Before the resistance (`LivingKnockBackEvent`): the hook is handed the raw 0.4, and+ // the push that follows is halved.let resisted = push(9104, 0.5);assert_eq!(velocity(&resisted), (-0.2, 0.2, 0.0));- assert_eq!(seen(9104)[0].1.strength, 0.2);- // A full resistance leaves a strength of 0, which a mod may raise.- let raised = push(9105, 1.0);- assert_eq!(seen(9105)[0].1.strength, 0.0);- assert_eq!(velocity(&raised), (-0.4, 0.4, 0.0));+ assert_eq!(seen(9104)[0].1.strength, 0.4);+ // A full resistance takes all of what the hook leaves: no push.+ let stopped = push(9105, 1.0);+ assert_eq!(seen(9105)[0].1.strength, 0.4);+ assert_eq!(velocity(&stopped), (0.0, 0.0, 0.0));// The game's own hit on a mob reaches the hook with its damage.let mut hurt = mob(9106, 0.0);assert!(hurt.damage(2.0, hit));diff --git a/docs/native-mods.md b/docs/native-mods.mdindex 00898d73a..a1209f147 100644--- a/docs/native-mods.md+++ b/docs/native-mods.md@@ -814,12 +814,12 @@ API 123 adds `native_screen_mouse_dragged_pre(screen, button, delta, modifiers,API 124 adds `native_mod_container_viewers(dimension, pos, viewers, previous)` is heard once each time the number of players with the mod container at `pos` open changes (vanilla's `ContainerOpenersCounter`, as a barrel keeps it): `previous` 0 is `onOpen`, `viewers` 0 is `onClose`, so a block can show itself open while `viewers` is not 0. It is counted every tick from the players' open menus, so a player who leaves without closing (a lost connection, death, another dimension, out of reach, the block gone) is heard too. On a server, with no player's state swapped in. Bundles that use it need `"hooks": 124`.API 125 adds knockback a mod can change or cancel through `native_living_knockback` (NeoForge's-`LivingKnockBackEvent`): in `LivingEntity.knockback`, after the entity's knockback resistance took its share and before its-motion changes, with the pushed entity's id and type (`minecraft:player` for a player), the `strength`, the direction+`LivingKnockBackEvent`): at the start of `LivingEntity.knockback`, on the raw strength, before the entity's knockback resistance takes its+share and its motion changes, with the pushed entity's id and type (`minecraft:player` for a player), the `strength`, the direction(`x`, `z`; vanilla points it at the source of a hit, the attacker's side, and the entity is pushed the other way) and a`canceled` flag. A mod may change the three numbers or set `canceled`, and the push follows: canceled, the entity's motion isleft alone. A `strength` of 0 or less after the hook is no push, and a direction too short to tell draws a random one-after it, as in vanilla; a full knockback resistance hands the hook a strength of 0, which a mod may raise. A value a mod+after it, as in vanilla; the resistance scales the strength the hook leaves, so a full knockback resistance still stops the push. A value a modleaves that is not a finite number is put back as it was. `damage_type` (`minecraft:player_attack`), `causing`(`DamageSource.getEntity`) and `direct` (`getDirectEntity`) are the push's damage source, named as`native_living_incoming_damage` names a hit's, with the same entity ids left at 0 (a goat's ram pushes with