Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update item component validation #317

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 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,18 @@ 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')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
// Leaving this empty as the base diagnoser should already flag an invalid format version
}
}
};

Expand Down