Fix false-positive geometry/material_instances pairing errors in block permutations#269
Conversation
…ions Co-authored-by: DaanV2 <2393905+DaanV2@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a false-positive diagnostic error where the minecraft:geometry ↔ minecraft:material_instances co-requirement (format version ≥ 1.21.80) was incorrectly enforced within block permutations. The check should only apply at the top-level components block since permutations may legitimately override just one of these components.
Changes:
- Added an
isPermutationflag to theContext<T>interface and gated the geometry/material_instances pairing check on!context.isPermutationto suppress false-positive errors in permutations. - Passed
{ ...context, isPermutation: true }when diagnosing permutation components indiagnose_block_document. - Added comprehensive tests for the pairing check across different scenarios (top-level, permutation, format versions).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/bedrock-diagnoser/src/utility/components/components.ts |
Added optional isPermutation boolean to the Context<T> interface |
packages/bedrock-diagnoser/src/diagnostics/behavior-pack/block/document.ts |
Passes isPermutation: true in context when diagnosing permutation components |
packages/bedrock-diagnoser/src/diagnostics/behavior-pack/block/components/diagnose.ts |
Gates geometry/material_instances pairing checks on !context.isPermutation |
packages/bedrock-diagnoser/test/lib/diagnostics/behavior-pack/block.test.ts |
New test file covering pairing check scenarios |
ide/vscode/src/version.ts |
Version bump from 9.0.18 to 9.0.20 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const diagnoser = TestDiagnoser.create(); | ||
| const block = makeBlock(FORMAT_VERSION_1_21_80); | ||
| const context = makeContext(block, ['minecraft:geometry']); | ||
|
|
||
| behaviorpack_diagnose_block_components( | ||
| { components: { 'minecraft:geometry': 'geometry.example' } }, | ||
| context, | ||
| diagnoser, | ||
| ); |
There was a problem hiding this comment.
TestDiagnoser.create() returns a TestDiagnoser which implements ManagedDiagnosticsBuilder but not DocumentDiagnosticsBuilder. The function behaviorpack_diagnose_block_components expects a DocumentDiagnosticsBuilder (which requires a document property). While this works at runtime because document is never accessed in this code path, it's a type mismatch that ts-jest may flag as a compilation error. Consider using TestDiagnoser.createDocument(undefined, doc) to create a TestDocumentDiagnoser (as done in block-properties.test.ts), or cast the diagnoser with as any.
The
minecraft:geometry↔minecraft:material_instancesco-requirement (format version ≥ 1.21.80) was being enforced per-permutation, but it only applies at the top-levelcomponentsblock. A permutation may legitimately override just one of these components.Changes
Context<T>interface (utility/components/components.ts): Added optionalisPermutation?: booleanfield.diagnose_block_document(block/document.ts): Passes{ ...context, isPermutation: true }when diagnosing permutation components, leaving top-level checks unaffected.minecraft:geometry/minecraft:material_instancesvalidators (block/components/diagnose.ts): Gate the pairing check on!context.isPermutationso it only fires for top-level components.Example — previously produced a false error
{ "permutations": [ { "condition": "!q.block_state('ns:hanging')", "components": { "minecraft:geometry": { "identifier": "geometry.ns.block" } } }, { "condition": "q.block_state('ns:lit')", "components": { "minecraft:material_instances": { "*": { "texture": "ns_block_on" } } } } ] }Previously this would error on the permutation containing only
minecraft:geometry. Both components are still required together at the top level.Original prompt
This section details on the original issue you should resolve
<issue_title>
"minecraft:geometry" requires "minecraft:material_instances" in format versions >= 1.21.80'when havingminecraft:geometryorminecraft:material_instancesoverrides in a permutation without overriding both.</issue_title><issue_description>Describe the bug
minecraft:geometryandminecraft:material_instancesare required to be together, but only at the top level. It is acceptable to have a single one of those components in a permutation condition, as long as both are defined in the end.Expected behavior
No error would be produced in this specific scenario.
Desktop:
</issue_description>
<agent_instructions>Here is the contents of the file shared: