|
1 | 1 | package birsy.clinker.client.entity.gnomad.basic; |
2 | 2 |
|
| 3 | +import birsy.clinker.client.entity.gnomad.mogul.GnomadMogulAnimator; |
| 4 | +import birsy.clinker.client.entity.gnomad.mogul.GnomadMogulSkeleton; |
| 5 | +import birsy.clinker.common.world.entity.gnomad.mogul.GnomadMogulEntity; |
3 | 6 | import birsy.clinker.common.world.entity.gnomad.testing.SquadTestingThrowerEntity; |
| 7 | +import foundry.veil.api.client.necromancer.animation.Animation; |
4 | 8 | import foundry.veil.api.client.necromancer.animation.Animator; |
5 | 9 | import net.minecraft.core.Direction; |
6 | 10 | import net.minecraft.util.Mth; |
7 | 11 |
|
| 12 | +import static net.minecraft.core.Direction.Axis.*; |
| 13 | +import static birsy.clinker.client.AnimationUtilities.*; |
| 14 | + |
| 15 | + |
8 | 16 | public class GnomadAnimator extends Animator<SquadTestingThrowerEntity, GnomadSkeleton> { |
| 17 | + public final AnimationEntry<?, ?> idleAnim, walkAnim, strafeAnim; |
9 | 18 | protected GnomadAnimator(SquadTestingThrowerEntity parent, GnomadSkeleton skeleton) { |
10 | 19 | super(parent, skeleton); |
| 20 | + this.idleAnim = this.addAnimation(IdleAnimation.INSTANCE, 0); |
| 21 | + this.walkAnim = this.addAnimation(WalkAnimation.INSTANCE, 1); |
| 22 | + this.strafeAnim = this.addAnimation(StrafeAnimation.INSTANCE, 2); |
11 | 23 | } |
12 | 24 |
|
13 | 25 | @Override |
14 | 26 | public void animate() { |
15 | 27 | super.animate(); |
16 | 28 | SquadTestingThrowerEntity entity = this.parent; |
17 | 29 |
|
18 | | - float bodyYaw = Mth.wrapDegrees(180 - entity.yBodyRot); |
19 | | - float headYaw = Mth.wrapDegrees(180 - entity.yHeadRot); |
20 | | - float netHeadYaw = Mth.degreesDifference(bodyYaw, headYaw); |
21 | | - netHeadYaw = Mth.clamp(netHeadYaw, -80, 80); |
22 | | - float headPitch = -entity.getViewXRot(1.0F); |
23 | | - skeleton.root.rotateDeg(bodyYaw, Direction.Axis.Y); |
24 | | - skeleton.neck.rotateDeg(netHeadYaw, Direction.Axis.Y); |
25 | | - skeleton.head.rotateDeg(headPitch, Direction.Axis.X); |
| 30 | + this.idleAnim.setMixFactor(1.0F); |
| 31 | + this.idleAnim.setTime(entity.tickCount); |
| 32 | + |
| 33 | + float moveTime = entity.getCumulativeLocomotionAmount() * 1.5F; |
| 34 | + |
| 35 | + float walkFac = Mth.clamp(12 * entity.getForwardLocomotionAmount(1.0F), -2.0F, 2.0F); |
| 36 | + this.walkAnim.setMixFactor(walkFac); |
| 37 | + this.walkAnim.setTime(moveTime); |
| 38 | + |
| 39 | + float strafeFac = Mth.clamp(12 * entity.getStrafeLocomotionAmount(1.0F), -2.0F, 2.0F); |
| 40 | + this.strafeAnim.setMixFactor(strafeFac); |
| 41 | + this.strafeAnim.setTime(moveTime); |
| 42 | + |
| 43 | + // flinch |
| 44 | + if (entity.hurtDuration > 0) { |
| 45 | + float flinchTime = entity.tickCount * 0.9F; |
| 46 | + float flinchFactor = (float) entity.hurtTime / entity.hurtDuration; |
| 47 | + skeleton.root.rotateDeg(Mth.sin(flinchTime) * 8 * flinchFactor, Direction.Axis.X); |
| 48 | + skeleton.root.rotateDeg(Mth.cos(flinchTime) * 8 * flinchFactor, Direction.Axis.Z); |
| 49 | + |
| 50 | + skeleton.head.rotateDeg(Mth.sin(flinchTime - 1) * 8 * flinchFactor, Direction.Axis.X); |
| 51 | + skeleton.head.rotateDeg(Mth.cos(flinchTime - 1) * 8 * flinchFactor, Direction.Axis.Z); |
| 52 | + |
| 53 | + skeleton.rightArm.rotateDeg(Mth.sin(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.X); |
| 54 | + skeleton.rightArm.rotateDeg(Mth.cos(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.Z); |
| 55 | + skeleton.leftArm.rotateDeg(Mth.sin(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.X); |
| 56 | + skeleton.leftArm.rotateDeg(Mth.cos(flinchTime - 1) * -15 * flinchFactor, Direction.Axis.Z); |
| 57 | + |
| 58 | + skeleton.leftLeg.rotateDeg(Mth.sin(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.X); |
| 59 | + skeleton.leftLeg.rotateDeg(Mth.cos(flinchTime - 1) * -15 * flinchFactor, Direction.Axis.Z); |
| 60 | + skeleton.rightLeg.rotateDeg(Mth.sin(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.X); |
| 61 | + skeleton.rightLeg.rotateDeg(Mth.cos(flinchTime - 1) * 15 * flinchFactor, Direction.Axis.Z); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + private static class IdleAnimation extends Animation<SquadTestingThrowerEntity, GnomadSkeleton> { |
| 66 | + protected static IdleAnimation INSTANCE = new IdleAnimation(); |
| 67 | + |
| 68 | + public void apply(SquadTestingThrowerEntity entity, GnomadSkeleton skeleton, float mixFactor, float time) { |
| 69 | + float bodyYaw = Mth.wrapDegrees(180 - entity.yBodyRot); |
| 70 | + float headYaw = Mth.wrapDegrees(180 - entity.yHeadRot); |
| 71 | + float netHeadYaw = Mth.degreesDifference(bodyYaw, headYaw); |
| 72 | + netHeadYaw = Mth.clamp(netHeadYaw, -80, 80); |
| 73 | + float headPitch = -entity.getViewXRot(1.0F); |
| 74 | + skeleton.root.rotateDeg(bodyYaw, Y); |
| 75 | + skeleton.neck.rotateDeg(netHeadYaw, Y); |
| 76 | + skeleton.head.rotateDeg(headPitch, X); |
| 77 | + |
| 78 | + float torsoRotation = -5; |
| 79 | + skeleton.torso.rotateDeg(torsoRotation, X); |
| 80 | + skeleton.torso.rotation.conjugate(skeleton.skirt.rotation); |
| 81 | + |
| 82 | + skeleton.rightArm.rotateDeg(-torsoRotation, X); |
| 83 | + skeleton.leftArm.rotateDeg(-torsoRotation, X); |
| 84 | + skeleton.rightArm.rotateDeg(5, Z); |
| 85 | + skeleton.leftArm.rotateDeg(-5, Z); |
| 86 | + |
| 87 | + float neckRotation = 10; |
| 88 | + skeleton.neck.rotateDeg(-torsoRotation + neckRotation, X); |
| 89 | + skeleton.headJoint.rotateDeg(-neckRotation, X); |
| 90 | + |
| 91 | + float speed = 1.0F / 40.0F; |
| 92 | + float degree = 1.0F; |
| 93 | + |
| 94 | + skeleton.rightArm.rotateDeg(nSin(time * speed * 1.0F) * 1 * mixFactor * degree, Z); |
| 95 | + skeleton.rightArm.rotateDeg(nSin(time * speed * 0.9F) * 1 * mixFactor * degree, X); |
| 96 | + |
| 97 | + skeleton.leftArm.rotateDeg(nSin(time * speed * 0.85F) * 1 * mixFactor * degree, Z); |
| 98 | + skeleton.leftArm.rotateDeg(nSin(time * speed * 0.95F) * 1 * mixFactor * degree, X); |
| 99 | + |
| 100 | + skeleton.torso.offsetY(nSin(time * speed * 0.7F) * 0.2F * mixFactor * degree); |
| 101 | + |
| 102 | + skeleton.nose.rotateDeg(nSin(time * speed * 0.85F) * 1 * mixFactor * degree, Z); |
| 103 | + skeleton.nose.rotateDeg(nSin(time * speed * 0.95F) * 1 * mixFactor * degree, X); |
| 104 | + |
| 105 | + skeleton.neck.rotateDeg(nSin(time * speed * 0.6F) * 1 * mixFactor * degree, Z); |
| 106 | + skeleton.neck.rotateDeg(nSin(time * speed * 0.5F) * 1 * mixFactor * degree, X); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + private static class WalkAnimation extends Animation<SquadTestingThrowerEntity, GnomadSkeleton> { |
| 111 | + protected static WalkAnimation INSTANCE = new WalkAnimation(); |
| 112 | + |
| 113 | + @Override |
| 114 | + public boolean running(SquadTestingThrowerEntity entity, GnomadSkeleton skeleton, float mixFactor, float time) { |
| 115 | + return mixFactor != 0; |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public void apply(SquadTestingThrowerEntity entity, GnomadSkeleton skeleton, float mixFactor, float time) { |
| 120 | + float degree = 1.0F; |
| 121 | + float sign = Mth.sign(mixFactor); |
| 122 | + mixFactor = Mth.abs(mixFactor); |
| 123 | + |
| 124 | + // bounce mix factor decreases with speed... |
| 125 | + float bounceMixFactor = mixFactor; |
| 126 | + if (mixFactor > 1.0F) bounceMixFactor = Mth.clampedMap(bounceMixFactor, 1.0F, 3.0F, mixFactor, 0); |
| 127 | + // squared mix factor really emphasizes movements when running |
| 128 | + float squaredMixFactor = mixFactor * mixFactor; |
| 129 | + |
| 130 | + skeleton.root.offsetY(Math.abs(nSin(time + 0.5F)) * 1.0F * bounceMixFactor * degree); |
| 131 | + skeleton.root.offsetX(nSin(time * 2) * 0.5F * bounceMixFactor * sign * degree); |
26 | 132 |
|
27 | | - float torsoRotation = -5; |
28 | | - skeleton.torso.rotateDeg(torsoRotation, Direction.Axis.X); |
29 | | - skeleton.torso.rotation.conjugate(skeleton.skirt.rotation); |
| 133 | + skeleton.root.rotateDeg(nSin(time) * 1 * bounceMixFactor * sign * degree, Z); |
30 | 134 |
|
31 | | - skeleton.rightArm.rotateDeg(-torsoRotation, Direction.Axis.X); |
32 | | - skeleton.leftArm.rotateDeg(-torsoRotation, Direction.Axis.X); |
33 | | - skeleton.rightArm.rotateDeg(5, Direction.Axis.Z); |
34 | | - skeleton.leftArm.rotateDeg(-5, Direction.Axis.Z); |
| 135 | + skeleton.rightLeg.offsetZ(nSin(time) * -2 * mixFactor * sign * degree); |
| 136 | + skeleton.rightLeg.offsetY(nSin(time + 0.5F) * 1 * mixFactor * degree); |
| 137 | + skeleton.rightLeg.rotateDeg(nSin(time) * 15 * mixFactor * sign * degree, X); |
35 | 138 |
|
36 | | - float neckRotation = 10; |
37 | | - skeleton.neck.rotateDeg(-torsoRotation + neckRotation, Direction.Axis.X); |
38 | | - skeleton.headJoint.rotateDeg(-neckRotation, Direction.Axis.X); |
| 139 | + skeleton.leftLeg.offsetZ(-nSin(time) * -2 * mixFactor * sign * degree); |
| 140 | + skeleton.leftLeg.offsetY(-nSin(time + 0.5F) * 1 * mixFactor * degree); |
| 141 | + skeleton.leftLeg.rotateDeg(-nSin(time) * 15 * mixFactor * sign * degree, X); |
39 | 142 |
|
| 143 | + skeleton.rightArm.rotateDeg(nSin(time + 0.2F) * -12 * squaredMixFactor * sign * degree, X); |
| 144 | + skeleton.leftArm.rotateDeg(-nSin(time + 0.2F) * -12 * squaredMixFactor * sign * degree, X); |
40 | 145 |
|
| 146 | + skeleton.rightArm.offsetY(nSin(time * 2 + 0.2F) * 0.1F * bounceMixFactor * degree); |
| 147 | + skeleton.leftArm .offsetY(nSin(time * 2 + 0.2F) * 0.1F * bounceMixFactor * degree); |
| 148 | + |
| 149 | + skeleton.neck.offsetY(nSin(time * 2 + 0.15F) * 0.15F * bounceMixFactor * degree); |
| 150 | + skeleton.head.offsetY(nSin(time * 2 + 0.30F) * 0.1F * bounceMixFactor * degree); |
| 151 | + |
| 152 | + skeleton.bag.offsetY(nSin(time * 2 + 0.4F) * 0.1F * bounceMixFactor * degree); |
| 153 | + |
| 154 | + float torsoAngle = -3.0F * squaredMixFactor * degree * sign; |
| 155 | + skeleton.torso.rotateDeg(torsoAngle, X); |
| 156 | + skeleton.skirt.rotateDeg(-torsoAngle, X); |
| 157 | + } |
41 | 158 | } |
| 159 | + |
| 160 | + private static class StrafeAnimation extends Animation<SquadTestingThrowerEntity, GnomadSkeleton> { |
| 161 | + protected static StrafeAnimation INSTANCE = new StrafeAnimation(); |
| 162 | + |
| 163 | + @Override |
| 164 | + public boolean running(SquadTestingThrowerEntity entity, GnomadSkeleton skeleton, float mixFactor, float time) { |
| 165 | + return mixFactor != 0; |
| 166 | + } |
| 167 | + |
| 168 | + @Override |
| 169 | + public void apply(SquadTestingThrowerEntity entity, GnomadSkeleton skeleton, float mixFactor, float time) { |
| 170 | + float degree = 1.0F; |
| 171 | + float sign = Mth.sign(mixFactor); |
| 172 | + mixFactor = Mth.abs(mixFactor); |
| 173 | + |
| 174 | + float bounceMixFactor = mixFactor; |
| 175 | + if (mixFactor > 1.0F) bounceMixFactor = Mth.clampedMap(bounceMixFactor, 1.0F, 3.0F, mixFactor, 0); |
| 176 | + |
| 177 | + skeleton.root.rotateDeg(-2 * mixFactor * sign * degree, Z); |
| 178 | + skeleton.neck.rotateDeg(2 * mixFactor * sign * degree, Z); |
| 179 | + skeleton.bag.rotateDeg(2 * mixFactor * sign * degree, Z); |
| 180 | + |
| 181 | + skeleton.root.offsetY(Math.abs(nSin(time + 0.5F)) * 0.5F * bounceMixFactor * degree); |
| 182 | + skeleton.root.rotateDeg(nSin(time) * 1 * bounceMixFactor * sign * degree, Z); |
| 183 | + |
| 184 | + skeleton.rightLeg.offsetX(nSin(time) * 1 * mixFactor * sign * degree); |
| 185 | + skeleton.rightLeg.offsetY(nSin(time + 0.5F) * 1 * mixFactor * degree); |
| 186 | + skeleton.rightLeg.rotateDeg(nSin(time) * 10 * mixFactor * sign * degree, Z); |
| 187 | + |
| 188 | + skeleton.leftLeg.offsetX(-nSin(time) * 1 * mixFactor * sign * degree); |
| 189 | + skeleton.leftLeg.offsetY(-nSin(time + 0.5F) * 1 * mixFactor * degree); |
| 190 | + skeleton.leftLeg.rotateDeg(-nSin(time) * 10 * mixFactor * sign * degree, Z); |
| 191 | + |
| 192 | + float armSwingMixFactor = mixFactor * mixFactor; |
| 193 | + skeleton.rightArm.rotateDeg(nSin(time + 0.2F) * -10 * armSwingMixFactor * sign * degree, X); |
| 194 | + skeleton.leftArm.rotateDeg(-nSin(time + 0.2F) * -10 * armSwingMixFactor * sign * degree, X); |
| 195 | + |
| 196 | + skeleton.neck.offsetY(nSin(time * 2 + 0.15F) * 0.10F * bounceMixFactor * degree); |
| 197 | + skeleton.head.offsetY(nSin(time * 2 + 0.30F) * 0.05F * bounceMixFactor * degree); |
| 198 | + skeleton.bag.offsetY(nSin(time * 2 + 0.4F) * 0.1F * bounceMixFactor * degree); |
| 199 | + } |
| 200 | + } |
| 201 | + |
42 | 202 | } |
0 commit comments