Skip to content

Commit

Permalink
Work on improving systems for use on multiplayer servers
Browse files Browse the repository at this point in the history
- Improved sprint jumping
- Reverted second layer parenting to old system
- Removed flying animation for the sake of server smoothness
- Added water wading animation when underwater but not "swimming"
- Removed ground impact kneel animation for the sake of server smoothness- this will be re-added later in a different context
- Updated to test8
  • Loading branch information
Trainguy9512 committed Aug 14, 2021
1 parent 0bc0631 commit 440b036
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 60 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.6

# Mod Properties
mod_version = 1.0-test5
mod_version = 1.0-test8
maven_group = com.example
archives_base_name = trainguys-animation-overhaul

Expand Down
Expand Up @@ -13,6 +13,7 @@ public abstract class MixinLivingEntity implements LivingEntityAccess {
public float kneelAmount;
public float verticalMovementRotation;
public float sprintAmount;
public float inWaterAmount;

public float leftArmItemPoseAmount;
public float rightArmItemPoseAmount;
Expand All @@ -38,6 +39,7 @@ public float getAnimationVariable(String variableType){
case "inAirAmount" -> inAirAmount;
case "kneelAmount" -> kneelAmount;
case "sprintAmount" -> sprintAmount;
case "inWaterAmount" -> inWaterAmount;
case "verticalMovementRotation" -> verticalMovementRotation;
case "leftArmItemPoseAmount" -> leftArmItemPoseAmount;
case "rightArmItemPoseAmount" -> rightArmItemPoseAmount;
Expand All @@ -60,6 +62,7 @@ public void setAnimationVariable(String variableType, float newValue){
case "inAirAmount" -> inAirAmount = newValue;
case "kneelAmount" -> kneelAmount = newValue;
case "sprintAmount" -> sprintAmount = newValue;
case "inWaterAmount" -> inWaterAmount = newValue;
case "verticalMovementRotation" -> verticalMovementRotation = newValue;
case "leftArmItemPoseAmount" -> leftArmItemPoseAmount = newValue;
case "rightArmItemPoseAmount" -> rightArmItemPoseAmount = newValue;
Expand Down
@@ -0,0 +1,25 @@
package com.trainguy.animationoverhaul.mixin;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.PiglinModel;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
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;

@Mixin(PiglinModel.class)
public class MixinPiglinModel<T extends Mob> extends PlayerModel<T> {
public MixinPiglinModel(ModelPart modelPart, boolean bl) {
super(modelPart, bl);
}

@Inject(method = "setupAnim", at = @At("HEAD"), cancellable = true)
private void animPiglinModel(T mob, float f, float g, float h, float i, float j, CallbackInfo ci){
super.setupAnim(mob, f, g, h, i, j);
ci.cancel();
}
}
Expand Up @@ -42,6 +42,9 @@ public MixinPlayerModel(ModelPart modelPart) {
@Inject(method = "setupAnim", at = @At("HEAD"), cancellable = true)
private void animPlayerModel(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci){
// TODO: Rewrite bow and crossbow logic
// TODO: Remove kneeling when hitting the ground- this is impossible to get working on servers and honestly looks too snappy
// TODO: Rework the flying and do it in a way that works on servers
// TODO: What's the deal with punching?

// Make it so this only applies to player animations, not mobs that use player animations as a base.
if(livingEntity.getType() != EntityType.PLAYER){
Expand Down Expand Up @@ -99,6 +102,14 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
float sprintAmount = Mth.sin(currentSprintAmount * Mth.PI - Mth.PI * 0.5F) * 0.5F + 0.5F;
((LivingEntityAccess)livingEntity).setAnimationVariable("sprintAmount", currentSprintAmount);

// In water
float entityInWaterAmount = ((LivingEntityAccess)livingEntity).getAnimationVariable("inWaterAmount");
float currentInWaterAmount = Mth.clamp(entityInWaterAmount + (livingEntity.isUnderWater() ? 0.0625F : -0.0625F), 0, 1);
float inWaterAmount = Mth.sin((currentInWaterAmount) * Mth.PI - Mth.PI * 0.5F) * 0.5F + 0.5F;
((LivingEntityAccess)livingEntity).setAnimationVariable("inWaterAmount", currentInWaterAmount);

/*
// When the player hits the ground after being in the air, start the hit ground animation
float entityInAirAmount = ((LivingEntityAccess)livingEntity).getAnimationVariable("inAirAmount");
float entityKneelAmount = ((LivingEntityAccess)livingEntity).getAnimationVariable("kneelAmount");
Expand All @@ -108,13 +119,16 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
}
// Get the in air and kneel values
currentKneelAmount = Mth.clamp(entityKneelAmount - 0.125F * delta, 0.0F, 1.0F);
float currentInAirAmount = !livingEntity.isOnGround() && !livingEntity.onClimbable() && !livingEntity.isSwimming() && !livingEntity.isPassenger() ? Mth.clamp(entityInAirAmount + 0.05F * delta, 0.0F, 1.0F) : 0;
float inAirAmount = livingEntity.isOnGround() || livingEntity.onClimbable() || livingEntity.isSwimming() || livingEntity.isPassenger() ? 0 : Mth.clamp(currentInAirAmount, 0, 1);
boolean isInAir = (livingEntity.fallDistance > 0 || (livingEntity.getDeltaMovement().y == 0 && !livingEntity.isOnGround())) && !livingEntity.onClimbable() && !livingEntity.isSwimming() && !livingEntity.isPassenger();
float currentInAirAmount = isInAir ? Mth.clamp(entityInAirAmount + 0.05F * delta, 0.0F, 1.0F) : Mth.clamp(entityInAirAmount - 0.25F * delta, 0.0F, 1.0F);
float inAirAmount = Mth.clamp(currentInAirAmount, 0, 1);
float kneelAmount = 2 - Mth.sqrt(Mth.cos((float) (currentKneelAmount * Math.PI * 0.5F))) * 2;
sprintAmount *= (1 - inAirAmount);
((LivingEntityAccess)livingEntity).setAnimationVariable("inAirAmount", currentInAirAmount);
((LivingEntityAccess)livingEntity).setAnimationVariable("kneelAmount", currentKneelAmount);
*/

// Get the look angle and delta movement to determine whether the character is moving forwards or backwards
// TODO: this breaks when strafing, may need to re-evaluate my approach for this
if(g > 0.1){
Expand All @@ -140,12 +154,12 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,

// Math for main movements
float bodyBob = livingEntity.isOnGround() ? (float) ( ((Mth.abs(Mth.sin(f * limbMotionMultiplier - Mth.PI / 4) * 1) * -1 + 1F) * Mth.clamp(g, 0, 0.25) * 4 * (sprintAmount + 1))): 0;
float rightLegLift = livingEntity.isOnGround() ? (float) ((Math.min(Mth.sin(f * limbMotionMultiplier + Mth.PI * directionShift) * -3, 0) + 1) * Mth.clamp(g, 0, 0.25) * 4): 0;
float leftLegLift = livingEntity.isOnGround() ? (float) ((Math.min(Mth.sin(f * limbMotionMultiplier + Mth.PI + Mth.PI * directionShift) * -3, 0) + 1) * Mth.clamp(g, 0, 0.25) * 4): 0;
float limbRotation = ((Mth.cos(f * limbMotionMultiplier)) * 1.1F * g) * (1 - inAirAmount);
float inverseLimbRotation = ((Mth.cos(f * limbMotionMultiplier + Mth.PI)) * 1.1F * g) * (1 - inAirAmount);
float limbForwardMotion = Mth.cos(f * limbMotionMultiplier) * 2.0F * g * (1 - inAirAmount);
float inverseLimbForwardMotion = Mth.cos(f * limbMotionMultiplier + Mth.PI) * 2.0F * g * (1 - inAirAmount);
float rightLegLift = livingEntity.isOnGround() ? (float) ((Math.min(Mth.sin(f * limbMotionMultiplier + Mth.PI * directionShift) * -3, 0) + 1) * Mth.clamp(g, 0, 0.25) * 4) * (1 - inWaterAmount): 0;
float leftLegLift = livingEntity.isOnGround() ? (float) ((Math.min(Mth.sin(f * limbMotionMultiplier + Mth.PI + Mth.PI * directionShift) * -3, 0) + 1) * Mth.clamp(g, 0, 0.25) * 4) * (1 - inWaterAmount): 0;
float limbRotation = ((Mth.cos(f * limbMotionMultiplier)) * 1.1F * g) * (1 - inWaterAmount);
float inverseLimbRotation = ((Mth.cos(f * limbMotionMultiplier + Mth.PI)) * 1.1F * g) * (1 - inWaterAmount);
float limbForwardMotion = Mth.cos(f * limbMotionMultiplier) * 2.0F * g * (1 - inWaterAmount);
float inverseLimbForwardMotion = Mth.cos(f * limbMotionMultiplier + Mth.PI) * 2.0F * g * (1 - inWaterAmount);

// Main movements
this.leftArm.z = limbForwardMotion * sprintAmount * 2 * (1 - leftArmItemPoseAmount) * (1 - crossbowHoldAmount);
Expand Down Expand Up @@ -205,15 +219,18 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
}

// In air post process
this.leftLeg.z += ((Math.cos(h * limbMotionMultiplier * 0.75) * 2) - 1) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.leftLeg.xRot += ((Math.cos(h * limbMotionMultiplier * 0.75 - Mth.PI / 4)) * 0.5) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.rightLeg.z += ((Math.cos(h * limbMotionMultiplier * 0.75 - Mth.PI) * 2) - 1) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.rightLeg.xRot += ((Math.cos(h * limbMotionMultiplier * 0.75 - Mth.PI / 4 - Mth.PI)) * 0.5) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.leftLeg.z += ((Math.cos(h * limbMotionMultiplier * 0.5) * 2) - 1) * inWaterAmount;
this.leftLeg.xRot += ((Math.cos(h * limbMotionMultiplier * 0.5 - Mth.PI / 4)) * 0.5) * inWaterAmount;
this.rightLeg.z += ((Math.cos(h * limbMotionMultiplier * 0.5 - Mth.PI) * 2) - 1) * inWaterAmount;
this.rightLeg.xRot += ((Math.cos(h * limbMotionMultiplier * 0.5 - Mth.PI / 4 - Mth.PI)) * 0.5) * inWaterAmount;

this.leftArm.xRot += ((Math.cos(h * limbMotionMultiplier * 0.75 - Mth.PI)) * 0.5) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.leftArm.zRot = (float) (((Math.cos(h * limbMotionMultiplier * 0.75 + Mth.PI / 2 - Mth.PI)) * 0.25F - 0.25F) * inAirAmount) * Mth.clamp(1 - g * 0.5F, 0, 1);
this.rightArm.xRot += ((Math.cos(h * limbMotionMultiplier * 0.75)) * 0.5) * inAirAmount * Mth.clamp(1 - g * 0.5F, 0, 1);
this.rightArm.zRot = (float) (((Math.cos(h * limbMotionMultiplier * 0.75 - Mth.PI / 2)) * 0.25F + 0.25F) * inAirAmount) * Mth.clamp(1 - g * 0.5F, 0, 1);
this.leftArm.xRot += ((Math.cos(h * limbMotionMultiplier * 0.5 - Mth.PI)) * 0.5) * inWaterAmount;
this.leftArm.zRot = (float) (((Math.cos(h * limbMotionMultiplier * 0.5 + Mth.PI / 2 - Mth.PI)) * 0.5F - 0.5F) * inWaterAmount);
this.rightArm.xRot += ((Math.cos(h * limbMotionMultiplier * 0.5)) * 0.5) * inWaterAmount;
this.rightArm.zRot = (float) (((Math.cos(h * limbMotionMultiplier * 0.5 - Mth.PI / 2)) * 0.5F + 0.5F) * inWaterAmount);

/*
Old code that was part of the creative flying animation
this.leftArm.xRot += 1 * g * inAirAmount;
this.rightArm.xRot += 1 * g * inAirAmount;
Expand All @@ -224,8 +241,12 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
this.rightLeg.z += 7 * g * inAirAmount;
this.leftLeg.y += -2 * g * inAirAmount;
this.rightLeg.y += -2 * g * inAirAmount;
*/

// Kneel post process
/*
Old code for the ground impact kneel
this.leftLeg.y += 2 * kneelAmount;
this.leftLeg.z += -4 * kneelAmount;
this.leftLeg.xRot += 0.5 * kneelAmount;
Expand All @@ -243,6 +264,7 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
this.rightArm.zRot += 0.25F * kneelAmount;
this.head.y += 2 * kneelAmount;
this.head.z += -3 * kneelAmount;
*/

// Right arm pose post process
this.rightArm.xRot += -0.2F * rightArmItemPoseAmount;
Expand All @@ -251,6 +273,7 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
this.leftArm.xRot += -0.2F * leftArmItemPoseAmount;

// Attack Animation Post Process
this.body.yRot = 0;
if(this.attackTime > 0){
// Get the selected arm
HumanoidArm humanoidArm = livingEntity.getMainArm();
Expand Down Expand Up @@ -343,47 +366,13 @@ private void animPlayerModel(T livingEntity, float f, float g, float h, float i,
// debug
//System.out.println(CrossbowItem.getChargeDuration(livingEntity.getUseItem()));

// Hat layer parent
this.hat.y = this.head.y;
this.hat.z = this.head.z;
this.hat.xRot = this.head.xRot;
this.hat.yRot = this.head.yRot;
this.hat.zRot = this.head.zRot;

// Jacket layer parent
this.jacket.y = this.body.y;
this.jacket.z = this.body.z;
this.jacket.xRot = this.body.xRot;
this.jacket.yRot = this.body.yRot;
this.jacket.zRot = this.body.zRot;

// Right Sleeve layer parent
this.rightSleeve.y = this.rightArm.y;
this.rightSleeve.z = this.rightArm.z;
this.rightSleeve.xRot = this.rightArm.xRot;
this.rightSleeve.yRot = this.rightArm.yRot;
this.rightSleeve.zRot = this.rightArm.zRot;

// Left Sleeve layer parent
this.leftSleeve.y = this.leftArm.y;
this.leftSleeve.z = this.leftArm.z;
this.leftSleeve.xRot = this.leftArm.xRot;
this.leftSleeve.yRot = this.leftArm.yRot;
this.leftSleeve.zRot = this.leftArm.zRot;

// Right Pants layer parent
this.rightPants.y = this.rightLeg.y;
this.rightPants.z = this.rightLeg.z;
this.rightPants.xRot = this.rightLeg.xRot;
this.rightPants.yRot = this.rightLeg.yRot;
this.rightPants.zRot = this.rightLeg.zRot;

// Left Pants layer parent
this.leftPants.y = this.leftLeg.y;
this.leftPants.z = this.leftLeg.z;
this.leftPants.xRot = this.leftLeg.xRot;
this.leftPants.yRot = this.leftLeg.yRot;
this.leftPants.zRot = this.leftLeg.zRot;
// Parent the second layer to the main meshes
this.hat.copyFrom(this.head);
this.jacket.copyFrom(this.body);
this.leftPants.copyFrom(this.leftLeg);
this.rightPants.copyFrom(this.rightLeg);
this.leftSleeve.copyFrom(this.leftArm);
this.rightSleeve.copyFrom(this.rightArm);

if (livingEntity.getItemBySlot(EquipmentSlot.CHEST).isEmpty()) {
if (livingEntity.isCrouching()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/animationoverhaul.mixins.json
Expand Up @@ -7,8 +7,8 @@
],
"client": [
"MixinGhastRenderer",
"MixinPlayerModel",
"MixinLivingEntity"
"MixinLivingEntity",
"MixinPlayerModel"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 440b036

Please sign in to comment.