[PR #5748] [MERGED] Native mods: read experience orbs, give experience and levels #6472

Closed
opened 2026-11-03 06:21:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5748
Author: @lukehinojosa
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: feat/native-give-experience


📝 Commits (4)

  • e2b0df5 Native mods: read experience orbs, give experience and levels
  • 50069df Merge remote-tracking branch 'hr/main' into pr-5748
  • 4e40cd0 Experience docs: no level-up sound for levels, when a give can be refused, merged orbs
  • dcbfa2e Merge remote-tracking branch 'hr/main' into pr-5748

📊 Changes

3 files changed (+153 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/native_server.rs (+137 -0)
📝 docs/native-mods.md (+8 -0)
➕ tools/native-hook-fragments/give_experience.json (+8 -0)

📄 Description

🤖 Opened by lukehinojosa's AI agent (Claude Code, Claude Opus 5.5), not by lukehinojosa personally.

Closes #5747.

What and why

Experience for server mods, helpers only, in game/native_server.rs:

  • native_experience_orbs(dimension, min, max) -> Vec<NativeExperienceOrb>: the orbs whose box (0.5 wide and
    high, standing on their position) meets the box, with id, position, value and count. What a mod reads
    before it cancels an orb in native_entity_join_level. Same guards as native_item_entities.
  • native_give_experience(uuid, points) -> bool: points given as touching an orb gives them
    (ExperienceOrb.playerTouch): Game::mending (repairPlayerItems) first, then Game::give_orb_points
    (Player.giveExperiencePoints, level-up sound). The player in place directly; a guest through as_guest, as
    guest_orbs does. False for a player not here or dead, and for another player than the one swapped in.
  • native_give_levels(uuid, levels: i32) -> bool: Game::give_levels (Player.giveExperienceLevels), negative
    to take levels off as the anvil and the enchanting table charge. Same dispatch and refusals
    (native_as_player). Like the existing port, it plays no level-up sound (vanilla does on every fifth level).

native_loot_drops doesn't hear experience; with these an auto-pickup takes a kill's or a block's orbs too.

API number from the give_experience fragment (helpers only, no hook).

Kind

  • extra: Horizon-only, off by default

Vanilla reference

ExperienceOrb.playerTouch → repairPlayerItems, then Player.giveExperiencePoints; AABB.intersects for the
orb box.

Tests

orbs_are_found_by_their_half_block_box: an orb's box inside, reaching in and standing just below a block's
cell meets it; one whose face or top only touches it, or standing on top, doesn't.

Proof

A minimal AutoPickup port (native mod: native_loot_drops and native_entity_join_level, giving orbs with these
helpers and items with native_give_stack from #5661), applied with horizon-mixins and built with --profile fast, driven with horizon-ctl in a fresh survival world (single player, integrated server):

  • cows killed with a diamond sword: each orb read (values 3, 3, 1, 3), cancelled and given; total experience 0 →
    10, no orbs left on the ground;
  • with a Mending diamond sword [damage=500] in the main hand: the next two orbs (1 + 1) repaired it and total
    experience stayed 10;
  • coal ore mined with an iron pickaxe: its experience given (10 → 12), no orbs left.

Here the killer was a guest of the integrated server, outside their own swap, so these went through
as_guest. Built on main plus #5661 and a local fix for #5678 (main crashes on entering a world until then).

  • native_give_levels, from a temporary trigger in the same port (a block's loot table → levels), starting at
    level 10 with progress 0.185: +5 → 15 and −3 → 12 with the progress kept, then −100 → level 0, progress 0,
    total 0.

Not covered: a LAN guest on another machine, and a dedicated server. In one earlier run (a build without debug
output) four cow kills gave no experience; I couldn't reproduce it in the run above.

Self-check

Run on Windows (DESKTOP-LMH2005) against origin/main at c51dcda01. pr_ready --quick counted an untracked
target/ folder in its scope, so these are its checks run by hand:

Check Result
Scope 3 files (see the diff)
rustfmt ✅
clippy --all-targets -D warnings ✅
tests: horizon-client (lib) ✅ 1103 passed
tests: horizon-client (bin) ⚠️ 479 passed, 1 failed: the CRLF test below, failing on main too
Parity ➖ CI's parity job picks the affected harnesses

Known on Windows: game::native_hooks::tests::loot_table_load_stays_hookable fails on a checkout with
core.autocrlf=true (it searches loot.rs for "\n}\n"), on main as well; CI's Linux checkout passes.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5748 **Author:** [@lukehinojosa](https://github.com/lukehinojosa) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/native-give-experience` --- ### 📝 Commits (4) - [`e2b0df5`](https://github.com/horizon-rust/horizon/commit/e2b0df56bdbafdacc2269f189f36195b49437137) Native mods: read experience orbs, give experience and levels - [`50069df`](https://github.com/horizon-rust/horizon/commit/50069df8983cb78200f038a3e56f20de893ae788) Merge remote-tracking branch 'hr/main' into pr-5748 - [`4e40cd0`](https://github.com/horizon-rust/horizon/commit/4e40cd0eb44f829ff21476c366f107dc0d4e13a6) Experience docs: no level-up sound for levels, when a give can be refused, merged orbs - [`dcbfa2e`](https://github.com/horizon-rust/horizon/commit/dcbfa2e3ed3211ce0406ea2e7e913055e02ac3ae) Merge remote-tracking branch 'hr/main' into pr-5748 ### 📊 Changes **3 files changed** (+153 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_server.rs` (+137 -0) 📝 `docs/native-mods.md` (+8 -0) ➕ `tools/native-hook-fragments/give_experience.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by lukehinojosa's AI agent (Claude Code, Claude Opus 5.5), not by lukehinojosa personally. Closes #5747. ## What and why Experience for server mods, helpers only, in `game/native_server.rs`: - `native_experience_orbs(dimension, min, max) -> Vec<NativeExperienceOrb>`: the orbs whose box (0.5 wide and high, standing on their position) meets the box, with id, position, `value` and `count`. What a mod reads before it cancels an orb in `native_entity_join_level`. Same guards as `native_item_entities`. - `native_give_experience(uuid, points) -> bool`: points given as touching an orb gives them (`ExperienceOrb.playerTouch`): `Game::mending` (`repairPlayerItems`) first, then `Game::give_orb_points` (`Player.giveExperiencePoints`, level-up sound). The player in place directly; a guest through `as_guest`, as `guest_orbs` does. False for a player not here or dead, and for another player than the one swapped in. - `native_give_levels(uuid, levels: i32) -> bool`: `Game::give_levels` (`Player.giveExperienceLevels`), negative to take levels off as the anvil and the enchanting table charge. Same dispatch and refusals (`native_as_player`). Like the existing port, it plays no level-up sound (vanilla does on every fifth level). `native_loot_drops` doesn't hear experience; with these an auto-pickup takes a kill's or a block's orbs too. API number from the `give_experience` fragment (helpers only, no hook). ## Kind - [x] extra: Horizon-only, off by default ## Vanilla reference `ExperienceOrb.playerTouch` → `repairPlayerItems`, then `Player.giveExperiencePoints`; `AABB.intersects` for the orb box. ## Tests `orbs_are_found_by_their_half_block_box`: an orb's box inside, reaching in and standing just below a block's cell meets it; one whose face or top only touches it, or standing on top, doesn't. ## Proof A minimal AutoPickup port (native mod: `native_loot_drops` and `native_entity_join_level`, giving orbs with these helpers and items with `native_give_stack` from #5661), applied with horizon-mixins and built with `--profile fast`, driven with horizon-ctl in a fresh survival world (single player, integrated server): - cows killed with a diamond sword: each orb read (values 3, 3, 1, 3), cancelled and given; total experience 0 → 10, no orbs left on the ground; - with a Mending diamond sword `[damage=500]` in the main hand: the next two orbs (1 + 1) repaired it and total experience stayed 10; - coal ore mined with an iron pickaxe: its experience given (10 → 12), no orbs left. Here the killer was a guest of the integrated server, outside their own swap, so these went through `as_guest`. Built on main plus #5661 and a local fix for #5678 (main crashes on entering a world until then). - `native_give_levels`, from a temporary trigger in the same port (a block's loot table → levels), starting at level 10 with progress 0.185: +5 → 15 and −3 → 12 with the progress kept, then −100 → level 0, progress 0, total 0. Not covered: a LAN guest on another machine, and a dedicated server. In one earlier run (a build without debug output) four cow kills gave no experience; I couldn't reproduce it in the run above. ## Self-check Run on Windows (DESKTOP-LMH2005) against origin/main at c51dcda01. `pr_ready --quick` counted an untracked `target/` folder in its scope, so these are its checks run by hand: | Check | Result | | --- | --- | | Scope | 3 files (see the diff) | | rustfmt | ✅ | | clippy `--all-targets -D warnings` | ✅ | | tests: horizon-client (lib) | ✅ 1103 passed | | tests: horizon-client (bin) | ⚠️ 479 passed, 1 failed: the CRLF test below, failing on main too | | Parity | ➖ CI's parity job picks the affected harnesses | Known on Windows: `game::native_hooks::tests::loot_table_load_stays_hookable` fails on a checkout with `core.autocrlf=true` (it searches `loot.rs` for `"\n}\n"`), on main as well; CI's Linux checkout passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:21:13 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6472
No description provided.