Skip to content

Commit

Permalink
- Account for block references being objects of format {"name": "value"}
Browse files Browse the repository at this point in the history
  • Loading branch information
Xterionix committed Nov 17, 2024
1 parent 3ead79e commit b34f713
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 12 additions & 11 deletions src/Lib/Diagnostics/BehaviorPack/Block/components/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,22 @@ const component_test: Record<string, ComponentCheck> = {
const destroyTime = component.seconds_to_destroy;
if (!destroyTime) return;
component.item_specific_speeds?.forEach((specific_speed: any) => {
if (specific_speed.destroy_speed && specific_speed.destroy_speed > destroyTime) {
diagnoser.add(
specific_speed.destroy_speed,
`Item specific destroy speed ${specific_speed.destroy_speed} cannot be higher than block's destroy time ${destroyTime}`,
DiagnosticSeverity.error,
"behaviorpack.block.components.fast_break_speed"
);
return false;
}
if (specific_speed.destroy_speed && specific_speed.destroy_speed > destroyTime) {
diagnoser.add(
specific_speed.destroy_speed,
`Item specific destroy speed ${specific_speed.destroy_speed} cannot be higher than block's destroy time ${destroyTime}`,
DiagnosticSeverity.error,
"behaviorpack.block.components.fast_break_speed"
);
return false;
}
});
},
"minecraft:placement_filter": (name, component, context, diagnoser) => {
for (const condition of component.conditions) {
condition.block_filter?.forEach((block: string) => {
behaviorpack_check_blockid(block, diagnoser);
condition.block_filter?.forEach((block: string | object) => {
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid((block as { name: string }).name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
}
},
Expand Down
14 changes: 10 additions & 4 deletions src/Lib/Diagnostics/BehaviorPack/Item/components/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,26 @@ const component_test: Record<string, ComponentCheck> = {
"minecraft:entity_placer": (name, component, context, diagnoser) => {
if (Array.isArray(component.dispense_on))
component.dispense_on.forEach((block: string) => {
behaviorpack_check_blockid(block, diagnoser);
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid((block as { name: string }).name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
if (Array.isArray(component.use_on))
component.use_on.forEach((block: string) => {
behaviorpack_check_blockid(block, diagnoser);
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid((block as { name: string }).name, 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) => {
behaviorpack_check_blockid(block, diagnoser);
if (typeof block == 'object' && 'name' in block) behaviorpack_check_blockid((block as { name: string }).name, diagnoser)
else if (typeof block == 'string') behaviorpack_check_blockid(block, diagnoser);
});
if (component.block) behaviorpack_check_blockid(component.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);
}
},
"minecraft:projectile": (name, component, context, diagnoser) => {
if (component.projectile_entity) behaviorpack_entityid_diagnose(component.projectile_entity, diagnoser);
Expand Down

0 comments on commit b34f713

Please sign in to comment.