Skip to content

Commit b57dc7e

Browse files
committed
✨ Locator entity selector functions
- Added `as_locator` {name: string, command: string} - Added `at_locator` {name: string, command: string} - Added `at_all_locators` {command: string}
1 parent e5fa970 commit b57dc7e

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

src/systems/datapackCompiler/1.21.5/animation.mcb

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,19 @@ dir <%export_namespace%> {
705705
function *global/errors/function_not_executed_as_root_entity \
706706
{'export_namespace': '<%export_namespace%>', 'function_path': '<%arguments[1].functions.at(-1)%>'}
707707
}
708-
$data modify storage aj:temp args.command set value '$(command)'
708+
data remove storage aj:temp args
709+
$data modify storage aj:temp args merge value {name:'$(name)', command:'$(command)'}
709710
$execute \
710711
on passengers \
711712
if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
712713
run block zzz/as_locator/as_data { {name: $(name)}
713714
$data modify storage aj:temp args.uuid set from entity @s data.uuids.locator_$(name)
715+
scoreboard players set #aj.check <%OBJECTIVES.I()%> 0
714716
block execute_as_uuid { with storage aj:temp args
715-
$execute as $(uuid) run $(command)
717+
$execute as $(uuid) at @s run $(command)
718+
scoreboard players set #aj.check <%OBJECTIVES.I()%> 1
716719
}
720+
execute if score #aj.check <%OBJECTIVES.I()%> matches 0 run tellraw @a <%TELLRAW.LOCATOR_NOT_FOUND_ENTITY()%>
717721
}
718722
}
719723

@@ -731,7 +735,57 @@ dir <%export_namespace%> {
731735
REPEAT (Object.values(rig.nodes).filter(v => v.type === 'locator' && v.config?.use_entity)) as locator {
732736
data modify storage aj:temp args.uuid set from entity @s data.uuids.<%locator.type + '_' + locator.name%>
733737
block execute_as_uuid { with storage aj:temp args
734-
$execute as $(uuid) run $(command)
738+
$execute as $(uuid) at @s run $(command)
739+
}
740+
}
741+
}
742+
}
743+
}
744+
745+
IF (has_locators) {
746+
function at_locator {
747+
#ARGS: {name: string, command: string}
748+
IF (show_function_errors) {
749+
# Assert that the function is being run as the root entity.
750+
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
751+
function *global/errors/function_not_executed_as_root_entity \
752+
{'export_namespace': '<%export_namespace%>', 'function_path': '<%arguments[1].functions.at(-1)%>'}
753+
}
754+
data remove storage aj:temp args
755+
$data modify storage aj:temp args merge value {name:'$(name)', command:'$(command)'}
756+
$execute \
757+
on passengers \
758+
if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
759+
run block zzz/at_locator/as_data { {name: $(name)}
760+
$execute unless data entity @s {data:{locators:{$(name):{}}}} run return run tellraw @a <%TELLRAW.LOCATOR_NOT_FOUND()%>
761+
$data modify storage aj:temp args merge from entity @s data.locators.$(name)
762+
block execute_at_transform { with storage aj:temp args
763+
$execute \
764+
positioned ^$(posx) ^$(posy) ^$(posz) \
765+
rotated ~$(roty) ~$(rotx) \
766+
run $(command)
767+
}
768+
}
769+
}
770+
771+
function at_all_locators {
772+
#ARGS: {command: string}
773+
IF (show_function_errors) {
774+
# Assert that the function is being run as the root entity.
775+
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
776+
function *global/errors/function_not_executed_as_root_entity \
777+
{'export_namespace': '<%export_namespace%>', 'function_path': '<%arguments[1].functions.at(-1)%>'}
778+
}
779+
data remove storage aj:temp args
780+
$data modify storage aj:temp args.command set value '$(command)'
781+
execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block zzz/at_all_locators/as_data {
782+
REPEAT (Object.values(rig.nodes).filter(v => v.type === 'locator' && v.config?.use_entity)) as locator {
783+
data modify storage aj:temp args merge from entity @s data.locators.<%locator.name%>
784+
block execute_at_transform { with storage aj:temp args
785+
$execute \
786+
positioned ^$(posx) ^$(posy) ^$(posz) \
787+
rotated ~$(roty) ~$(rotx) \
788+
run $(command)
735789
}
736790
}
737791
}

src/systems/datapackCompiler/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,42 @@ namespace TELLRAW {
598598
},
599599
TELLRAW_SUFFIX(),
600600
])
601+
export const LOCATOR_NOT_FOUND = () =>
602+
new JsonText([
603+
TELLRAW_PREFIX(),
604+
{ text: 'Locator ', color: 'red' },
605+
{ nbt: 'args.name', storage: 'aj:temp', color: 'aqua' },
606+
{ text: ' not found!', color: 'red' },
607+
{
608+
text: "\nPlease ensure that it's name is spelled correctly.",
609+
color: 'gray',
610+
italic: true,
611+
},
612+
TELLRAW_SUFFIX(),
613+
])
614+
export const LOCATOR_NOT_FOUND_ENTITY = () =>
615+
new JsonText([
616+
TELLRAW_PREFIX(),
617+
{ text: 'Locator ', color: 'red' },
618+
{ nbt: 'args.name', storage: 'aj:temp', color: 'aqua' },
619+
{ text: ' not found!', color: 'red' },
620+
{
621+
text: '\nPlease ensure that the locator has ',
622+
color: 'gray',
623+
italic: true,
624+
},
625+
{
626+
text: 'Use Entity',
627+
color: 'yellow',
628+
italic: true,
629+
},
630+
{
631+
text: " enabled in it's config, and it's name is spelled correctly.",
632+
color: 'gray',
633+
italic: true,
634+
},
635+
TELLRAW_SUFFIX(),
636+
])
601637
}
602638

603639
async function generateRootEntityPassengers(

0 commit comments

Comments
 (0)