Skip to content

Commit

Permalink
Reworking stored values
Browse files Browse the repository at this point in the history
- Removed part-transform-based variables
- Added proper variables stored in LivingEntity
- Fixed arms spreading apart when looking up or down while holding charged crossbow
- Added rotation for Ghasts when flying up and down
- Fixed player animations on servers for the most part, there's still noticable issues with sprint jumping and crossbow charging that still need to be worked out
- Updated version to test5
  • Loading branch information
Trainguy9512 committed Aug 13, 2021
1 parent c576ae7 commit 0bc0631
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 74 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.6

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

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

public interface LivingEntityAccess {
float getAnimationVariable(String animationVariable);
void setAnimationVariable(String animationVariable, float newValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import com.trainguy.animationoverhaul.access.LivingEntityAccess;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.GhastRenderer;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Ghast;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -20,8 +15,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Random;

@Unique
@Mixin(GhastRenderer.class)
public class MixinGhastRenderer {
Expand All @@ -39,6 +32,9 @@ private void overrideGhastTexture(Ghast ghast, CallbackInfoReturnable<ResourceLo

@Inject(method="scale", at = @At("HEAD"), cancellable = true)
private void overrideGhastRenderer(Ghast ghast, PoseStack poseStack, float f, CallbackInfo ci){

float delta = Minecraft.getInstance().getDeltaFrameTime();

float ghastHurtTime = ghast.hurtTime + (1 - f);
if(ghast.hurtTime > 0 && ghast.deathTime == 0){
float ghastHurtRotationCurve = Mth.sin((1 - ghastHurtTime / 10) * Mth.PI * 2) * (1 - (1 - ghastHurtTime / 10)) * 25;
Expand All @@ -48,6 +44,12 @@ private void overrideGhastRenderer(Ghast ghast, PoseStack poseStack, float f, Ca
poseStack.mulPose(Vector3f.XP.rotationDegrees(Mth.sin((ghast.tickCount + f) / 12 - 1.5F) * 10));
poseStack.mulPose(Vector3f.ZP.rotationDegrees(Mth.sin((ghast.tickCount + f) / 20) * 10));
poseStack.scale(4.5F, 4.5F, 4.5F);

float currentVerticalMovementRotation = ((LivingEntityAccess)ghast).getAnimationVariable("verticalMovementRotation");
currentVerticalMovementRotation = ghast.getDeltaMovement().y >= 0 ? Mth.clamp(currentVerticalMovementRotation - 2 * delta, -25, 25) : Mth.clamp(currentVerticalMovementRotation + 2 * delta, -25, 25);
((LivingEntityAccess)ghast).setAnimationVariable("verticalMovementRotation", currentVerticalMovementRotation);
poseStack.mulPose(Vector3f.XP.rotationDegrees(currentVerticalMovementRotation));

ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.trainguy.animationoverhaul.mixin;

import com.trainguy.animationoverhaul.access.LivingEntityAccess;
import net.minecraft.world.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Unique
@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity implements LivingEntityAccess {
public float crouchAmount;
public float inAirAmount;
public float kneelAmount;
public float verticalMovementRotation;
public float sprintAmount;

public float leftArmItemPoseAmount;
public float rightArmItemPoseAmount;

public float leftArmBowPoseAmount;
public float rightArmBowPoseAmount;

public float leftArmSpearPoseAmount;
public float rightArmSpearPoseAmount;

public float leftArmCrossbowPoseAmount;
public float rightArmCrossbowPoseAmount;

public float leftArmShieldPoseAmount;
public float rightArmShieldPoseAmount;

public float leftArmSpyglassPoseAmount;
public float rightArmSpyglassPoseAmount;

public float getAnimationVariable(String variableType){
return switch (variableType) {
case "crouchAmount" -> crouchAmount;
case "inAirAmount" -> inAirAmount;
case "kneelAmount" -> kneelAmount;
case "sprintAmount" -> sprintAmount;
case "verticalMovementRotation" -> verticalMovementRotation;
case "leftArmItemPoseAmount" -> leftArmItemPoseAmount;
case "rightArmItemPoseAmount" -> rightArmItemPoseAmount;
case "leftArmBowPoseAmount" -> leftArmBowPoseAmount;
case "rightArmBowPoseAmount" -> rightArmBowPoseAmount;
case "leftArmSpearPoseAmount" -> leftArmSpearPoseAmount;
case "rightArmSpearPoseAmount" -> rightArmSpearPoseAmount;
case "leftArmCrossbowPoseAmount" -> leftArmCrossbowPoseAmount;
case "rightArmCrossbowPoseAmount" -> rightArmCrossbowPoseAmount;
case "leftArmShieldPoseAmount" -> leftArmShieldPoseAmount;
case "rightArmShieldPoseAmount" -> rightArmShieldPoseAmount;
case "leftArmSpyglassPoseAmount" -> leftArmSpyglassPoseAmount;
case "rightArmSpyglassPoseAmount" -> rightArmSpyglassPoseAmount;
default -> 0;
};
}
public void setAnimationVariable(String variableType, float newValue){
switch (variableType) {
case "crouchAmount" -> crouchAmount = newValue;
case "inAirAmount" -> inAirAmount = newValue;
case "kneelAmount" -> kneelAmount = newValue;
case "sprintAmount" -> sprintAmount = newValue;
case "verticalMovementRotation" -> verticalMovementRotation = newValue;
case "leftArmItemPoseAmount" -> leftArmItemPoseAmount = newValue;
case "rightArmItemPoseAmount" -> rightArmItemPoseAmount = newValue;
case "leftArmBowPoseAmount" -> leftArmBowPoseAmount = newValue;
case "rightArmBowPoseAmount" -> rightArmBowPoseAmount = newValue;
case "leftArmSpearPoseAmount" -> leftArmSpearPoseAmount = newValue;
case "rightArmSpearPoseAmount" -> rightArmSpearPoseAmount = newValue;
case "leftArmCrossbowPoseAmount" -> leftArmCrossbowPoseAmount = newValue;
case "rightArmCrossbowPoseAmount" -> rightArmCrossbowPoseAmount = newValue;
case "leftArmShieldPoseAmount" -> leftArmShieldPoseAmount = newValue;
case "rightArmShieldPoseAmount" -> rightArmShieldPoseAmount = newValue;
case "leftArmSpyglassPoseAmount" -> leftArmSpyglassPoseAmount = newValue;
case "rightArmSpyglassPoseAmount" -> rightArmSpyglassPoseAmount = newValue;
default -> System.out.println("Invalid variable type: " + variableType);
}
}
}

0 comments on commit 0bc0631

Please sign in to comment.