Skip to content

Commit b3c520d

Browse files
committed
Fully functional move function
1 parent 45c303e commit b3c520d

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/exporters/animationExporter.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ async function createMCFile(
717717
execute as @e[type=${entityTypes.boneRoot},tag=${tags.allBones},distance=..${maxDistance}] if score @s ${scoreboards.id} = .this ${scoreboards.id} run {
718718
${baseModifiers.join('\n')}
719719
execute store result score .calc ${scoreboards.internal} run data get entity @s Air
720-
execute store result entity @s Air short 1 run scoreboard players add .calc ${scoreboards.internal} 1
720+
execute store result entity @s Air short 1 run scoreboard players add .calc ${scoreboards.internal} 2
721721
}
722722
execute as @e[type=${entityTypes.boneDisplay},tag=${tags.allBones},distance=..${maxDistance}] if score @s ${scoreboards.id} = .this ${scoreboards.id} run {
723723
${displayModifiers.join('\n')}
@@ -732,6 +732,44 @@ async function createMCFile(
732732
`)
733733
}
734734

735+
{
736+
//? Move Function
737+
// prettier-ignore
738+
FILE.push(`function move {
739+
# Make sure this function has been ran as the root entity
740+
execute(if entity @s[tag=${tags.root}] rotated ~ 0) {
741+
tp @s ~ ~ ~ ~ ~
742+
scoreboard players operation .this ${scoreboards.id} = @s ${scoreboards.id}
743+
scoreboard players operation .this ${scoreboards.frame} = @s ${scoreboards.frame}
744+
745+
# Split based on animation name
746+
scoreboard players set # ${scoreboards.internal} 0
747+
${Object.values(animations).map(animation => `execute if entity @s[tag=aj.${projectName}.anim.${animation.name}] run {
748+
scoreboard players set # ${scoreboards.internal} 1
749+
# Select bone entities
750+
execute at @s as @e[type=${entityTypes.bone},tag=${tags.allBones}] if score @s ${scoreboards.id} = .this ${scoreboards.id} run {
751+
# Split based on bone entity type
752+
execute if entity @s[type=${entityTypes.boneRoot}] run {
753+
# Run root animation frame tree
754+
function ${projectName}:animations/${animation.name}/tree/root_bone_name
755+
execute store result score .calc ${scoreboards.internal} run data get entity @s Air
756+
execute store result entity @s Air short 1 run scoreboard players add .calc ${scoreboards.internal} 2
757+
}
758+
execute if entity @s[type=${entityTypes.boneDisplay}] run tp @s ~ ~ ~ ~ ~
759+
}
760+
}`).join('\n')}
761+
execute if score # ${scoreboards.internal} matches 0 run {
762+
execute at @s as @e[type=${entityTypes.boneRoot},tag=${tags.allBones}] if score @s ${scoreboards.id} = .this ${scoreboards.id} run tp @s ~ ~ ~
763+
function ${projectName}:reset
764+
}
765+
766+
# If this entity is not the root
767+
} else {
768+
tellraw @s ${rootExeErrorJsonText.replace('%functionName',`${projectName}:move`)}
769+
}
770+
}`)
771+
}
772+
735773
{
736774
//? Animation Loop function
737775
// prettier-ignore
@@ -763,30 +801,6 @@ async function createMCFile(
763801
`)
764802
}
765803

766-
{
767-
// Move Function
768-
FILE.push(`function move {
769-
# Make sure this function has been ran as the root entity
770-
execute(if entity @s[tag=${tags.root}] at @s rotated ~ 0) {
771-
tp @e[type=${entityTypes.boneRoot}] ~ ~ ~ ~ ~
772-
773-
scoreboard players set # aj.i 0
774-
${Object.values(animations).map(animation => `execute if entity @s[tag=aj.${projectName}.anim.${animation.name}] run {
775-
function ${projectName}:animations/${animation.name}/next_frame
776-
scoreboard players set # aj.i 1
777-
}`).join('\n')}
778-
execute if score # aj.i matches 0 run function ${projectName}:reset
779-
780-
# If this entity is not the root
781-
} else {
782-
tellraw @s ${rootExeErrorJsonText.replace(
783-
'%functionName',
784-
`${projectName}:move`
785-
)}
786-
}
787-
}`)
788-
}
789-
790804
{
791805
//? Animations
792806
if (!Object.keys(animations).length) {

0 commit comments

Comments
 (0)