[GH-ISSUE #6713] Hardcoded 99 limit in item_defaults.rs makes it impossible for native mods to stack above 99 #2193

Closed
opened 2026-11-02 15:52:53 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @bartekchomik26-dotcom on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6713

I was looking into how native mods (hnmods) interact with item stack sizes and noticed that it is currently impossible for a mod to set a stack size above 99.

In crates/horizon-items/src/item_defaults.rs, the read() function calls the native mod hook, but immediately follows it with a hardcoded clamp. Because the clamp runs after the hook, any value greater than 99 injected by a mod is silently overwritten:

native_modify_default_components(item, components);

// ExtraCodecs.intRange(1, 99)
if let Some(size) = components
    .get_mut("minecraft:max_stack_size")
    .filter(|size| size.is_number())
{
    *size = size.as_f64().map_or(64, |n| (n as i64).clamp(1, 99)).into();
}

Impact / Use Case:
I am currently developing a native mod that allows server owners to configure custom item stack sizes via a settings menu. The goal is to support stack sizes up to 1k (1,000), 1m (1,000,000), and 1b (1,000,000,000).

Because of the clamp(1, 99), this is completely blocked at the engine level. Given that ItemStack::count is defined as a u32, the core engine appears fully capable of handling these larger values in memory. If the 99 limit is strictly a networking or UI constraint (to match vanilla's client protocol), it would be helpful to know, as it prevents modded servers from utilizing large stack sizes for performance or custom gameplay.

Additional Context (Type Bypass):
I also noticed that the .filter(|size| size.is_number()) check means a mod could bypass the clamp by setting the JSON value as a string (e.g., "500"). However, this skips the safety check and likely results in a parsing error or panic further down the line when the game attempts to read it as an integer.

Question:
Is this hardcoded limit intentional and required for engine stability? If so, what is the safest maximum value (e.g., i32::MAX or u32::MAX) that native mods could use without causing crashes?

Alternatively, could the clamp be removed at this stage, leaving the limiting to the packet serialization or UI rendering layer where the actual protocol constraints apply?

Originally created by @bartekchomik26-dotcom on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6713 I was looking into how native mods (hnmods) interact with item stack sizes and noticed that it is currently impossible for a mod to set a stack size above 99. In crates/horizon-items/src/item_defaults.rs, the read() function calls the native mod hook, but immediately follows it with a hardcoded clamp. Because the clamp runs after the hook, any value greater than 99 injected by a mod is silently overwritten: ```rust native_modify_default_components(item, components); // ExtraCodecs.intRange(1, 99) if let Some(size) = components .get_mut("minecraft:max_stack_size") .filter(|size| size.is_number()) { *size = size.as_f64().map_or(64, |n| (n as i64).clamp(1, 99)).into(); } ``` Impact / Use Case: I am currently developing a native mod that allows server owners to configure custom item stack sizes via a settings menu. The goal is to support stack sizes up to 1k (1,000), 1m (1,000,000), and 1b (1,000,000,000). Because of the clamp(1, 99), this is completely blocked at the engine level. Given that ItemStack::count is defined as a u32, the core engine appears fully capable of handling these larger values in memory. If the 99 limit is strictly a networking or UI constraint (to match vanilla's client protocol), it would be helpful to know, as it prevents modded servers from utilizing large stack sizes for performance or custom gameplay. Additional Context (Type Bypass): I also noticed that the .filter(|size| size.is_number()) check means a mod could bypass the clamp by setting the JSON value as a string (e.g., "500"). However, this skips the safety check and likely results in a parsing error or panic further down the line when the game attempts to read it as an integer. Question: Is this hardcoded limit intentional and required for engine stability? If so, what is the safest maximum value (e.g., i32::MAX or u32::MAX) that native mods could use without causing crashes? Alternatively, could the clamp be removed at this stage, leaving the limiting to the packet serialization or UI rendering layer where the actual protocol constraints apply?
Author
Owner

@kira-horizon[bot] commented on GitHub (Nov 2, 2026):

Claimed by JustKrabby on Discord (GitHub: JustKarkat), to avoid duplicate work. The claim lapses after 14 days without activity (a comment, a pull request or a commit mentioning #6713).

<!-- gh-comment-id:6569419679 --> @kira-horizon[bot] commented on GitHub (Nov 2, 2026): Claimed by `JustKrabby` on Discord (GitHub: `JustKarkat`), to avoid duplicate work. The claim lapses after 14 days without activity (a comment, a pull request or a commit mentioning #6713). <!-- kira:work -->
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#2193
No description provided.