@@ -901,6 +901,26 @@ async function createMCFile(
901901 }
902902 }
903903
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+
904924 function generateBoneTrees ( ) {
905925 const animationTree = generateTree ( animation . frames )
906926 if ( animationTree . type === 'leaf' )
@@ -1014,7 +1034,10 @@ async function createMCFile(
10141034 }
10151035 case 'leaf' :
10161036 const rot = getRot ( boneName , item )
1037+ const nextFrame = getFrame ( boneName , item . index + 1 )
10171038 if ( isEqualVector ( rot , lastRot ) ) {
1039+ // Ignore deduplication if next frame is different value
1040+ if ( nextFrame && isEqualVector ( rot , nextFrame . rot ) )
10181041 return { v : '' , trimmed : true }
10191042 }
10201043 lastRot = rot
@@ -1053,7 +1076,8 @@ async function createMCFile(
10531076 # Add animation tag
10541077 tag @s add aj.${ projectName } .anim.${ animation . name }
10551078 # 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
10571081 # Assert that .noScripts is tracked properly
10581082 scoreboard players add .noScripts ${ scoreboards . internal } 0
10591083 # Start the animation loop if not running
@@ -1167,7 +1191,7 @@ async function createMCFile(
11671191 # Let the anim_loop know we're still running
11681192 scoreboard players set .aj.animation ${ scoreboards . animatingFlag } 1
11691193 # 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
11711195 }`
11721196 )
11731197
0 commit comments