Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Native mods: a player's fishing rod, cast to reel-in, cancellable (native_player_fish)

Detimes5cd3a0027619
diff --git a/crates/horizon-client/src/game/fishing.rs b/crates/horizon-client/src/game/fishing.rs
index 344f13edb..af3456f6d 100644
--- a/crates/horizon-client/src/game/fishing.rs
+++ b/crates/horizon-client/src/game/fishing.rs
@@ -98,6 +98,22 @@ impl Game<'_> {
if &*stack.item != "minecraft:fishing_rod" {
return false;
}
+ // The mods hear a server player's cast or reel-in first.
+ if self.player.is_some()
+ && let (Some(uuid), Some(name)) = (self.lan_acting_uuid, self.lan_acting_name.clone())
+ {
+ let state = match &self.hook {
+ None => 0,
+ Some(h) if matches!(h.state, State::Hooked(_)) => 4,
+ Some(h) if h.nibble > 0 => 2,
+ Some(_) => 3,
+ };
+ let mut cancel = false;
+ self.native_player_fish(uuid, &name, state, &mut cancel);
+ if cancel {
+ return true;
+ }
+ }
let Some(p) = self.player.as_ref() else {
return false;
};
@@ -419,6 +435,19 @@ impl Game<'_> {
}
}
} else {
+ // The mods hear a server player's fish bite, and may call it
+ // off: the wait starts over.
+ if let (Some(uuid), Some(name)) =
+ (self.lan_acting_uuid, self.lan_acting_name.clone())
+ {
+ let mut cancel = false;
+ self.native_player_fish(uuid, &name, 1, &mut cancel);
+ if cancel {
+ h.time_until_lured = 0;
+ h.time_until_hooked = 0;
+ return;
+ }
+ }
let pitch =
1.0 + (self.world.random.next_float() - self.world.random.next_float()) * 0.4;
self.audio.play(
diff --git a/crates/horizon-client/src/game/native_hooks.rs b/crates/horizon-client/src/game/native_hooks.rs
index 14b884c4a..2f189a934 100644
--- a/crates/horizon-client/src/game/native_hooks.rs
+++ b/crates/horizon-client/src/game/native_hooks.rs
@@ -2725,6 +2725,28 @@ impl Game<'_> {
pub(super) fn native_perform_console_command(&mut self, command: &str, ran: &mut bool) {
let _ = (command, ran);
}
+ /// A server player's fishing rod, with `state`: 0 the cast
+ /// (`FishingRodItem.use` throwing the bobber), 1 a fish biting
+ /// (`FishingHook.catchingFish`), 2 the reel-in of a bite, which gives the
+ /// catch, 3 the reel-in with nothing on the line, 4 the reel-in of a
+ /// bobber hooked to an entity or item (like NeoForge's `ItemFishedEvent`
+ /// and Bukkit's `PlayerFishEvent`). Set `cancel` on the cast and nothing
+ /// is thrown; on a bite the fish gets away and the wait starts over; on
+ /// a reel-in (2 to 4) nothing happens, the bobber stays out and the rod
+ /// takes no wear. The bobber ending by itself (too far, the rod put
+ /// away, the owner dying), nor the host of a LAN world's rod. The
+ /// player's state is swapped in, so `native_acting_player`, `native_tell`
+ /// and the item helpers reach them. Once for each cast, bite and reel-in,
+ /// on a server. @API:native_player_fish@.
+ pub(super) fn native_player_fish(
+ &mut self,
+ player: u128,
+ name: &str,
+ state: i32,
+ cancel: &mut bool,
+ ) {
+ let _ = (player, name, state, cancel);
+ }
/// A click in a menu a mod opened (`native_open_menu`), which moved
/// nothing: the menu's `slot` (its own first, then the player's
/// inventory, `native_menu_inventory_slot`; -999 outside), the `button`
diff --git a/docs/native-mods.md b/docs/native-mods.md
index 00898d73a..30cb98667 100644
--- a/docs/native-mods.md
+++ b/docs/native-mods.md
@@ -1203,6 +1203,12 @@ For mods that run where the world is simulated: a dedicated server, a LAN host,
`native_player`, `native_give_items` and the other helpers reach them. A respawn at an anchor in another dimension, or
at the world spawn's free column, may still move them on a later tick, once that level has loaded round them; the
End-exit respawn (after the credits) does not fire it.
+- **`native_player_fish(player, name, state, cancel)`**: a player's fishing rod, on a server: `state` 0 the cast, 1 a fish
+ biting, 2 the reel-in of a bite (the catch), 3 the reel-in with nothing on the line, 4 the reel-in of a bobber hooked
+ to an entity or item. Set `cancel` and nothing is thrown (0), the fish gets away and the wait starts over (1), or the
+ bobber stays out with no wear on the rod (2 to 4). The bobber ending by itself (too far, rod put away, owner dead) is
+ not heard, nor is the host of a LAN world's rod. The player's state is swapped in, so `native_acting_player`,
+ `native_tell` and the item helpers reach them.
- **`native_perform_command(player, command, ran)`**: a player typed a registered command (without its slash) and
their level allows it, whether the world allows commands or not. The mod parses the line and sets `ran`. The
player's state is swapped in for the call, as for their other actions, so `native_player` reads them; a
diff --git a/tools/native-hook-fragments/native_player_fish.json b/tools/native-hook-fragments/native_player_fish.json
new file mode 100644
index 000000000..5a9099866
--- /dev/null
+++ b/tools/native-hook-fragments/native_player_fish.json
@@ -0,0 +1,12 @@
+{
+ "hooks": [
+ {
+ "name": "player_fish",
+ "target": "horizon_client::game::native_hooks::Game<'_>::native_player_fish",
+ "neoforge": "ItemFishedEvent",
+ "side": "server"
+ }
+ ],
+ "rust_summary": "a player's fishing rod: cast, bite, catch, reel-in, cancellable (`native_player_fish`).",
+ "doc_summary": "a player's fishing rod: `native_player_fish(player, name, state, cancel)` is heard for the cast (`state` 0), a fish biting (1), the reel-in with a catch (2), the reel-in with nothing on the line (3) and the reel-in of a bobber hooked to an entity or item (4), for a player of a server (NeoForge's `ItemFishedEvent`, Bukkit's `PlayerFishEvent`). A mod sets `cancel` to stop a cast, make the fish get away, or leave the bobber out on a reel-in. The player's state is swapped in. Bundles that use it need `\"hooks\": @API:native_player_fish@`."
+}