Skip to content

Commit

Permalink
- Update item component validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xterionix committed Feb 9, 2025
1 parent f5d4a35 commit 3354455
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { minecraft_get_item } from "../../../Minecraft/Items";
import { behaviorpack_check_blockid } from "../../Block";
import { behaviorpack_entityid_diagnose } from "../../Entity";
import { behaviorpack_item_diagnose } from "../diagnose";
import { FormatVersion } from 'bc-minecraft-bedrock-types/lib/minecraft';

/**
*
Expand Down Expand Up @@ -65,6 +66,10 @@ const component_test: Record<string, ComponentCheck<Internal.BehaviorPack.Item>>
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid(block.name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
if (component.replace_block_item && context.source['minecraft:item'].description.identifier != component.block) diagnoser.add(`minecraft:block_placer/block/${component.block}`,
`${component.replace_block_item} and ${context.source['minecraft:item'].description.identifier} need to match when trying to replace the block item`,
DiagnosticSeverity.error,
'behaviorpack.item.components.replace_block_ids_dont_match')
if (component.block) {
if (typeof component.block == 'object' && 'name' in component.block) behaviorpack_check_blockid((component.block as { name: string }).name, diagnoser)
else if (typeof component.block == 'string') behaviorpack_check_blockid(component.block, diagnoser);
Expand Down Expand Up @@ -100,6 +105,17 @@ const component_test: Record<string, ComponentCheck<Internal.BehaviorPack.Item>>
'behaviorpack.item.components.texture_not_found')
})
}
},
"minecraft:custom_components": (name, component, context, diagnoser) => {
try {
const version = FormatVersion.parse(context.source.format_version);
if (version[0] < 1 || version[1] < 21 || (version[2] < 10 && version[1] <= 21)) diagnoser.add(context.source.format_version,
`To use custom components, a minimum format version of 1.21.10 is required`,
DiagnosticSeverity.error,
'behaviorpack.item.components.custom_components_min_version')
} catch (err) {
// Leaving this empty as the base diagnoser should already flag an invalid format version
}
}
};

Expand Down

0 comments on commit 3354455

Please sign in to comment.