Skip to content

Commit

Permalink
- Add checks for icon and material instance being defined in their re…
Browse files Browse the repository at this point in the history
…spective atlas files (#286)
  • Loading branch information
Xterionix authored Nov 30, 2024
1 parent 352e050 commit 0cef4c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ const component_test: Record<string, ComponentCheck> = {
"minecraft:loot": (name, component, context, diagnoser) => {
if (typeof component === "string") behaviorpack_loot_table_diagnose(component, diagnoser);
},
"minecraft:material_instances": (name, component, context, diagnoser) => {
Object.keys(component).forEach(value => {
const textureId = component[value].texture;
if (!diagnoser.context.getCache().resourcePacks.textures.find(val => val.id == textureId && val.location.uri.includes('terrain_texture')))
diagnoser.add(textureId,
`Texture reference "${textureId}" was not defined in terrain_texture.json`,
DiagnosticSeverity.error,
'behaviorpack.block.components.texture_not_found')
})
}
};

function deprecated_component(replacement?: string) {
Expand Down
30 changes: 24 additions & 6 deletions src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentBehavior } from "bc-minecraft-bedrock-types/lib/minecraft/components";
import { DocumentDiagnosticsBuilder } from "../../../../Types";
import { DiagnosticSeverity, DocumentDiagnosticsBuilder } from "../../../../Types";
import { Context } from "../../../../utility/components";
import { component_error, ComponentCheck, components_check } from "../../../../utility/components/checks";
import { behaviorpack_check_blockid } from "../../Block";
Expand Down Expand Up @@ -49,24 +49,24 @@ const component_test: Record<string, ComponentCheck> = {
if (Array.isArray(component.dispense_on))
component.dispense_on.forEach((block: string | { name: string }) => {
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid(block.name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
if (Array.isArray(component.use_on))
component.use_on.forEach((block: string | { name: string }) => {
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid(block.name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
if (component.entity) behaviorpack_entityid_diagnose(component.entity, diagnoser);
},
"minecraft:block_placer": (name, component, context, diagnoser) => {
if (Array.isArray(component.use_on))
component.use_on.forEach((block: string | { name: string }) => {
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid(block.name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
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);
else if (typeof component.block == 'string') behaviorpack_check_blockid(component.block, diagnoser);
}
},
"minecraft:projectile": (name, component, context, diagnoser) => {
Expand All @@ -81,7 +81,25 @@ const component_test: Record<string, ComponentCheck> = {
});
});
},
// TODO: Check if icon points to valid item_texture
"minecraft:icon": (name, component, context, diagnoser) => {
if (typeof component == 'string') {
const textureId = component
if (!diagnoser.context.getCache().resourcePacks.textures.find(val => val.id == textureId && val.location.uri.includes('item_texture')))
diagnoser.add(textureId,
`Texture reference "${textureId}" was not defined in item_texture.json`,
DiagnosticSeverity.error,
'behaviorpack.item.components.texture_not_found')
} else {
Object.keys(component.textures)?.forEach(value => {
const textureId = component.textures[value];
if (!diagnoser.context.getCache().resourcePacks.textures.find(val => val.id == textureId && val.location.uri.includes('item_texture')))
diagnoser.add(textureId,
`Texture reference "${textureId}" was not defined in item_texture.json`,
DiagnosticSeverity.error,
'behaviorpack.item.components.texture_not_found')
})
}
}
};

function deprecated_component(replacement?: string) {
Expand Down

0 comments on commit 0cef4c9

Please sign in to comment.