Skip to content

Fix ItemStack quantity > 99 crash during serialization#2895

Merged
tastybento merged 1 commit into
developfrom
fix/clamp-itemstack-quantity
Apr 2, 2026
Merged

Fix ItemStack quantity > 99 crash during serialization#2895
tastybento merged 1 commit into
developfrom
fix/clamp-itemstack-quantity

Conversation

@tastybento
Copy link
Copy Markdown
Member

Summary

  • Mojang's ItemStack codec enforces a [1, 99] range on item count (ExtraCodecs.intRange(1, 99) in ItemStack.MAP_CODEC). When addons provide items with quantities exceeding this limit (e.g., RED_MUSHROOM:100 in a Biomes template), CraftMagicNumbers.serializeStack() throws IllegalStateException: Value must be within range [1;99]: 100
  • Clamps quantities to [1, 99] at both parse time (ItemParser) and serialization time (ItemStackTypeAdapter) with a warning log, so the operation succeeds gracefully instead of crashing
  • Applies to all 4 quantity-parsing paths in ItemParser: simple items, potions, old-format potions, and banners

Test plan

  • ./gradlew test passes
  • Manual test: import a Biomes template with RED_MUSHROOM:100, verify warning is logged and import succeeds with quantity clamped to 99

🤖 Generated with Claude Code

Mojang's ItemStack codec enforces a [1, 99] range on item count
(ExtraCodecs.intRange(1, 99)). When addons provide items with
quantities exceeding this limit (e.g., RED_MUSHROOM:100), serialization
throws IllegalStateException.

Clamp quantities at both parse time (ItemParser) and serialization time
(ItemStackTypeAdapter) with a warning log, so the operation succeeds
gracefully instead of crashing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2026

@tastybento tastybento merged commit 74e7110 into develop Apr 2, 2026
3 checks passed
@tastybento tastybento deleted the fix/clamp-itemstack-quantity branch April 2, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant