diff --git a/src/Lib/Diagnostics/BehaviorPack/Block/components/dependencies.ts b/src/Lib/Diagnostics/BehaviorPack/Block/components/dependencies.ts index 4deac6e..b03bfcd 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Block/components/dependencies.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Block/components/dependencies.ts @@ -16,7 +16,7 @@ const component_dependents_any: DependedMap = { * @param diagnoser The diagnoser to report to*/ export function behaviorpack_block_components_dependencies( block: Internal.BehaviorPack.Block, - context: Context, + context: Context, diagnoser: DiagnosticsBuilder ): void { components_dependencies("block", context, diagnoser, component_dependents_all, component_dependents_any); diff --git a/src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts b/src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts index 2b6d6a9..d647671 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts @@ -1,4 +1,4 @@ -import { ComponentBehavior } from 'bc-minecraft-bedrock-types/lib/minecraft/components'; +import { ComponentBehavior } from "bc-minecraft-bedrock-types/lib/minecraft/components"; import { DiagnosticSeverity, DocumentDiagnosticsBuilder } from "../../../../Types"; import { Context } from "../../../../utility/components"; import { component_error, ComponentCheck, components_check } from "../../../../utility/components/checks"; @@ -6,6 +6,7 @@ import { check_geo_and_rules } from "../../../ResourcePack/BlockCulling"; import { resourcepack_has_model } from "../../../ResourcePack/Model/diagnose"; import { behaviorpack_loot_table_diagnose } from "../../Loot Table"; import { behaviorpack_check_blockid } from "../diagnose"; +import { Internal } from "bc-minecraft-bedrock-project"; /** * @@ -15,13 +16,13 @@ import { behaviorpack_check_blockid } from "../diagnose"; */ export function behaviorpack_diagnose_block_components( container: ComponentBehavior, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder ): void { components_check(container, context, diagnoser, component_test); } -const component_test: Record = { +const component_test: Record> = { "minecraft:destroy_time": deprecated_component("minecraft:destructible_by_mining"), "minecraft:block_light_emission": deprecated_component("minecraft:light_emission"), "minecraft:block_light_absorption": deprecated_component("minecraft:light_dampening"), @@ -68,8 +69,8 @@ const component_test: Record = { "minecraft:placement_filter": (name, component, context, diagnoser) => { for (const condition of component.conditions) { condition.block_filter?.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); + if (typeof block == "object" && "name" in block) behaviorpack_check_blockid(block.name, diagnoser); + else if (typeof block == "string") behaviorpack_check_blockid(block, diagnoser); }); } }, @@ -87,15 +88,17 @@ const component_test: Record = { if (typeof component === "string") behaviorpack_loot_table_diagnose(component, diagnoser); }, "minecraft:material_instances": (name, component, context, diagnoser) => { - Object.keys(component).forEach(value => { + Object.keys(component).forEach((value) => { const textureId = component[value].texture; - if (!diagnoser.context.getCache().resourcePacks.terrainTextures.find(val => val.id == textureId)) - diagnoser.add(textureId, + if (!diagnoser.context.getCache().resourcePacks.terrainTextures.find((val) => val.id == textureId)) + diagnoser.add( + textureId, `Texture reference "${textureId}" was not defined in terrain_texture.json`, DiagnosticSeverity.error, - 'behaviorpack.block.components.texture_not_found') - }) - } + "behaviorpack.block.components.texture_not_found" + ); + }); + }, }; function deprecated_component(replacement?: string) { diff --git a/src/Lib/Diagnostics/BehaviorPack/Block/entry.ts b/src/Lib/Diagnostics/BehaviorPack/Block/entry.ts index 52b29fb..559096d 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Block/entry.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Block/entry.ts @@ -18,7 +18,8 @@ export function Diagnose(diagnoser: DocumentDiagnosticsBuilder): void { if (!Internal.BehaviorPack.Block.is(block)) return; //check components - const context: Context = { + const context: Context = { + source: block, components: getUsedComponents(block["minecraft:block"]), }; block["minecraft:block"]?.permutations?.forEach((p) => { @@ -33,11 +34,11 @@ export function Diagnose(diagnoser: DocumentDiagnosticsBuilder): void { behaviorpack_block_components_dependencies(block, context, diagnoser); - if (block["minecraft:block"]["events"]) diagnoser.add( - `events`, - `Block events have been deprecated in favour of \`minecraft:custom_components\`.`, - DiagnosticSeverity.error, - "behaviorpack.block.deprecated" - ); - + if (block["minecraft:block"]["events"]) + diagnoser.add( + `events`, + `Block events have been deprecated in favour of \`minecraft:custom_components\`.`, + DiagnosticSeverity.error, + "behaviorpack.block.deprecated" + ); } diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/components.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/components.ts index 0d099b4..7ceed1d 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/components.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/components.ts @@ -6,7 +6,7 @@ import { behaviorpack_diagnose_entity_components } from "./components/diagnose"; export function behaviorpack_entity_components_check( entity: Internal.BehaviorPack.Entity, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder ) { const desc = entity["minecraft:entity"]; @@ -25,7 +25,7 @@ export function behaviorpack_entity_components_check( function behaviorpack_entity_componentscontainer_check( container: ComponentContainer | undefined | null, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder ) { if (container === null || typeof container !== "object") return; diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/components/dependencies.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/components/dependencies.ts index ffcc250..56e7255 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/components/dependencies.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/components/dependencies.ts @@ -35,7 +35,7 @@ const component_dependents_any: DependedMap = { * @param diagnoser The diagnoser to report to*/ export function behaviorpack_entity_components_dependencies( entity: Internal.BehaviorPack.Entity, - context: Context, + context: Context, diagnoser: DiagnosticsBuilder ): void { const components = context.components; diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/components/diagnose.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/components/diagnose.ts index 5693c33..7f506f8 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/components/diagnose.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/components/diagnose.ts @@ -5,6 +5,7 @@ import { ComponentCheck, components_check } from "../../../../utility/components import { behaviorpack_entity_components_filters } from './filters'; import { check_loot_table } from "./loot"; import { check_trade_table } from "./trade"; +import { Internal } from 'bc-minecraft-bedrock-project'; /** * @@ -14,7 +15,7 @@ import { check_trade_table } from "./trade"; */ export function behaviorpack_diagnose_entity_components( container: ComponentBehavior, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder ): void { components_check(container, context, diagnoser, component_test); @@ -22,7 +23,7 @@ export function behaviorpack_diagnose_entity_components( behaviorpack_entity_components_filters(container, diagnoser); } -const component_test: Record = { +const component_test: Record> = { "minecraft:economy_trade_table": check_trade_table, "minecraft:equipment": check_loot_table, "minecraft:loot": check_loot_table, diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/components/loot.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/components/loot.ts index 118bddb..7627519 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/components/loot.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/components/loot.ts @@ -1,9 +1,13 @@ -import { behaviorpack_loot_table_diagnose } from "../../Loot Table/diagnose"; import { DiagnosticsBuilder } from "../../../../Types"; -import { Context } from '../../../../utility/components'; - +import { Context } from "../../../../utility/components"; +import { behaviorpack_loot_table_diagnose } from "../../Loot Table/diagnose"; -export function check_loot_table(name: string, component: any, context: Context, diagnoser: DiagnosticsBuilder): void { +export function check_loot_table( + _name: string, + component: any, + _context: Context, + diagnoser: DiagnosticsBuilder +): void { if (component === undefined) return; if (typeof component.table !== "string") return; const table = component.table; diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/components/trade.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/components/trade.ts index f554527..e9be0ba 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/components/trade.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/components/trade.ts @@ -2,7 +2,7 @@ import { DiagnosticsBuilder } from "../../../../Types"; import { behaviorpack_trading_diagnose } from "../../Trading/diagnose"; import { Context } from '../../../../utility/components'; -export function check_trade_table(name: string, component: any, context: Context, diagnoser: DiagnosticsBuilder): void { +export function check_trade_table(_name: string, component: any, _context: Context, diagnoser: DiagnosticsBuilder): void { if (component === undefined) return; if (typeof component.table !== "string") return; const table = component.table; diff --git a/src/Lib/Diagnostics/BehaviorPack/Entity/entry.ts b/src/Lib/Diagnostics/BehaviorPack/Entity/entry.ts index 993c2fd..577eaf2 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Entity/entry.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Entity/entry.ts @@ -30,7 +30,8 @@ export function Diagnose(diagnoser: DocumentDiagnosticsBuilder): void { //No resource-pack check, entities can exist without their rp side //check components - const context: Context = { + const context: Context = { + source: entity, components: getUsedComponents(entity["minecraft:entity"]), }; diff --git a/src/Lib/Diagnostics/BehaviorPack/Item/components/dependencies.ts b/src/Lib/Diagnostics/BehaviorPack/Item/components/dependencies.ts index 15ffe96..7e1413e 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Item/components/dependencies.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Item/components/dependencies.ts @@ -21,7 +21,7 @@ const component_dependents_any: DependedMap = { * @param diagnoser The diagnoser to report to*/ export function behaviorpack_item_components_dependencies( item: Internal.BehaviorPack.Item, - context: Context, + context: Context, diagnoser: DiagnosticsBuilder ): void { components_dependencies("item", context, diagnoser, component_dependents_all, component_dependents_any); diff --git a/src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts b/src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts index 287d7a4..3dccf8b 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts @@ -1,11 +1,12 @@ +import { Internal } from "bc-minecraft-bedrock-project"; import { ComponentBehavior } from "bc-minecraft-bedrock-types/lib/minecraft/components"; import { DiagnosticSeverity, DocumentDiagnosticsBuilder } from "../../../../Types"; import { Context } from "../../../../utility/components"; import { component_error, ComponentCheck, components_check } from "../../../../utility/components/checks"; +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 { minecraft_get_item } from "../../../Minecraft/Items"; /** * @@ -15,13 +16,13 @@ import { minecraft_get_item } from "../../../Minecraft/Items"; */ export function behaviorpack_diagnose_item_components( container: ComponentBehavior, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder ): void { components_check(container, context, diagnoser, component_test); } -const component_test: Record = { +const component_test: Record> = { "minecraft:armor": deprecated_component("minecraft:wearable"), "minecraft:chargeable": deprecated_component("minecraft:custom_components"), "minecraft:creative_category": deprecated_component("description.menu_category"), diff --git a/src/Lib/Diagnostics/BehaviorPack/Item/entry.ts b/src/Lib/Diagnostics/BehaviorPack/Item/entry.ts index d44e727..add5434 100644 --- a/src/Lib/Diagnostics/BehaviorPack/Item/entry.ts +++ b/src/Lib/Diagnostics/BehaviorPack/Item/entry.ts @@ -14,7 +14,8 @@ export function Diagnose(diagnoser: DocumentDiagnosticsBuilder): void { if (!Internal.BehaviorPack.Item.is(item)) return; //Check components - const context: Context = { + const context: Context = { + source: item, components: getUsedComponents(item["minecraft:item"]), }; diff --git a/src/Lib/utility/components/checks.ts b/src/Lib/utility/components/checks.ts index 2ffa83c..2151429 100644 --- a/src/Lib/utility/components/checks.ts +++ b/src/Lib/utility/components/checks.ts @@ -2,25 +2,30 @@ import { ComponentBehavior, ComponentContainer } from "bc-minecraft-bedrock-type import { DocumentDiagnosticsBuilder, DiagnosticSeverity } from "../../Types"; import { Context } from "./components"; -export type ComponentCheck = (name: string, component: any, context: Context, diagnoser: DocumentDiagnosticsBuilder) => void; - -export function component_error(message: string, code: string | number): ComponentCheck { - return (name, component, context, diagnoser) => { +export type ComponentCheck = ( + name: string, + component: any, + context: Context, + diagnoser: DocumentDiagnosticsBuilder +) => void; + +export function component_error(message: string, code: string | number): ComponentCheck { + return (name, _component, _context, diagnoser) => { diagnoser.add(name, message, DiagnosticSeverity.error, code); }; } -export function component_warning(message: string, code: string | number): ComponentCheck { - return (name, component, context, diagnoser) => { +export function component_warning(message: string, code: string | number): ComponentCheck { + return (name, _component, _context, diagnoser) => { diagnoser.add(name, message, DiagnosticSeverity.warning, code); }; } -export function components_check( +export function components_check( data: ComponentBehavior | undefined, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder, - component_test: Record + component_test: Record> ): void { if (data === undefined) return; @@ -33,11 +38,11 @@ export function components_check( } } -function compContainerCheck( +function compContainerCheck( container: ComponentContainer | undefined, - context: Context, + context: Context, diagnoser: DocumentDiagnosticsBuilder, - component_test: Record + component_test: Record> ): void { if (container === undefined) return; diff --git a/src/Lib/utility/components/components.ts b/src/Lib/utility/components/components.ts index e17a3bc..1207292 100644 --- a/src/Lib/utility/components/components.ts +++ b/src/Lib/utility/components/components.ts @@ -6,10 +6,10 @@ export type DependedMap = Record; /** * */ -export interface Context { - /** - * - */ +export interface Context { + /** The object / item that defined or carries the components */ + source: Readonly; + /** The components used by the source collected from multiple sources */ components: string[]; } @@ -17,9 +17,9 @@ export interface Context { * @param entity The entity to check * @param entity The needed context * @param diagnoser The diagnoser to report to*/ -export function components_dependencies( +export function components_dependencies( owner: string, - context: Context, + context: Context, diagnoser: DiagnosticsBuilder, component_dependents_all: DependedMap, component_dependents_any: DependedMap