[PR #6800] [MERGED] Native mods: let an item's stack size go past 99 (fixes #6713) #7104

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6800
Author: @JustKarkat
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/native-mod-max-stack-size


📝 Commits (3)

  • b05b0d9 Native mods: let an item's stack size go past 99
  • a6b2255 Merge main into #6800
  • 9ed22e8 Fill main's two new loot hooks in the stack-size test's NativeLoadHooks

📊 Changes

7 files changed (+134 additions, -36 deletions)

View changed files

📝 crates/horizon-client/src/game/commands.rs (+5 -2)
📝 crates/horizon-client/src/game/lan_actions.rs (+6 -3)
📝 crates/horizon-client/src/menu.rs (+6 -4)
📝 crates/horizon-client/src/menu/place.rs (+1 -3)
📝 crates/horizon-client/src/mod_api/generated.rs (+6 -5)
📝 crates/horizon-world/src/item_defaults.rs (+104 -16)
📝 docs/native-mods.md (+6 -3)

📄 Description

🤖 Opened by JustKarkat's AI agent (ZCode, opencode-go-chat/deepseek-v4.1), not by JustKarkat personally.

What and why

Fixes #6713.

item_defaults::read ran a native mod's modify_default_components hook and
then clamped minecraft:max_stack_size to 1..=99, so a mod's larger value was
silently discarded. Two defects came with it:

  • a value that is not a number ("500") skipped the clamp entirely, and each
    reader then read its own default from it (the item table 64, the item models
    1), so the same item had two different stack sizes;
  • even a numeric value above 99 never reached any reader, so a native mod
    could not raise a stack size at all (the report's settings-menu use case).

Now:

  • a data pack's own size is held to vanilla's 1 to 99 before the hook
    (ExtraCodecs.intRange(1, 99)), as before for every item that ships today;
  • a mod's size, which no codec decodes, is held to 1 to i32::MAX — the
    count the wire's VarInt and the save's int carry, so a bigger value cannot
    turn negative on the way out (item_defaults::MAX_STACK_SIZE);
  • a value that is not a number leaves the data pack's own, and a component the
    mod removes stays removed.

A stack above 99 is useless if the first click trims it, so a container slot
now caps at the item's own size instead of vanilla's fixed Container.getMaxStackSize
of 99. For every data pack item that is the same answer as before (their sizes
are at most 99), and the mod-slot hook (native_menu_slot_rules) keeps its own
1 to 99 container limit. The creative slot packet's 1-to-99 check and /give's
max_stack * 100 limit follow the same bound (the latter saturates instead of
overflowing near i32::MAX).

Cross-side caveat, documented in docs/native-mods.md: a vanilla client
decodes the count with vanilla's 1 to 99, so a stack above 99 belongs to a
server whose clients run the mod.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

ItemStack.CODEC / ExtraCodecs.intRange(1, 99) for a data pack's own value,
Container.getMaxStackSize (99) and Slot.getMaxStackSize(stack) for a
container slot, ServerGamePacketListenerImpl.handleSetCreativeModeSlot for
the creative packet, GiveCommand for /give. The hook itself is
NeoForge-only (ModifyDefaultComponentsEvent); "Horizon-only" in the sense
that vanilla has no hook. No harness changes: vanilla items keep their sizes,
which tools/test_menu_click_parity.py and the item harnesses cover in CI
(pr_ready --quick listed parity for CI).

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on cachy-josh-pc, against origin/main at c2d352e0a, 1 min 8 s)

Check Result
Scope ✅ 7 files, +132 −36
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 602 passed (30 s)
rustfmt ✅ (6 s)
clippy ✅ (10 s)
tests: horizon-client, horizon-client-lib, horizon-world ✅ 2365 passed (15 s)
doc tests ✅ 0 passed (4 s)
content root tests ➖ content root untouched
mod API up to date ✅ (3 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Screenshots

No visual change: no item that ships today gets a different size.


🔄 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/6800 **Author:** [@JustKarkat](https://github.com/JustKarkat) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/native-mod-max-stack-size` --- ### 📝 Commits (3) - [`b05b0d9`](https://github.com/horizon-rust/horizon/commit/b05b0d939a3fe36dc8c698ab53fd8213d122f62c) Native mods: let an item's stack size go past 99 - [`a6b2255`](https://github.com/horizon-rust/horizon/commit/a6b2255754ed05bfc2ed8e29be971555c5643c5d) Merge main into #6800 - [`9ed22e8`](https://github.com/horizon-rust/horizon/commit/9ed22e8d8a62ff0bbe7864987a520a82a59b1cea) Fill main's two new loot hooks in the stack-size test's NativeLoadHooks ### 📊 Changes **7 files changed** (+134 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands.rs` (+5 -2) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+6 -3) 📝 `crates/horizon-client/src/menu.rs` (+6 -4) 📝 `crates/horizon-client/src/menu/place.rs` (+1 -3) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+6 -5) 📝 `crates/horizon-world/src/item_defaults.rs` (+104 -16) 📝 `docs/native-mods.md` (+6 -3) </details> ### 📄 Description > 🤖 Opened by JustKarkat's AI agent (ZCode, opencode-go-chat/deepseek-v4.1), not by JustKarkat personally. ## What and why Fixes #6713. `item_defaults::read` ran a native mod's `modify_default_components` hook and then clamped `minecraft:max_stack_size` to 1..=99, so a mod's larger value was silently discarded. Two defects came with it: - a value that is not a number (`"500"`) skipped the clamp entirely, and each reader then read its own default from it (the item table 64, the item models 1), so the same item had two different stack sizes; - even a numeric value above 99 never reached any reader, so a native mod could not raise a stack size at all (the report's settings-menu use case). Now: - a data pack's own size is held to vanilla's 1 to 99 **before** the hook (`ExtraCodecs.intRange(1, 99)`), as before for every item that ships today; - a mod's size, which no codec decodes, is held to 1 to `i32::MAX` — the count the wire's VarInt and the save's `int` carry, so a bigger value cannot turn negative on the way out (`item_defaults::MAX_STACK_SIZE`); - a value that is not a number leaves the data pack's own, and a component the mod removes stays removed. A stack above 99 is useless if the first click trims it, so a container slot now caps at the item's own size instead of vanilla's fixed `Container.getMaxStackSize` of 99. For every data pack item that is the same answer as before (their sizes are at most 99), and the mod-slot hook (`native_menu_slot_rules`) keeps its own 1 to 99 container limit. The creative slot packet's 1-to-99 check and `/give`'s `max_stack * 100` limit follow the same bound (the latter saturates instead of overflowing near `i32::MAX`). Cross-side caveat, documented in `docs/native-mods.md`: a vanilla client decodes the count with vanilla's 1 to 99, so a stack above 99 belongs to a server whose clients run the mod. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `ItemStack.CODEC` / `ExtraCodecs.intRange(1, 99)` for a data pack's own value, `Container.getMaxStackSize` (99) and `Slot.getMaxStackSize(stack)` for a container slot, `ServerGamePacketListenerImpl.handleSetCreativeModeSlot` for the creative packet, `GiveCommand` for `/give`. The hook itself is NeoForge-only (`ModifyDefaultComponentsEvent`); "Horizon-only" in the sense that vanilla has no hook. No harness changes: vanilla items keep their sizes, which `tools/test_menu_click_parity.py` and the item harnesses cover in CI (`pr_ready --quick` listed parity for CI). ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on cachy-josh-pc, against origin/main at c2d352e0a, 1 min 8 s) | Check | Result | | --- | --- | | Scope | ✅ 7 files, +132 −36 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 602 passed (30 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (10 s) | | tests: horizon-client, horizon-client-lib, horizon-world | ✅ 2365 passed (15 s) | | doc tests | ✅ 0 passed (4 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (3 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Screenshots No visual change: no item that ships today gets a different size. <!-- Please tick "Allow edits by maintainers": we push small fixups ourselves instead of a round trip. See CONTRIBUTING.md. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:33:54 +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#7104
No description provided.