diff --git a/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java b/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java index 0a98de1..dc00791 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/AnimationOverhaulMain.java @@ -1,14 +1,12 @@ package com.trainguy9512.animationoverhaul; -import com.trainguy9512.animationoverhaul.animation.LivingEntityAnimatorRegistry; -import com.trainguy9512.animationoverhaul.animation.animator.entity.PlayerJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.JointAnimatorRegistry; +import com.trainguy9512.animationoverhaul.animation.animator.entity.FirstPersonPlayerJointAnimator; import com.trainguy9512.animationoverhaul.animation.data.AnimationSequenceDataLoader; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.minecraft.server.packs.PackType; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,9 +18,6 @@ public class AnimationOverhaulMain implements ModInitializer { public static Logger LOGGER = LogManager.getLogger(); - public static final LivingEntityAnimatorRegistry ENTITY_ANIMATORS = new LivingEntityAnimatorRegistry(); - public static Entity debugEntity; - public static void onClientInit() { registerTimelineGroupLoader(); @@ -55,7 +50,7 @@ public void onInitialize() { private static void registerEntityAnimators(){ - ENTITY_ANIMATORS.register(EntityType.PLAYER, new PlayerJointAnimator()); + JointAnimatorRegistry.registerFirstPersonPlayerJointAnimator(new FirstPersonPlayerJointAnimator()); } /* diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java deleted file mode 100644 index e97bb27..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.trainguy9512.animationoverhaul.animation; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; - -import java.util.HashMap; -import java.util.Map; - -public class LivingEntityAnimatorRegistry { - - private final HashMap, EntityJointAnimator> livingEntityPartAnimatorHashMap; - - public LivingEntityAnimatorRegistry(){ - this.livingEntityPartAnimatorHashMap = Maps.newHashMap(); - } - - public void register(EntityType entityType, EntityJointAnimator livingEntityPartAnimator){ - livingEntityPartAnimatorHashMap.put(entityType, livingEntityPartAnimator); - } - - public boolean contains(EntityType entityType){ - return livingEntityPartAnimatorHashMap.containsKey(entityType); - } - - public EntityJointAnimator get(EntityType entityType){ - return this.livingEntityPartAnimatorHashMap.get(entityType); - } -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java index a151847..e92b87e 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimator.java @@ -9,41 +9,26 @@ * Uses a data reference and a joint skeleton to calculate a pose once per tick. * @param Object used for data reference */ -public abstract class JointAnimator { - - protected final JointSkeleton jointSkeleton; - - protected JointAnimator() { - this.jointSkeleton = buildSkeleton(); - } - - /** - * Returns the joint skeleton used by the animator as reference. - * @return Joint skeleton - */ - public JointSkeleton getJointSkeleton(){ - return this.jointSkeleton; - } +public interface JointAnimator { /** - * Retrieves a joint skeleton created upon class construction - * @return Built joint skeleton + * Creates a joint skeleton created upon class construction + * @return Built joint skeleton */ - protected abstract JointSkeleton buildSkeleton(); + public JointSkeleton buildSkeleton(); /** * Uses an object for data reference and updates the animation data container. Called once per tick, prior to pose samplers updating and pose calculation. - * @param dataReference Object used as reference for updating the animation data container - * @param animationDriverContainer Data container from the previous tick - * @return Resulting data container + * @param dataReference Object used as reference for updating the animation data container + * @param animationDriverContainer Data container from the previous tick */ - public abstract AnimationDriverContainer extractAnimationData(T dataReference, AnimationDriverContainer animationDriverContainer); + public abstract void extractAnimationData(T dataReference, AnimationDriverContainer animationDriverContainer); /** * Calculates and returns an animation pose once per tick, after pose sampler update and animation data extraction - * @param animationDriverContainer Data container containing extracted animation variable data. - * @param poseSamplerStateContainer Data container containing pose sampler states, used for sampling poses. - * @return Calculated animation pose to be passed off to the baked animation pose + * @param animationDriverContainer Data container containing extracted animation variable data. + * @param poseSamplerStateContainer Data container containing pose sampler states, used for sampling poses. + * @return Calculated animation pose to be passed off to the baked animation pose */ - public abstract AnimationPose calculatePose(AnimationDriverContainer animationDriverContainer, PoseSamplerStateContainer poseSamplerStateContainer); + public abstract AnimationPose calculatePose(AnimationDriverContainer animationDriverContainer, PoseSamplerStateContainer poseSamplerStateContainer, JointSkeleton jointSkeleton); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimatorRegistry.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimatorRegistry.java new file mode 100644 index 0000000..c219022 --- /dev/null +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/JointAnimatorRegistry.java @@ -0,0 +1,83 @@ +package com.trainguy9512.animationoverhaul.animation.animator; + +import com.google.common.collect.Maps; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; + +public class JointAnimatorRegistry { + + private static final HashMap, EntityJointAnimator> THIRD_PERSON_ENTITY_JOINT_ANIMATORS = Maps.newHashMap(); + private static final HashMap, JointSkeleton> THIRD_PERSON_ENTITY_JOINT_SKELETONS = Maps.newHashMap(); + + private static LivingEntityJointAnimator FIRST_PERSON_PLAYER_JOINT_ANIMATOR = null; + private static JointSkeleton FIRST_PERSON_PLAYER_JOINT_SKELETON = null; + + /** + * Registers a joint animator for use on third person living entities. + * @param entityType Type of entity associated with the living entity + * @param entityJointAnimator Newly constructed entity joint animator object + */ + public static void registerEntityJointAnimator(EntityType entityType, EntityJointAnimator entityJointAnimator){ + THIRD_PERSON_ENTITY_JOINT_ANIMATORS.put(entityType, entityJointAnimator); + THIRD_PERSON_ENTITY_JOINT_SKELETONS.put(entityType, entityJointAnimator.buildSkeleton()); + } + + + public static void registerFirstPersonPlayerJointAnimator(LivingEntityJointAnimator firstPersonPlayerJointAnimator){ + FIRST_PERSON_PLAYER_JOINT_ANIMATOR = firstPersonPlayerJointAnimator; + FIRST_PERSON_PLAYER_JOINT_SKELETON = firstPersonPlayerJointAnimator.buildSkeleton(); + } + + /** + * Returns whether the provided entity type has a registered joint animator. + * @param entityType Entity type + */ + public static boolean entityTypeRegisteredWithJointAnimator(EntityType entityType){ + return THIRD_PERSON_ENTITY_JOINT_ANIMATORS.containsKey(entityType); + } + + /** + * Returns the entity joint animator for the provided entity type. If the entity type does not have a joint animator registered, null is returned. + * @param entityType Entity type + * @return Entity joint animator + */ + @Nullable + @SuppressWarnings("unchecked") + public static EntityJointAnimator getThirdPersonJointAnimator(EntityType entityType){ + return (EntityJointAnimator) THIRD_PERSON_ENTITY_JOINT_ANIMATORS.get(entityType); + } + + /** + * Returns a joint skeleton for the provided entity type. If the entity type does not have a joint animator registered, null is returned. + * @param entityType Entity type + * @return Joint skeleton + */ + @Nullable + public static JointSkeleton getThirdPersonJointSkeleton(EntityType entityType){ + return THIRD_PERSON_ENTITY_JOINT_SKELETONS.get(entityType); + } + + /** + * Returns the first person player joint animator, if it has been registered. If not, it returns null. + */ + @Nullable + public static LivingEntityJointAnimator getFirstPersonPlayerJointAnimator(){ + return FIRST_PERSON_PLAYER_JOINT_ANIMATOR; + } + + /** + * Returns the first person player joint skeleton, if it has been registered. If not, it returns null. + */ + @Nullable + public static JointSkeleton getFirstPersonPlayerJointSkeleton(){ + return FIRST_PERSON_PLAYER_JOINT_SKELETON; + } +} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java index ef4dcbc..4b3bc22 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimator.java @@ -7,55 +7,12 @@ import net.minecraft.client.renderer.entity.state.EntityRenderState; import net.minecraft.world.entity.Entity; -public abstract class EntityJointAnimator extends JointAnimator { - - - //protected AnimationDataContainer entityAnimationData; - - public EntityJointAnimator(){ - super(); - } - - /* - protected WalkAnimationState getWalkAnimationState(){ - return this.livingEntity != null ? this.livingEntity.walkAnimation : new WalkAnimationState(); - } +public interface EntityJointAnimator extends JointAnimator { + /** + * Does some final operations on the entity model, similar to what would happen in the {@link EntityModel#setupAnim(EntityRenderState)} function. Called every frame after pose interpolation.\ + * @param entityRenderState Entity render state + * @param rootModelPart Root model part of the entity model */ - - /* - public void overallTick(LivingEntity livingEntity){ - BakedAnimationPose bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(livingEntity.getUUID()); - AnimationDataContainer entityAnimationData = EntityJointAnimatorDispatcher.INSTANCE.getEntityAnimationData(livingEntity.getUUID()); - - this.tick(livingEntity, entityAnimationData); - - entityAnimationData.tickAnimationStates(); - - if(bakedPose == null){ - bakedPose = new BakedAnimationPose(); - } - if(!bakedPose.hasPose){ - bakedPose.setPose(AnimationPose.of(this.jointSkeleton)); - bakedPose.hasPose = true; - } - bakedPose.pushToOld(); - - //this.locatorRig.resetRig(); - AnimationPose animationPose = this.calculatePose(); - if (animationPose == null){ - animationPose = AnimationPose.of(this.jointSkeleton); - } - animationPose.applyDefaultPoseOffset(); - - bakedPose.setPose(animationPose.getCopy()); - EntityJointAnimatorDispatcher.INSTANCE.saveBakedPose(livingEntity.getUUID(), bakedPose); - } - - */ - - - - public void postProcessModelParts(S entityRenderState, ModelPart rootModelPart){ - } + public void postProcessModelParts(S entityRenderState, ModelPart rootModelPart); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimatorDispatcher.java similarity index 57% rename from src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java rename to src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimatorDispatcher.java index a468c4b..465f4f1 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/EntityJointAnimatorDispatcher.java @@ -1,13 +1,15 @@ -package com.trainguy9512.animationoverhaul.animation; +package com.trainguy9512.animationoverhaul.animation.animator.entity; import com.google.common.collect.Maps; -import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; -import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.JointAnimatorRegistry; import com.trainguy9512.animationoverhaul.animation.data.AnimationDriverContainer; import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerStateContainer; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; import net.minecraft.world.entity.Entity; import java.util.HashMap; @@ -17,8 +19,12 @@ public class EntityJointAnimatorDispatcher { public static final EntityJointAnimatorDispatcher INSTANCE = new EntityJointAnimatorDispatcher(); private final HashMap entityAnimationDataContainerStorage; - private final HashMap entityBakedAnimationPoseStorage; private final HashMap entityPoseSamplerStateContainerStorage; + private final HashMap entityBakedAnimationPoseStorage; + + private final AnimationDriverContainer firstPersonPlayerAnimationDriverContainer = new AnimationDriverContainer(); + private PoseSamplerStateContainer firstPersonPoseSamplerStateContainer; + private BakedAnimationPose firstPersonPlayerBakedAnimationPose; public EntityJointAnimatorDispatcher(){ this.entityAnimationDataContainerStorage = Maps.newHashMap(); @@ -26,12 +32,12 @@ public EntityJointAnimatorDispatcher(){ this.entityPoseSamplerStateContainerStorage = Maps.newHashMap(); } - public void tick(T entity){ + public void tickThirdPersonJointAnimators(T entity){ UUID entityUUID = entity.getUUID(); @SuppressWarnings("unchecked") - EntityJointAnimator entityJointAnimator = (EntityJointAnimator) AnimationOverhaulMain.ENTITY_ANIMATORS.get(entity.getType()); - JointSkeleton jointSkeleton = entityJointAnimator.getJointSkeleton(); + EntityJointAnimator entityJointAnimator = (EntityJointAnimator) JointAnimatorRegistry.getThirdPersonJointAnimator(entity.getType()); + JointSkeleton jointSkeleton = JointAnimatorRegistry.getThirdPersonJointSkeleton(entity.getType()); BakedAnimationPose bakedPose = this.getEntityBakedAnimationPose(entityUUID, jointSkeleton); AnimationDriverContainer animationDriverContainer = this.getEntityAnimationDataContainer(entityUUID); @@ -44,7 +50,7 @@ public void tick(T entity){ poseSamplerStateContainer.tick(animationDriverContainer); // Step 3: Calculate pose - AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(animationDriverContainer, poseSamplerStateContainer); + AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(animationDriverContainer, poseSamplerStateContainer, jointSkeleton); if (calculatedAnimationPose == null){ calculatedAnimationPose = AnimationPose.of(jointSkeleton); } @@ -52,8 +58,40 @@ public void tick(T entity){ // Step 4: Push the local space pose to the baked pose, and save the baked pose. bakedPose.pushPose(calculatedAnimationPose.getConvertedToLocalSpace()); this.saveBakedPose(entityUUID, bakedPose); + } + + public void tickFirstPersonJointAnimator(){ + if(JointAnimatorRegistry.getFirstPersonPlayerJointAnimator() != null){ + LivingEntityJointAnimator entityJointAnimator = JointAnimatorRegistry.getFirstPersonPlayerJointAnimator(); + JointSkeleton jointSkeleton = JointAnimatorRegistry.getFirstPersonPlayerJointSkeleton(); + + // Initialize the pose sampler state container + if(this.firstPersonPoseSamplerStateContainer == null){ + this.firstPersonPoseSamplerStateContainer = new PoseSamplerStateContainer(jointSkeleton); + } + + // Initialize the baked animation pose + if(this.firstPersonPlayerBakedAnimationPose == null){ + this.firstPersonPlayerBakedAnimationPose = new BakedAnimationPose(jointSkeleton); + } + + LocalPlayer player = Minecraft.getInstance().player; + // Step 1: Extract animation driver data + entityJointAnimator.extractAnimationData(player, this.firstPersonPlayerAnimationDriverContainer); + // Step 2: Update pose samplers using animation driver data + this.firstPersonPoseSamplerStateContainer.tick(this.firstPersonPlayerAnimationDriverContainer); + + // Step 3: Calculate pose + AnimationPose calculatedAnimationPose = entityJointAnimator.calculatePose(this.firstPersonPlayerAnimationDriverContainer, this.firstPersonPoseSamplerStateContainer, jointSkeleton); + if (calculatedAnimationPose == null){ + calculatedAnimationPose = AnimationPose.of(jointSkeleton); + } + + // Step 4: Push the local space pose to the baked pose, and save the baked pose. + this.firstPersonPlayerBakedAnimationPose.pushPose(calculatedAnimationPose.getConvertedToLocalSpace()); + } } public > void saveBakedPose(UUID uuid, BakedAnimationPose bakedPose){ @@ -84,7 +122,7 @@ public > BakedAnimationPose getEntityBakedAnimationPose(UUID u * @return Animation data container */ private AnimationDriverContainer getEntityAnimationDataContainer(UUID uuid){ - return this.entityAnimationDataContainerStorage.getOrDefault(uuid, new AnimationDriverContainer()); + return this.entityAnimationDataContainerStorage.computeIfAbsent(uuid, uuid1 -> new AnimationDriverContainer()); } /** @@ -94,4 +132,12 @@ private AnimationDriverContainer getEntityAnimationDataContainer(UUID uuid){ public boolean entityHasBakedAnimationPose(UUID uuid){ return this.entityAnimationDataContainerStorage.containsKey(uuid); } + + public BakedAnimationPose getFirstPersonPlayerBakedAnimationPose(){ + return this.firstPersonPlayerBakedAnimationPose; + } + + public AnimationDriverContainer getFirstPersonPlayerAnimationDriverContainer(){ + return this.firstPersonPlayerAnimationDriverContainer; + } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/FirstPersonPlayerJointAnimator.java similarity index 64% rename from src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java rename to src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/FirstPersonPlayerJointAnimator.java index af65f70..6b75a54 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/FirstPersonPlayerJointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/FirstPersonPlayerJointAnimator.java @@ -1,17 +1,14 @@ -package com.trainguy9512.animationoverhaul.animation.animator; +package com.trainguy9512.animationoverhaul.animation.animator.entity; -import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityJointAnimator; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDriverContainer; -import com.trainguy9512.animationoverhaul.animation.data.PoseSamplerKey; -import com.trainguy9512.animationoverhaul.animation.data.AnimationDriverKey; +import com.trainguy9512.animationoverhaul.animation.data.*; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; +import com.trainguy9512.animationoverhaul.animation.pose.JointTransform; import com.trainguy9512.animationoverhaul.animation.pose.sample.*; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import com.trainguy9512.animationoverhaul.animation.data.AnimationSequenceData; import com.trainguy9512.animationoverhaul.util.time.Easing; import net.minecraft.client.Minecraft; -import net.minecraft.client.model.PlayerModel; +import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.entity.state.PlayerRenderState; @@ -23,13 +20,7 @@ import java.util.List; import java.util.function.BiFunction; -public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator { - - public static FirstPersonPlayerJointAnimator INSTANCE = new FirstPersonPlayerJointAnimator(); - - public AnimationDriverContainer localAnimationDriverContainer = new AnimationDriverContainer(); - public BakedAnimationPose localBakedPose; - +public class FirstPersonPlayerJointAnimator implements LivingEntityJointAnimator { public static final String ROOT_JOINT = "root"; public static final String CAMERA_JOINT = "camera"; @@ -69,30 +60,30 @@ public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator TIME_TEST = AnimationDriverKey.of(() -> 0F).setIdentifier("time_test").build(); + public static final AnimationDriverKey TIME_TEST = AnimationDriverKey.builder(() -> 0F).setIdentifier("time_test").build(); - public static final AnimationDriverKey CAMERA_ROTATION = AnimationDriverKey.of(() -> new Vector3f(0, 0, 0)).setIdentifier("camera_rotation").build(); - public static final AnimationDriverKey DAMPENED_CAMERA_ROTATION = AnimationDriverKey.of(() -> new Vector3f(0, 0, 0)).setIdentifier("dampened_camera_rotation").build(); - public static final AnimationDriverKey MAIN_HAND_ITEM = AnimationDriverKey.of(() -> ItemStack.EMPTY).setIdentifier("main_hand_item_stack").build(); - public static final AnimationDriverKey IS_ATTACKING = AnimationDriverKey.of(() -> false).setIdentifier("is_attacking").build(); - public static final AnimationDriverKey IS_USING_ITEM = AnimationDriverKey.of(() -> false).setIdentifier("is_using_item").build(); - public static final AnimationDriverKey IS_MINING = AnimationDriverKey.of(() -> false).setIdentifier("is_mining").build(); - public static final AnimationDriverKey IS_FALLING = AnimationDriverKey.of(() -> false).setIdentifier("is_falling").build(); - public static final AnimationDriverKey IS_JUMPING = AnimationDriverKey.of(() -> false).setIdentifier("is_jumping").build(); - public static final AnimationDriverKey WALK_SPEED = AnimationDriverKey.of(() -> 0f).setIdentifier("walk_speed").build(); + public static final AnimationDriverKey CAMERA_ROTATION = AnimationDriverKey.builder(() -> new Vector3f(0, 0, 0)).setIdentifier("camera_rotation").build(); + public static final AnimationDriverKey DAMPENED_CAMERA_ROTATION = AnimationDriverKey.builder(() -> new Vector3f(0, 0, 0)).setIdentifier("dampened_camera_rotation").build(); + public static final AnimationDriverKey MAIN_HAND_ITEM = AnimationDriverKey.builder(() -> ItemStack.EMPTY).setIdentifier("main_hand_item_stack").build(); + public static final AnimationDriverKey IS_ATTACKING = AnimationDriverKey.builder(() -> false).setIdentifier("is_attacking").build(); + public static final AnimationDriverKey IS_USING_ITEM = AnimationDriverKey.builder(() -> false).setIdentifier("is_using_item").build(); + public static final AnimationDriverKey IS_MINING = AnimationDriverKey.builder(() -> false).setIdentifier("is_mining").build(); + public static final AnimationDriverKey IS_FALLING = AnimationDriverKey.builder(() -> false).setIdentifier("is_falling").build(); + public static final AnimationDriverKey IS_JUMPING = AnimationDriverKey.builder(() -> false).setIdentifier("is_jumping").build(); + public static final AnimationDriverKey WALK_SPEED = AnimationDriverKey.builder(() -> 0f).setIdentifier("walk_speed").build(); public static final PoseSamplerKey> TEST_STATE_MACHINE = PoseSamplerKey.builder(() -> AnimationStateMachine.of("test_state_machine", TestStates.values()) .addStateTransition(TestStates.IDLE, TestStates.MOVING, AnimationStateMachine.StateTransition.of( - animationDataContainer -> animationDataContainer.getAnimationVariable(WALK_SPEED).get() > 0.1F) + animationDataContainer -> animationDataContainer.get(WALK_SPEED) > 0.1F) .setTransitionTime(5) - .setEasing(Easing.CubicBezier.bezierInOutSine()) + .setEasing(Easing.CubicBezier.SINE_IN_OUT()) .build()) .addStateTransition(TestStates.MOVING, TestStates.IDLE, AnimationStateMachine.StateTransition.of( - animationDataContainer -> animationDataContainer.getAnimationVariable(WALK_SPEED).get() < 0.1F) + animationDataContainer -> animationDataContainer.get(WALK_SPEED) <= 0.1F) .setTransitionTime(10) - .setEasing(Easing.CubicBezier.bezierOutSine()) + .setEasing(Easing.CubicBezier.SINE_OUT()) .build()) .build()).build(); @@ -108,17 +99,22 @@ public class FirstPersonPlayerJointAnimator extends LivingEntityJointAnimator> BiFunction, AnimationPose> getStatePose() { + public > BiFunction getStatePose() { return (animationDataContainer, fpPlayerLocatorsJointSkeleton) -> animationDataContainer.getPoseSampler(IDLE_SEQUENCE_PLAYER).sample(fpPlayerLocatorsJointSkeleton); } }, MOVING { @Override - public > BiFunction, AnimationPose> getStatePose() { + public > BiFunction getStatePose() { return (animationDataContainer, fpPlayerLocatorsJointSkeleton) -> animationDataContainer.getPoseSampler(IDLE_SEQUENCE_PLAYER_ALT).sample(fpPlayerLocatorsJointSkeleton); } } @@ -153,21 +149,20 @@ protected JointSkeleton.Builder buildSkeleton() { } @Override - public AnimationPose calculatePose(AnimationDriverContainer animationDriverContainer) { + public AnimationPose calculatePose(AnimationDriverContainer animationDriverContainer, PoseSamplerStateContainer poseSamplerStateContainer, JointSkeleton jointSkeleton) { // Update main hand item based on the anim notify //animationDataContainer.getAnimationVariable(MAIN_HAND_ITEM).set(localPlayer.getMainHandItem().copy()); //setEntityAnimationVariable(MAIN_HAND_ITEM, this.livingEntity.getMainHandItem().copy()); - AnimationPose pose = animationDriverContainer.getPoseSampler(TEST_STATE_MACHINE).sample(this.getJointSkeleton()); - + AnimationPose pose = poseSamplerStateContainer.sample(TEST_STATE_MACHINE); pose = dampenArmRotation(pose, animationDriverContainer); - Vector3f rotation = new Vector3f(Mth.sin(animationDriverContainer.getAnimationVariable(TIME_TEST).get() * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); + Vector3f rotation = new Vector3f(Mth.sin(animationDriverContainer.get(TIME_TEST) * 0.2F) * Mth.HALF_PI * 0.7f, 0, 0); //Vector3f translation = new Vector3f(Mth.sin(getEntityAnimationVariable(TIME_TEST) * 1.3F) * 3F, 0, 0); //pose.translateJoint(FPPlayerLocators.rightArm, translation, AnimationPose.TransformSpace.ENTITY, false); //pose.rotateJoint(FPPlayerLocators.rightArm, rotation, AnimationPose.TransformSpace.ENTITY, false); @@ -179,35 +174,32 @@ public AnimationPose calculatePose(AnimationDriverContainer anim /* Get the pose with the added dampened camera rotation */ - private AnimationPose dampenArmRotation(AnimationPose pose, AnimationDriverContainer animationDriverContainer){ - Vector3f cameraRotation = animationDriverContainer.getAnimationVariable(CAMERA_ROTATION).get(); - Vector3f dampenedCameraRotation = animationDriverContainer.getAnimationVariable(DAMPENED_CAMERA_ROTATION).get(); + private AnimationPose dampenArmRotation(AnimationPose pose, AnimationDriverContainer animationDriverContainer){ + Vector3f cameraRotation = animationDriverContainer.get(CAMERA_ROTATION); + Vector3f dampenedCameraRotation = animationDriverContainer.get(DAMPENED_CAMERA_ROTATION); Vector3f cameraDampWeight = new Vector3f(0.6F, 0.3F, 0.1F); pose.setJointTransform( - FPPlayerJoints.armBuffer, - pose.getJointTransform(FPPlayerJoints.armBuffer).rotate( + ARM_BUFFER_JOINT, + pose.getJointTransform(ARM_BUFFER_JOINT).rotate( new Vector3f( (dampenedCameraRotation.x() - cameraRotation.x()) * (cameraDampWeight.x() * 0.01F), (dampenedCameraRotation.y() - cameraRotation.y()) * (cameraDampWeight.y() * 0.01F), (dampenedCameraRotation.z() - cameraRotation.z()) * (cameraDampWeight.z() * 0.01F) ), - AnimationPose.TransformSpace.ENTITY + JointTransform.TransformSpace.ENTITY )); return pose; } @Override - public AnimationDriverContainer extractAnimationData(LocalPlayer dataReference, AnimationDriverContainer animationDriverContainer){ - - - - animationDriverContainer.getAnimationVariable(WALK_SPEED).set(this.getWalkAnimationSpeed(dataReference)); - animationDriverContainer.getAnimationVariable(TIME_TEST).set(animationDriverContainer.getAnimationVariable(TIME_TEST).get() + 1); + public void extractAnimationData(LocalPlayer dataReference, AnimationDriverContainer animationDriverContainer){ + animationDriverContainer.set(WALK_SPEED, dataReference.walkAnimation.speed()); + animationDriverContainer.set(TIME_TEST, animationDriverContainer.get(TIME_TEST) + 1); //Tick the dampened camera rotation. @@ -215,10 +207,10 @@ public AnimationDriverContainer extractAnimationData(LocalPlayer dataReference, // First, set the target camera rotation from the living entity. Vector3f targetRotation = new Vector3f(dataReference.getXRot(), dataReference.getYRot(), dataReference.getYRot()); - animationDriverContainer.getAnimationVariable(CAMERA_ROTATION).set(targetRotation); + animationDriverContainer.set(CAMERA_ROTATION, targetRotation); - Vector3f dampenedCameraRotation = animationDriverContainer.getAnimationVariable(DAMPENED_CAMERA_ROTATION).get(); + Vector3f dampenedCameraRotation = animationDriverContainer.get(DAMPENED_CAMERA_ROTATION); // If the dampened camera rotation is 0 (which is what it is upon initialization), set it to the target if(dampenedCameraRotation.x() == 0F && dampenedCameraRotation.y() == 0F){ @@ -232,38 +224,7 @@ public AnimationDriverContainer extractAnimationData(LocalPlayer dataReference, ); //dampenedCameraRotation.lerp(targetRotation, 0.5F); } - animationDriverContainer.getAnimationVariable(DAMPENED_CAMERA_ROTATION).set(dampenedCameraRotation); - - } + animationDriverContainer.set(DAMPENED_CAMERA_ROTATION, dampenedCameraRotation); - - //TODO: Move this elsewhere - - public void tickExternal(){ - LocalPlayer player = Minecraft.getInstance().player; - AnimationDriverContainer animationDriverContainer = this.localAnimationDriverContainer; - - this.extractAnimationData(player, animationDriverContainer); - animationDriverContainer.tickAllPoseSamplers(); - - if(this.localBakedPose == null){ - this.localBakedPose = new BakedAnimationPose<>(this.jointSkeleton); - } - - AnimationPose animationPose = this.calculatePose(animationDriverContainer); - if (animationPose == null){ - animationPose = AnimationPose.of(this.jointSkeleton); - } - - - this.localBakedPose.pushPose(animationPose); - } - - private boolean compareVariableItemStackWithEntityItemStack(AnimationDriverKey itemStackDataKey, ItemStack entityItemStack, AnimationDriverContainer animationDriverContainer){ - ItemStack currentItemStack = animationDriverContainer.getAnimationVariable(itemStackDataKey).get(); - if(currentItemStack.getItem() != null && entityItemStack.getItem() == null || currentItemStack.getItem() == null && entityItemStack.getItem() != null) { - return true; - } - return currentItemStack.getItem() != entityItemStack.getItem(); } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java index 328e070..07aeb40 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/LivingEntityJointAnimator.java @@ -6,13 +6,5 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -public abstract class LivingEntityJointAnimator, L extends Enum> extends EntityJointAnimator { - @Deprecated - protected float getWalkAnimationSpeed(T livingEntity){ - return livingEntity.walkAnimation.speed(); - } - @Deprecated - protected float getWalkAnimationPosition(T livingEntity){ - return livingEntity.walkAnimation.position(); - } +public interface LivingEntityJointAnimator extends EntityJointAnimator { } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java deleted file mode 100644 index b1cbbfd..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/animator/entity/PlayerJointAnimator.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.trainguy9512.animationoverhaul.animation.animator.entity; - -import com.trainguy9512.animationoverhaul.animation.data.AnimationDriverContainer; -import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; -import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; -import net.minecraft.client.model.PlayerModel; -import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.client.model.geom.PartPose; -import net.minecraft.client.renderer.entity.state.PlayerRenderState; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.player.Player; - -public class PlayerJointAnimator extends LivingEntityJointAnimator { - - private static final String MODEL_PART_ROOT = "root"; - private static final String MODEL_PART_HEAD = "head"; - private static final String MODEL_PART_BODY = "body"; - private static final String MODEL_PART_LEFT_LEG = "left_leg"; - private static final String MODEL_PART_RIGHT_LEG = "right_leg"; - private static final String MODEL_PART_LEFT_ARM = "left_arm"; - private static final String MODEL_PART_RIGHT_ARM = "right_arm"; - private static final String MODEL_PART_CAPE = "cloak"; - - public enum ModelPartLocators{ - root, - head, - body, - leftLeg, - rightLeg, - leftArm, - rightArm, - cape, - leftHand, - rightHand - } - - - public PlayerJointAnimator(){ - super(); - } - - // Building the locator rig - @Override - protected JointSkeleton buildSkeleton() { - - //TODO: Adjust rig with proper parenting and no more offsets on the legs. - - return JointSkeleton.of(ModelPartLocators.root) - .addChildToRoot(ModelPartLocators.body) - .addChildToRoot(ModelPartLocators.cape) - .addChildToRoot(ModelPartLocators.leftArm) - .addChildToRoot(ModelPartLocators.rightArm) - .addChildToRoot(ModelPartLocators.leftLeg) - .addChildToRoot(ModelPartLocators.rightLeg) - .addChildToRoot(ModelPartLocators.head) - .setLocatorModelPart(ModelPartLocators.head, MODEL_PART_HEAD) - .setLocatorModelPart(ModelPartLocators.leftArm, MODEL_PART_LEFT_ARM) - .setLocatorModelPart(ModelPartLocators.rightArm, MODEL_PART_RIGHT_ARM) - .setLocatorModelPart(ModelPartLocators.leftLeg, MODEL_PART_LEFT_LEG) - .setLocatorModelPart(ModelPartLocators.rightLeg, MODEL_PART_RIGHT_LEG) - .setLocatorModelPart(ModelPartLocators.body, MODEL_PART_BODY) - .setLocatorModelPart(ModelPartLocators.cape, MODEL_PART_CAPE) - .setDefaultJointTransform(ModelPartLocators.leftLeg, PartPose.offset(1.9f, 12.0f, 0.0f)) - .setDefaultJointTransform(ModelPartLocators.rightLeg, PartPose.offset(-1.9f, 12.0f, 0.0f)) - .setDefaultJointTransform(ModelPartLocators.leftArm, PartPose.offset(5.0f, 2.0f, 0.0f)) - .setDefaultJointTransform(ModelPartLocators.rightArm, PartPose.offset(-5.0f, 2.0f, 0.0f)) - .setDefaultJointTransform(ModelPartLocators.cape, PartPose.offsetAndRotation(0, 0, 2, 0, Mth.PI, 0)) - .setLocatorMirror(ModelPartLocators.leftArm, ModelPartLocators.rightArm) - .setLocatorMirror(ModelPartLocators.rightArm, ModelPartLocators.leftArm) - .setLocatorMirror(ModelPartLocators.leftLeg, ModelPartLocators.rightLeg) - .setLocatorMirror(ModelPartLocators.rightLeg, ModelPartLocators.leftLeg); - /* - locatorRig.addLocator(LOCATOR_ROOT); - locatorRig.addLocatorModelPart(LOCATOR_HEAD, "head"); - locatorRig.addLocatorModelPart(LOCATOR_BODY, "body"); - locatorRig.addLocatorModelPart(LOCATOR_LEFT_LEG, LOCATOR_RIGHT_LEG, "left_leg", PartPose.offset(1.9f, 12.0f, 0.0f)); - locatorRig.addLocatorModelPart(LOCATOR_RIGHT_LEG, LOCATOR_LEFT_LEG, "right_leg", PartPose.offset(-1.9f, 12.0f, 0.0f)); - locatorRig.addLocatorModelPart(LOCATOR_LEFT_ARM, LOCATOR_RIGHT_ARM, "left_arm", PartPose.offset(5.0f, 2.0f, 0.0f)); - locatorRig.addLocatorModelPart(LOCATOR_RIGHT_ARM, LOCATOR_LEFT_ARM, "right_arm", PartPose.offset(-5.0f, 2.0f, 0.0f)); - locatorRig.addLocatorModelPart(LOCATOR_CAPE, "cloak", PartPose.offsetAndRotation(0, 0, 2, 0, Mth.PI, 0)); - locatorRig.addLocator(LOCATOR_LEFT_HAND, LOCATOR_RIGHT_HAND); - locatorRig.addLocator(LOCATOR_RIGHT_HAND, LOCATOR_LEFT_HAND); - - */ - } - - // Ticking every sampleable animation state, in this case updating the state machine conditions - @Override - public AnimationDriverContainer extractAnimationData(Player dataReference, AnimationDriverContainer animationDriverContainer) { - return animationDriverContainer; - - - } - - // This is the function for getting the final pose every tick - @Override - public AnimationPose calculatePose(AnimationDriverContainer animationDriverContainer) { - return AnimationPose.of(this.jointSkeleton); - } - - // Post-processing on the animation, copying stuff to the second layer and whatnot - @Override - public void postProcessModelParts(PlayerRenderState playerRenderState, PlayerModel playerModel, ModelPart rootModelPart) { - rootModelPart.getChild("left_pants").copyFrom(rootModelPart.getChild("left_leg")); - rootModelPart.getChild("right_pants").copyFrom(rootModelPart.getChild("right_leg")); - rootModelPart.getChild("left_sleeve").copyFrom(rootModelPart.getChild("left_arm")); - rootModelPart.getChild("right_sleeve").copyFrom(rootModelPart.getChild("right_arm")); - rootModelPart.getChild("jacket").copyFrom(rootModelPart.getChild("body")); - rootModelPart.getChild("hat").copyFrom(rootModelPart.getChild("head")); - rootModelPart.getChild("cloak").xRot *= -1F; - // Removes the vanilla transformation done for the crouch pose - if(playerRenderState.isCrouching){ - for(ModelPart modelPart : rootModelPart.getAllParts().toList()){ - modelPart.y -= 2; - } - } - } -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainer.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainer.java index 0d5dde4..1830bd0 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainer.java @@ -16,7 +16,7 @@ * @see AnimationDriverKey * @see PoseSamplerKey */ -public class AnimationDriverContainer implements AnimationDriverContainerState { +public class AnimationDriverContainer { private final HashMap, AnimationDriver> animationDrivers; @@ -25,58 +25,51 @@ public AnimationDriverContainer(){ } /** - * Retrieves value of animation animator from the given key. If the driver does not exist, then - * it is created from the default and then retrieved. + * Retrieves value of animation driver from the given key. * - * @param dataKey the {@link AnimationDriverKey} attached to the desired {@link AnimationDriver} + * @param dataKey the {@link AnimationDriverKey} attached to the desired {@link AnimationDriver} * * @return an {@link AnimationDriver} object reference */ - @Override public D get(AnimationDriverKey dataKey) { - return this.animationDrivers.computeIfAbsent((dataKey) -> {new A}); + return this.getDriver(dataKey).get(); } + /** + * Sets the value of the animation driver from the given key. + * + * @param dataKey Data key value of param + * @param value New value to set + */ + public void set(AnimationDriverKey dataKey, D value){ + this.getDriver(dataKey).set(value); + } + @SuppressWarnings("unchecked") + private AnimationDriver getDriver(AnimationDriverKey dataKey) { + return (AnimationDriver) this.animationDrivers.computeIfAbsent(dataKey, AnimationDriver::new); + } - - public static class AnimationDriver{ + private static class AnimationDriver{ private D value; + private final Supplier defaultValue; - private AnimationDriver(D value){ - this.value = value; - } - - public static AnimationDriver of(AnimationDriverKey dataKey){ - return new AnimationDriver<>(dataKey.getDefaultValueSupplier()); + private AnimationDriver(AnimationDriverKey key){ + this.value = key.getDefaultValue().get(); + this.defaultValue = key.getDefaultValue(); } - /** - * Returns the value of this animation variable. - * - * @return - value of the {@link AnimationDriver} instance's type - */ public D get(){ return this.value; } - /** - * Sets the value of this animation variable. Also updates the old value, setting it - * to what it was prior to this method call. - * - * @param value new value of the {@link AnimationDriver} instance's type - */ public void set(D value){ - this.value = value; + this.value = value != null ? value : this.defaultValue.get(); } - /** - * Sets this animation variable's value to the default value, supplied from the - * default value supplier. - */ public void reset(){ - this.set(this.defaultValueSupplier.get()); + this.set(this.defaultValue.get()); } } } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainerState.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainerState.java deleted file mode 100644 index 7ea6ff2..0000000 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverContainerState.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.trainguy9512.animationoverhaul.animation.data; - -public interface AnimationDriverContainerState { - public D get(AnimationDriverKey dataKey); -} diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverKey.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverKey.java index e84c78d..debdcc9 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverKey.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/data/AnimationDriverKey.java @@ -34,10 +34,6 @@ public class AnimationDriverKey { * if the input involves things like random number generation */ private final Supplier defaultValue; - - /** - * The string identifier, used primarily in debugging. - */ private final String identifier; protected AnimationDriverKey(Supplier defaultValue, String identifier) { @@ -46,32 +42,25 @@ protected AnimationDriverKey(Supplier defaultValue, String identifier) { } /** - * Creates a builder for a key + * Creates a builder for an animation driver key * * @param defaultValue The default value of the animation variable */ - public static Builder of(Supplier defaultValue){ + public static Builder builder(Supplier defaultValue){ return new Builder<>(defaultValue); } - /** - * Returns the identifier for this key, utilized for debugging - * - * @return the {@link String} identifier attached to this key - */ + public Supplier getDefaultValue() { + return this.defaultValue; + } + public String getIdentifier() { return identifier; } - /** - * A mutable builder for {@link AnimationDriverContainer.AnimationDriver} objects. - * - * @param the type of data - */ public static class Builder { private final Supplier defaultValue; - private String identifier = "null"; protected Builder(Supplier defaultValue) { @@ -92,10 +81,6 @@ public Builder setIdentifier(String identifier){ return this; } - /** - * Returns a new {@link AnimationDriverKey} - * @return an {@link AnimationDriverKey} - */ public AnimationDriverKey build(){ return new AnimationDriverKey<>(this.defaultValue, this.identifier); } diff --git a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointTransform.java b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointTransform.java index 170e57d..cd89dd7 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointTransform.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/animation/pose/JointTransform.java @@ -94,41 +94,46 @@ public PartPose asPartPose(){ ); } - public void transform(Matrix4f transform, TransformSpace transformSpace){ + public JointTransform transform(Matrix4f transform, TransformSpace transformSpace){ switch (transformSpace){ case ENTITY, PARENT -> this.transform.mul(transform); case LOCAL -> this.transform.mulLocal(transform); } + return this; } - public void translate(Vector3f translation, TransformSpace transformSpace){ + public JointTransform translate(Vector3f translation, TransformSpace transformSpace){ if(translation.x() != 0 || translation.y() != 0 || translation.z() != 0){ switch (transformSpace){ case ENTITY, PARENT -> this.transform.translateLocal(translation); case LOCAL -> this.transform.translate(translation); } } + return this; } - public void rotate(Quaternionf rotation, TransformSpace transformSpace){ + public JointTransform rotate(Quaternionf rotation, TransformSpace transformSpace){ switch (transformSpace){ case ENTITY, PARENT -> this.setRotation(new Matrix4f(this.transform).getNormalizedRotation(new Quaternionf()).premul(rotation)); case LOCAL -> this.transform.rotate(rotation); } + return this; } - public void rotate(Vector3f rotationEuler, TransformSpace transformSpace){ - this.rotate(new Quaternionf().rotationXYZ(rotationEuler.x(), rotationEuler.y(), rotationEuler.z()), transformSpace); + public JointTransform rotate(Vector3f rotationEuler, TransformSpace transformSpace){ + return this.rotate(new Quaternionf().rotationXYZ(rotationEuler.x(), rotationEuler.y(), rotationEuler.z()), transformSpace); } - public void multiplyTransform(JointTransform jointTransform){ + public JointTransform multiplyTransform(JointTransform jointTransform){ this.translate(jointTransform.getTranslation(), TransformSpace.ENTITY); this.rotate(jointTransform.getRotation(), TransformSpace.ENTITY); + return this; } - public void inverseMultiplyTransform(JointTransform jointTransform){ + public JointTransform inverseMultiplyTransform(JointTransform jointTransform){ this.translate(jointTransform.getTranslation().negate(), TransformSpace.ENTITY); this.rotate(jointTransform.getRotation().invert(), TransformSpace.ENTITY); + return this; } public void mirror(){ @@ -147,7 +152,7 @@ public JointTransform blend(JointTransform jointTransform, float alpha, Easing e } public JointTransform blendLinear(JointTransform jointTransform, float alpha){ - return this.blend(jointTransform, alpha, Easing.Linear.of()); + return this.blend(jointTransform, alpha, Easing.LINEAR); } public void translateAndRotatePoseStack(PoseStack poseStack){ diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java index ef67b3c..7c7da76 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinElytraLayer.java @@ -2,7 +2,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.trainguy9512.animationoverhaul.access.LivingEntityRenderStateAccess; -import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelPart; @@ -10,7 +9,6 @@ import net.minecraft.client.renderer.entity.RenderLayerParent; import net.minecraft.client.renderer.entity.layers.RenderLayer; import net.minecraft.client.renderer.entity.layers.WingsLayer; -import net.minecraft.client.renderer.entity.state.EntityRenderState; import net.minecraft.client.renderer.entity.state.HumanoidRenderState; import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; import net.minecraft.world.entity.LivingEntity; diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java index cc8bd97..2983763 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinGameRenderer.java @@ -3,13 +3,15 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; -import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.JointAnimatorRegistry; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.animator.entity.FirstPersonPlayerJointAnimator; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointTransform; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -58,13 +60,13 @@ private > void tickEntityInformation(Callbac for(Entity entity : this.minecraft.level.entitiesForRendering()){ if(entity instanceof LivingEntity){ EntityType entityType = entity.getType(); - if(AnimationOverhaulMain.ENTITY_ANIMATORS.contains(entityType)){ - EntityJointAnimatorDispatcher.INSTANCE.tick(entity); + if(JointAnimatorRegistry.entityTypeRegisteredWithJointAnimator(entityType)){ + EntityJointAnimatorDispatcher.INSTANCE.tickThirdPersonJointAnimators(entity); } } } // Special functionality for the first person player joint animator - FirstPersonPlayerJointAnimator.INSTANCE.tickExternal(); + EntityJointAnimatorDispatcher.INSTANCE.tickFirstPersonJointAnimator(); } } @@ -72,8 +74,8 @@ private > void tickEntityInformation(Callbac @Inject(method = "bobView", at = @At(value = "HEAD"), cancellable = true) private void injectCameraRotation(PoseStack poseStack, float f, CallbackInfo ci){ if(this.minecraft.options.getCameraType().isFirstPerson() && this.renderHand){ - if(FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose != null){ - AnimationPose animationPose = FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose.getBlendedPose(f); + if(EntityJointAnimatorDispatcher.INSTANCE.getFirstPersonPlayerBakedAnimationPose() != null){ + AnimationPose animationPose = EntityJointAnimatorDispatcher.INSTANCE.getFirstPersonPlayerBakedAnimationPose().getBlendedPose(f); JointTransform cameraPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.CAMERA_JOINT); JointTransform rootPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.ROOT_JOINT); cameraPose.multiplyTransform(rootPose); diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java index dd50e99..b965603 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinItemInHandRenderer.java @@ -2,7 +2,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.animator.entity.FirstPersonPlayerJointAnimator; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointTransform; import net.minecraft.client.Minecraft; @@ -43,12 +44,12 @@ public abstract class MixinItemInHandRenderer { @Inject(method = "renderHandsWithItems", at = @At("HEAD"), cancellable = true) private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, LocalPlayer localPlayer, int i, CallbackInfo ci){ - if(FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose != null){ - AnimationPose animationPose = FirstPersonPlayerJointAnimator.INSTANCE.localBakedPose.getBlendedPose(f); - JointTransform rightArmPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.FPPlayerJoints.rightArm); - JointTransform leftArmPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.FPPlayerJoints.leftArm); - JointTransform rightHandPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.FPPlayerJoints.rightHand); - JointTransform leftHandPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.FPPlayerJoints.leftHand); + if(EntityJointAnimatorDispatcher.INSTANCE.getFirstPersonPlayerBakedAnimationPose() != null){ + AnimationPose animationPose = EntityJointAnimatorDispatcher.INSTANCE.getFirstPersonPlayerBakedAnimationPose().getBlendedPose(f); + JointTransform rightArmPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.RIGHT_ARM_JOINT); + JointTransform leftArmPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.LEFT_ARM_JOINT); + JointTransform rightHandPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.RIGHT_HAND_JOINT); + JointTransform leftHandPose = animationPose.getJointTransform(FirstPersonPlayerJointAnimator.LEFT_HAND_JOINT); poseStack.pushPose(); poseStack.mulPose(Axis.ZP.rotationDegrees(180)); @@ -130,7 +131,7 @@ private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBuf - this.renderItemInHand(abstractClientPlayer, FirstPersonPlayerJointAnimator.INSTANCE.localAnimationDriverContainer.getAnimationVariable(FirstPersonPlayerJointAnimator.MAIN_HAND_ITEM).get(), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); + this.renderItemInHand(abstractClientPlayer, EntityJointAnimatorDispatcher.INSTANCE.getFirstPersonPlayerAnimationDriverContainer().get(FirstPersonPlayerJointAnimator.MAIN_HAND_ITEM), poseStack, HumanoidArm.RIGHT, animationPose, bufferSource, i); //this.renderItemInHand(abstractClientPlayer, ItemStack.EMPTY, poseStack, HumanoidArm.LEFT, animationPose, bufferSource, i); @@ -143,10 +144,10 @@ private void overwriteItemInHandRendering(float f, PoseStack poseStack, MultiBuf ci.cancel(); } - private void renderItemInHand(AbstractClientPlayer abstractClientPlayer, ItemStack itemStack, PoseStack poseStack, HumanoidArm humanoidArm, AnimationPose animationPose, MultiBufferSource multiBufferSource, int i){ + private void renderItemInHand(AbstractClientPlayer abstractClientPlayer, ItemStack itemStack, PoseStack poseStack, HumanoidArm humanoidArm, AnimationPose animationPose, MultiBufferSource multiBufferSource, int i){ - JointTransform armPose = animationPose.getJointTransform(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.FPPlayerJoints.leftArm : FirstPersonPlayerJointAnimator.FPPlayerJoints.rightArm); - JointTransform handPose = animationPose.getJointTransform(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.FPPlayerJoints.leftHand : FirstPersonPlayerJointAnimator.FPPlayerJoints.rightHand); + JointTransform armPose = animationPose.getJointTransform(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.LEFT_ARM_JOINT : FirstPersonPlayerJointAnimator.RIGHT_ARM_JOINT); + JointTransform handPose = animationPose.getJointTransform(humanoidArm == HumanoidArm.LEFT ? FirstPersonPlayerJointAnimator.LEFT_HAND_JOINT : FirstPersonPlayerJointAnimator.RIGHT_HAND_JOINT); diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java index 02fb404..14b9c9d 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinLivingEntityRenderer.java @@ -5,7 +5,7 @@ import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; import com.trainguy9512.animationoverhaul.access.LivingEntityRenderStateAccess; import com.trainguy9512.animationoverhaul.access.ModelAccess; -import com.trainguy9512.animationoverhaul.animation.EntityJointAnimatorDispatcher; +import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimatorDispatcher; import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; import com.trainguy9512.animationoverhaul.animation.pose.JointSkeleton; diff --git a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java index 563aefc..a118f63 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/mixin/MixinMinecraft.java @@ -1,12 +1,7 @@ package com.trainguy9512.animationoverhaul.mixin; -import com.trainguy9512.animationoverhaul.animation.animator.FirstPersonPlayerJointAnimator; import net.minecraft.client.Minecraft; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Minecraft.class) public class MixinMinecraft { diff --git a/src/main/java/com/trainguy9512/animationoverhaul/util/time/Easing.java b/src/main/java/com/trainguy9512/animationoverhaul/util/time/Easing.java index beae2c0..81c17f5 100644 --- a/src/main/java/com/trainguy9512/animationoverhaul/util/time/Easing.java +++ b/src/main/java/com/trainguy9512/animationoverhaul/util/time/Easing.java @@ -2,23 +2,14 @@ import net.minecraft.util.Mth; -public abstract class Easing { +@FunctionalInterface +public interface Easing { - public abstract float ease(float time); + public float ease(float time); - public static class Linear extends Easing { + public static Easing LINEAR = time -> time; - public static Linear of() { - return new Linear(); - } - - @Override - public float ease(float time) { - return time; - } - } - - public static class CubicBezier extends Easing { + public static class CubicBezier implements Easing { float cx; float bx; @@ -31,6 +22,69 @@ public static class CubicBezier extends Easing { float startGradient; float endGradient; + // Preset cubic beziers + // https://easings.net/ + + public static CubicBezier SINE_IN_OUT() { + return new CubicBezier(0.37F, 0, 0.63F, 1); + } + public static CubicBezier SINE_IN() { + return new CubicBezier(0.12F, 0, 0.39F, 0); + } + public static CubicBezier SINE_OUT() { + return new CubicBezier(0.61F, 1, 0.88F, 1); + } + + public static CubicBezier QUAD_IN_OUT() { + return new CubicBezier(0.45F, 0, 0.55F, 1); + } + public static CubicBezier QUAD_IN() { + return new CubicBezier(0.11F, 0, 0.5F, 0); + } + public static CubicBezier QUAD_OUT() { + return new CubicBezier(0.5F, 1, 0.89F, 1); + } + + public static CubicBezier CUBIC_IN_OUT() { + return new CubicBezier(0.65F, 0, 0.35F, 1); + } + public static CubicBezier CUBIC_IN() { + return new CubicBezier(0.32F, 0, 0.67F, 0); + } + public static CubicBezier CUBIC_OUT() { + return new CubicBezier(0.33F, 1, 0.68F, 1); + } + + public static CubicBezier QUART_IN_OUT() { + return new CubicBezier(0.76F, 0, 0.24F, 1); + } + public static CubicBezier QUART_IN() { + return new CubicBezier(0.5F, 0, 0.75F, 0); + } + public static CubicBezier QUART_OUT() { + return new CubicBezier(0.25F, 1, 0.5F, 1); + } + + public static CubicBezier QUINT_IN_OUT() { + return new CubicBezier(0.83F, 0, 0.17F, 1); + } + public static CubicBezier QUINT_IN() { + return new CubicBezier(0.64F, 0, 0.78F, 0); + } + public static CubicBezier QUINT_OUT() { + return new CubicBezier(0.22F, 1, 0.36F, 1); + } + + public static CubicBezier CIRC_IN_OUT() { + return new CubicBezier(0.85F, 0, 0.15F, 1); + } + public static CubicBezier CIRC_IN() { + return new CubicBezier(0.55F, 0, 1F, 0.45F); + } + public static CubicBezier CIRC_OUT() { + return new CubicBezier(0F, 0.55F, 0.45F, 1); + } + public CubicBezier(float p1x, float p1y, float p2x, float p2y) { cx = 3f * p1x; bx = 3f * (p2x - p1x) - cx; @@ -126,81 +180,6 @@ public float ease(float time) { public static CubicBezier getInverseBezier(float p1x, float p1y, float p2x, float p2y) { return new CubicBezier(1 - p2x, 1 - p2y, 1 - p1x, 1 - p1y); } - - // Preset cubic beziers - // https://easings.net/ - - public static CubicBezier bezierInOutSine() { - return new CubicBezier(0.37F, 0, 0.63F, 1); - } - - public static CubicBezier bezierInSine() { - return new CubicBezier(0.12F, 0, 0.39F, 0); - } - - public static CubicBezier bezierOutSine() { - return new CubicBezier(0.61F, 1, 0.88F, 1); - } - - public static CubicBezier bezierInOutQuad() { - return new CubicBezier(0.45F, 0, 0.55F, 1); - } - - public static CubicBezier bezierInQuad() { - return new CubicBezier(0.11F, 0, 0.5F, 0); - } - - public static CubicBezier bezierOutQuad() { - return new CubicBezier(0.5F, 1, 0.89F, 1); - } - - public static CubicBezier bezierInOutCubic() { - return new CubicBezier(0.65F, 0, 0.35F, 1); - } - - public static CubicBezier bezierInCubic() { - return new CubicBezier(0.32F, 0, 0.67F, 0); - } - - public static CubicBezier bezierOutCubic() { - return new CubicBezier(0.33F, 1, 0.68F, 1); - } - - public static CubicBezier bezierInOutQuart() { - return new CubicBezier(0.76F, 0, 0.24F, 1); - } - - public static CubicBezier bezierInQuart() { - return new CubicBezier(0.5F, 0, 0.75F, 0); - } - - public static CubicBezier bezierOutQuart() { - return new CubicBezier(0.25F, 1, 0.5F, 1); - } - - public static CubicBezier bezierInOutQuint() { - return new CubicBezier(0.83F, 0, 0.17F, 1); - } - - public static CubicBezier bezierInQuint() { - return new CubicBezier(0.64F, 0, 0.78F, 0); - } - - public static CubicBezier bezierOutQuint() { - return new CubicBezier(0.22F, 1, 0.36F, 1); - } - - public static CubicBezier bezierInOutCirc() { - return new CubicBezier(0.85F, 0, 0.15F, 1); - } - - public static CubicBezier bezierInCirc() { - return new CubicBezier(0.55F, 0, 1F, 0.45F); - } - - public static CubicBezier bezierOutCirc() { - return new CubicBezier(0F, 0.55F, 0.45F, 1); - } } public static CubicBezier easeInOut(float easeIn, float easeOut) {