@@ -901,6 +901,26 @@ async function createMCFile(
901
901
}
902
902
}
903
903
904
+ function getFrame ( boneName : string , index : number ) {
905
+ const frame = animation . frames [ index ]
906
+ if ( ! frame ) return
907
+ let pos = frame . bones [ boneName ] . pos
908
+ pos = {
909
+ x : roundToN ( pos . x , 1000 ) ,
910
+ y : roundToN ( pos . y + headYOffset , 1000 ) ,
911
+ z : roundToN ( pos . z , 1000 ) ,
912
+ }
913
+
914
+ let rot = frame . bones [ boneName ] . rot
915
+ rot = {
916
+ x : roundToN ( rot . x , 1000 ) ,
917
+ y : roundToN ( rot . y , 1000 ) ,
918
+ z : roundToN ( rot . z , 1000 ) ,
919
+ }
920
+
921
+ return { pos, rot } as aj . AnimationFrameBone
922
+ }
923
+
904
924
function generateBoneTrees ( ) {
905
925
const animationTree = generateTree ( animation . frames )
906
926
if ( animationTree . type === 'leaf' )
@@ -1014,7 +1034,10 @@ async function createMCFile(
1014
1034
}
1015
1035
case 'leaf' :
1016
1036
const rot = getRot ( boneName , item )
1037
+ const nextFrame = getFrame ( boneName , item . index + 1 )
1017
1038
if ( isEqualVector ( rot , lastRot ) ) {
1039
+ // Ignore deduplication if next frame is different value
1040
+ if ( nextFrame && isEqualVector ( rot , nextFrame . rot ) )
1018
1041
return { v : '' , trimmed : true }
1019
1042
}
1020
1043
lastRot = rot
@@ -1053,7 +1076,8 @@ async function createMCFile(
1053
1076
# Add animation tag
1054
1077
tag @s add aj.${ projectName } .anim.${ animation . name }
1055
1078
# Reset animation time
1056
- scoreboard players set @s ${ scoreboards . frame } 0
1079
+ execute if score .aj.${ projectName } .framerate aj.i matches ..-1 run scoreboard players set @s ${ scoreboards . frame } ${ animation . frames . length }
1080
+ execute if score .aj.${ projectName } .framerate aj.i matches 1.. run scoreboard players set @s ${ scoreboards . frame } 0
1057
1081
# Assert that .noScripts is tracked properly
1058
1082
scoreboard players add .noScripts ${ scoreboards . internal } 0
1059
1083
# Start the animation loop if not running
@@ -1167,7 +1191,7 @@ async function createMCFile(
1167
1191
# Let the anim_loop know we're still running
1168
1192
scoreboard players set .aj.animation ${ scoreboards . animatingFlag } 1
1169
1193
# If (the next frame is the end of the animation) perform the necessary actions for the loop mode of the animation
1170
- execute unless score @s ${ scoreboards . frame } matches 1 ..${ animation . frames . length } run function ${ projectName } :animations/${ animation . name } /edge
1194
+ execute unless score @s ${ scoreboards . frame } matches 0 ..${ animation . frames . length } run function ${ projectName } :animations/${ animation . name } /edge
1171
1195
}`
1172
1196
)
1173
1197
0 commit comments