Skip to content

Commit

Permalink
Big WIP on restructuring everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Trainguy9512 committed Mar 12, 2024
1 parent 096bb95 commit 83725fb
Show file tree
Hide file tree
Showing 30 changed files with 721 additions and 888 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@


import com.trainguy9512.animationoverhaul.animation.LivingEntityAnimatorRegistry;
import com.trainguy9512.animationoverhaul.animation.animator.entity.PlayerJointAnimator;
import com.trainguy9512.animationoverhaul.animation.data.TimelineGroupDataLoader;
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;

Expand Down Expand Up @@ -53,7 +55,7 @@ public void onInitialize() {


private static void registerEntityAnimators(){
//ENTITY_ANIMATORS.register(EntityType.PLAYER, new PlayerPartAnimator());
ENTITY_ANIMATORS.register(EntityType.PLAYER, new PlayerJointAnimator());
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.trainguy9512.animationoverhaul.access;

import com.trainguy9512.animationoverhaul.util.animation.LocatorSkeleton;
import com.trainguy9512.animationoverhaul.util.animation.JointSkeleton;
import net.minecraft.core.BlockPos;

public interface LivingEntityAccess {
Expand All @@ -16,6 +16,6 @@ public interface LivingEntityAccess {
boolean getUseInventoryRenderer();
void setUseInventoryRenderer(boolean bool);

LocatorSkeleton getLocatorRig();
void storeLocatorRig(LocatorSkeleton locatorRig);
JointSkeleton getLocatorRig();
void storeLocatorRig(JointSkeleton locatorRig);
}

This file was deleted.

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());
}
}
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);
}
}
Loading

0 comments on commit 83725fb

Please sign in to comment.