Skip to content

Commit 1f41bf4

Browse files
committed
✨ Add as_camera function
1 parent a13998e commit 1f41bf4

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/pluginPackage/changelog.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
"Added a new function: `animated_java:<export_namespace>/at_all_locators {command: string}` that runs a command at all of a rig's entity-less locator positions.",
140140
"Added a new function: `animated_java:<export_namespace>/as_locator {name: string, command: string}` that runs a command as and at a named locator's entity.",
141141
"Added a new function: `animated_java:<export_namespace>/at_locator {name: string, command: string}` that runs a command at an entity-less locator's position.",
142+
"Added a new function: `animated_java:<export_namespace>/as_camera {name: string, command: string}` that runs a command as and at a camera's entity.",
142143
"Added a new function: `animated_java:<export_namespace>/remove/entities` that kills all entities owned by a rig, whether they are attached to a root entity or not.",
143144
"Added a new Blueprint setting: `On-Remove Commands`.",
144145
"Added support for `shadow_color` to JSON Text Components.",

src/systems/datapackCompiler/1.21.5/animation.mcb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,32 @@ dir <%export_namespace%> {
792792
}
793793
}
794794

795+
IF (has_cameras) {
796+
function as_camera {
797+
#ARGS: {name: string, command: string}
798+
IF (show_function_errors) {
799+
# Assert that the function is being run as the root entity.
800+
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
801+
function *global/errors/function_not_executed_as_root_entity \
802+
{'export_namespace': '<%export_namespace%>', 'function_path': '<%arguments[1].functions.at(-1)%>'}
803+
}
804+
data remove storage aj:temp args
805+
$data modify storage aj:temp args merge value {name:'$(name)', command:'$(command)'}
806+
$execute \
807+
on passengers \
808+
if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] \
809+
run block zzz/as_camera/as_data { {name: $(name)}
810+
data modify storage aj:temp args.uuid set from entity @s data.cameras.$(name)
811+
scoreboard players set #aj.check <%OBJECTIVES.I()%> 0
812+
block execute_as_uuid { with storage aj:temp args
813+
$execute as $(uuid) at @s run $(command)
814+
scoreboard players set #aj.check <%OBJECTIVES.I()%> 1
815+
}
816+
execute if score #aj.check <%OBJECTIVES.I()%> matches 0 run tellraw @a <%TELLRAW.CAMERA_NOT_FOUND_ENTITY()%>
817+
}
818+
}
819+
}
820+
795821
dir remove {
796822
function all {
797823
# Removes all instances of this rig from the world.

src/systems/datapackCompiler/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,19 @@ namespace TELLRAW {
634634
},
635635
TELLRAW_SUFFIX(),
636636
])
637+
export const CAMERA_NOT_FOUND_ENTITY = () =>
638+
new JsonText([
639+
TELLRAW_PREFIX(),
640+
{ text: 'Camera ', color: 'red' },
641+
{ nbt: 'args.name', storage: 'aj:temp', color: 'aqua' },
642+
{ text: ' not found!', color: 'red' },
643+
{
644+
text: "\nPlease ensure that it's name is spelled correctly.",
645+
color: 'gray',
646+
italic: true,
647+
},
648+
TELLRAW_SUFFIX(),
649+
])
637650
}
638651

639652
async function generateRootEntityPassengers(

test-packs/1.21.5/blueprints/armor_stand.ajblueprint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"meta": {
33
"format": "animated_java_blueprint",
4-
"format_version": "1.7.0",
4+
"format_version": "1.7.0-pre1",
55
"uuid": "167b27cd-b559-3f13-a97c-0841fe21f1d1",
66
"save_location": "D:\\github-repos\\animated-java\\animated-java\\test-packs\\1.21.5\\blueprints\\armor_stand.ajblueprint",
77
"last_used_export_namespace": "armor_stand"

0 commit comments

Comments
 (0)