feat(items): support an @<count> stack-size suffix on item references - #232
feat(items): support an @<count> stack-size suffix on item references#23269Jesse wants to merge 1 commit into
Conversation
An item field previously placed the referenced item's stack verbatim, so every stack size needed its own ITEM declaration or .snbt file. A reference may now carry `@<count>` (1-64) to restack it, which the check pass validates, the printer emits unquoted, and the capture registry recognizes on export so a house using suffixes does not round-trip into one duplicate item per size. `@` becomes reserved in an ITEM importable's `name` to keep `giveItem coins@3` unambiguous; the import.json parser and schema both reject it. Only the reference is restacked -- the declaration's nbt is never mutated, and the dependency index folds a counted reference back onto its base entry so two sizes cannot race to define one graph node.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThe PR adds
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defects identified. Count suffixes are validated before application, base NBT remains immutable, all resolver forms preserve the requested count, and capture matching retains the existing click-action identity safeguards.
|
| Filename | Overview |
|---|---|
| language/src/items/index.ts | Adds suffix parsing, bounds validation, immutable count application, and count-aware resolution for all reference forms. |
| language/src/check/passes/checkItems.ts | Diagnoses out-of-range counts and provides targeted guidance for malformed suffixes. |
| ct_module/src/importables/items/projectItems.ts | Builds cached counted wrappers around resolved base items without mutating declarations. |
| ct_module/src/importables/items/captureRegistry.ts | Adds conservative single-stack identity indexes so captured stack variants can reuse known declarations. |
| ct_module/src/importables/items/dependencyIndex.ts | Folds counted wrappers onto base dependency nodes while leaving action-text differences visible. |
| ct_module/src/importables/items/resolveItem.ts | Composes cached click-action data onto counted NBT so click-action items retain the requested stack size. |
| language/src/htsl/print/helpers.ts | Allows count-bearing item references to print as lexer-compatible bare names. |
| language/src/importjson/parse/arguments.ts | Rejects ambiguous @ characters in ITEM declaration names with a targeted diagnostic. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Item reference text] --> B[Split optional @count suffix]
B --> C{Resolve base reference}
C --> D[Named ITEM]
C --> E[Vanilla item]
C --> F[Direct SNBT path]
D --> G[Copy NBT and set Count]
E --> G
F --> G
G --> H[Place or compare item stack]
I[Captured Housing stack] --> J[Restack to one for identity matching]
J --> K{Known base item?}
K -->|Yes| L[Emit base@count]
K -->|No| M[Export separate SNBT item]
Reviews (1): Last reviewed commit: "feat(items): support an @<count> stack-s..." | Re-trigger Greptile
An item field previously placed the referenced item's stack verbatim, so every stack size needed its own ITEM declaration or
.snbtfile. A reference may now carry an@<count>suffix (1–64) to restack it:The referenced item is unchanged — only the stack it is placed into — so one declaration covers every size.
Language
parseItemReferenceParts,isValidItemCount,withItemCountinlanguage/src/items/index.ts, with count-aware resolution across all three resolver entry points. The suffix must be all digits, which keeps direct.snbtpaths unambiguous.checkItemsreports an out-of-range count as an error, and adds a hint when a stray@survives the split.@, sooak_log@8emits unquoted.Reserved
@in item names@is now rejected in an ITEM importable'sname— otherwisegiveItem coins@3could mean either the item literally namedcoins@3or three ofcoins. Enforced in both the import.json parser and the JSON schema. Display names inside an item's NBT are unaffected.ct_module
name@<count>instead of a duplicate.snbtper size. Restack matching is deliberately narrower than the registry's normal edit-adoption path: only an identity match, or a cached click-action expectation that agrees, is accepted, since a wrong guess would silently point an action at an item with different click actions.nbtis never mutated —withItemCountalways copies.Docs
New "Stack Counts" section in
docs/htsl/basic-syntax.md, cross-linked from the affected actions and conditions. Includes the note that the count cannot come from a variable, and the doubling pattern for handing out a variable amount.One documented unknown: whether Housing's Block Type condition takes stack size into account is untested, and is marked as such in
docs/htsl/conditions.md.Tests
New
ct_module/test/itemFieldContent.test.ts, additions toitemCaptureRegistry,itemDependencyIndex,itemReferences, andimportjson.test.ts, plus fixtures for the suffix, an out-of-range count, and an@in a declared name.Test suites have not been run against this branch yet.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.