-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
096bb95
commit 83725fb
Showing
30 changed files
with
721 additions
and
888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
src/main/java/com/trainguy9512/animationoverhaul/animation/AnimatorDispatcher.java
This file was deleted.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
...main/java/com/trainguy9512/animationoverhaul/animation/EntityJointAnimatorDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.trainguy9512.animationoverhaul.animation; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.trainguy9512.animationoverhaul.AnimationOverhaulMain; | ||
import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; | ||
import com.trainguy9512.animationoverhaul.animation.pose.AnimationPose; | ||
import com.trainguy9512.animationoverhaul.animation.pose.BakedAnimationPose; | ||
import com.trainguy9512.animationoverhaul.animation.data.AnimationDataContainer; | ||
import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton; | ||
import net.minecraft.client.model.EntityModel; | ||
import net.minecraft.client.model.geom.ModelPart; | ||
import net.minecraft.world.entity.Entity; | ||
|
||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class EntityJointAnimatorDispatcher { | ||
public static final EntityJointAnimatorDispatcher INSTANCE = new EntityJointAnimatorDispatcher(); | ||
|
||
private final HashMap<UUID, AnimationDataContainer> entityAnimationDataMap = Maps.newHashMap(); | ||
private final HashMap<UUID, BakedAnimationPose<?>> bakedPoseMap = Maps.newHashMap(); | ||
|
||
public EntityJointAnimatorDispatcher(){ | ||
} | ||
|
||
public <T extends Entity, L extends Enum<L>> void tickEntity(T entity, EntityJointAnimator<T, ?, L> entityJointAnimator){ | ||
|
||
UUID entityUUID = entity.getUUID(); | ||
if(!entityAnimationDataMap.containsKey(entityUUID)){ | ||
entityAnimationDataMap.put(entityUUID, new AnimationDataContainer()); | ||
} | ||
|
||
BakedAnimationPose<L> bakedPose = (BakedAnimationPose<L>) INSTANCE.getBakedPose(entityUUID); | ||
AnimationDataContainer animationDataContainer = EntityJointAnimatorDispatcher.INSTANCE.getEntityAnimationDataReference(entityUUID); | ||
JointSkeleton<L> jointSkeleton = (JointSkeleton<L>) entityJointAnimator.getJointSkeleton(); | ||
|
||
// First tick the entity part animator | ||
entityJointAnimator.tick(entity, animationDataContainer); | ||
|
||
animationDataContainer.tickAnimationStates(); | ||
|
||
|
||
/* | ||
if(bakedPose == null){ | ||
bakedPose = new BakedAnimationPose<>(); | ||
} | ||
*/ | ||
if(!bakedPose.hasPose){ | ||
bakedPose.setPose(AnimationPose.of(jointSkeleton)); | ||
bakedPose.hasPose = true; | ||
} | ||
bakedPose.pushToOld(); | ||
|
||
|
||
AnimationPose<L> calculatedAnimationPose = entityJointAnimator.calculatePose(entity, animationDataContainer); | ||
if (calculatedAnimationPose == null){ | ||
calculatedAnimationPose = AnimationPose.of(jointSkeleton); | ||
} | ||
calculatedAnimationPose.convertSpaceEntityToLocal(); | ||
|
||
//TODO: Rewrite how pose offsets are done | ||
calculatedAnimationPose.applyDefaultPoseOffset(); | ||
|
||
bakedPose.setPose(new AnimationPose<L>(calculatedAnimationPose)); | ||
|
||
//TODO: Should this be a reference to the static instance and not itself? | ||
EntityJointAnimatorDispatcher.INSTANCE.saveBakedPose(entityUUID, bakedPose); | ||
|
||
|
||
//livingEntityPartAnimator.overallTick(livingEntity); | ||
} | ||
|
||
public <T extends Entity, M extends EntityModel<T>, L extends Enum<L>> boolean animateEntity(T livingEntity, M entityModel, PoseStack poseStack, float partialTicks){ | ||
if(entityAnimationDataMap.containsKey(livingEntity.getUUID())){ | ||
if(AnimationOverhaulMain.ENTITY_ANIMATORS.contains(livingEntity.getType())){ | ||
EntityJointAnimator<T, M, L> entityJointAnimator = (EntityJointAnimator<T, M, L>) AnimationOverhaulMain.ENTITY_ANIMATORS.get(livingEntity.getType()); | ||
applyBakedPose(livingEntity, entityModel, entityJointAnimator, partialTicks); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private <T extends Entity, M extends EntityModel<T>, L extends Enum<L>> void applyBakedPose(T entity, M entityModel, EntityJointAnimator<T, M, L> entityJointAnimator, float partialTicks){ | ||
BakedAnimationPose<?> bakedPose = EntityJointAnimatorDispatcher.INSTANCE.getBakedPose(entity.getUUID()); | ||
|
||
if(bakedPose != null){ | ||
ModelPart rootModelPart = entityJointAnimator.getRoot(entityModel); | ||
|
||
bakedPose.bakeToModelParts(rootModelPart, partialTicks); | ||
entityJointAnimator.finalizeModelParts(entityModel, rootModelPart); | ||
} | ||
} | ||
|
||
public <L extends Enum<L>> void saveBakedPose(UUID uuid, BakedAnimationPose<L> bakedPose){ | ||
this.bakedPoseMap.put(uuid, bakedPose); | ||
} | ||
|
||
public BakedAnimationPose<?> getBakedPose(UUID uuid){ | ||
return this.bakedPoseMap.getOrDefault(uuid, new BakedAnimationPose<>()); | ||
/* | ||
if(this.bakedPoseMap.containsKey(uuid)){ | ||
return this.bakedPoseMap.get(uuid); | ||
} | ||
return null; | ||
*/ | ||
} | ||
|
||
public boolean hasAnimationData(UUID uuid){ | ||
return this.entityAnimationDataMap.containsKey(uuid); | ||
} | ||
|
||
public AnimationDataContainer getEntityAnimationDataReference(UUID uuid){ | ||
if(entityAnimationDataMap.containsKey(uuid)){ | ||
return entityAnimationDataMap.get(uuid); | ||
} | ||
return new AnimationDataContainer(); | ||
} | ||
|
||
public <T extends Entity> AnimationDataContainer getEntityAnimationData(T entity){ | ||
return getEntityAnimationDataReference(entity.getUUID()); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
src/main/java/com/trainguy9512/animationoverhaul/animation/LivingEntityAnimatorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
package com.trainguy9512.animationoverhaul.animation; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.trainguy9512.animationoverhaul.animation.animator.entity.LivingEntityAnimator; | ||
import com.trainguy9512.animationoverhaul.animation.animator.entity.EntityJointAnimator; | ||
import net.minecraft.world.entity.EntityType; | ||
|
||
import java.util.HashMap; | ||
|
||
public class LivingEntityAnimatorRegistry { | ||
|
||
private final HashMap<EntityType<?>, LivingEntityAnimator<?, ?, ?>> livingEntityPartAnimatorHashMap = Maps.newHashMap(); | ||
private final HashMap<EntityType<?>, EntityJointAnimator<?, ?, ?>> livingEntityPartAnimatorHashMap = Maps.newHashMap(); | ||
|
||
public LivingEntityAnimatorRegistry(){ | ||
} | ||
|
||
public void register(EntityType<?> entityType, LivingEntityAnimator<?, ?, ?> livingEntityPartAnimator){ | ||
public void register(EntityType<?> entityType, EntityJointAnimator<?, ?, ?> livingEntityPartAnimator){ | ||
livingEntityPartAnimatorHashMap.put(entityType, livingEntityPartAnimator); | ||
} | ||
|
||
public boolean contains(EntityType<?> entityType){ | ||
return livingEntityPartAnimatorHashMap.containsKey(entityType); | ||
} | ||
|
||
public LivingEntityAnimator<?, ?, ?> get(EntityType<?> entityType){ | ||
public EntityJointAnimator<?, ?, ?> get(EntityType<?> entityType){ | ||
return livingEntityPartAnimatorHashMap.get(entityType); | ||
} | ||
} |
Oops, something went wrong.