Skip to content

Commit

Permalink
Fix DeathAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Apr 19, 2024
1 parent 89a9f4a commit 55171bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface DeathAnimation {

int getDeathTime();

Runnable executeDeathAnimation();
Runnable getDeathAnimation();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.mmodding.mmodding_lib.library.client.utils;

import com.mmodding.mmodding_lib.mixin.accessors.SinglePartEntityModelAccessor;
import com.mmodding.mmodding_lib.mixin.accessors.client.AnimatorAccessor;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.animation.Animation;
import net.minecraft.client.render.animation.AnimationKeyframe;
import net.minecraft.client.render.animation.Animator;
import net.minecraft.client.render.animation.PartAnimation;
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
import net.minecraft.entity.AnimationState;
import net.minecraft.entity.LivingEntity;
Expand All @@ -15,9 +11,6 @@
import net.minecraft.util.math.Vec3f;
import org.quiltmc.loader.api.minecraft.ClientOnly;

import java.util.List;
import java.util.Optional;

@ClientOnly
public class AnimationUtils {

Expand All @@ -41,22 +34,25 @@ public static void updateAnimation(SinglePartEntityModel<?> model, Animation ani
}

public static void animateSmoothly(SinglePartEntityModel<?> model, Animation animation, Animation lastAnimation, long duration, float strength, Vec3f animationCache, int smooth) {
float f = AnimatorAccessor.invokeGetAnimationTimestamp(animation, duration);
Animator.animate(model, animation, duration, strength, animationCache);
/* float f = AnimatorAccessor.invokeGetAnimationTimestamp(animation, duration);
animation.animations().forEach((string, parts) -> {
List<PartAnimation> lastParts = lastAnimation.animations().get(string);
Optional<ModelPart> optionalModelPart = model.findPart(string);
optionalModelPart.ifPresent(modelPart -> parts.forEach(current -> lastParts.forEach(lastPart -> {
AnimationKeyframe[] animationKeyframes = current.keyframes();
AnimationKeyframe[] lastAnimationKeyFrames = lastPart.keyframes();
int i = Math.max(0, MathHelper.binarySearch(0, lastAnimationKeyFrames.length, index -> f <= lastAnimationKeyFrames[index].timestamp()) - 1);
int j = Math.min(animationKeyframes.length - 1, i + 1);
AnimationKeyframe lastAnimationKeyFrame = lastAnimationKeyFrames[i];
AnimationKeyframe endAnimationKeyFrame = animationKeyframes[j];
float h = f - lastAnimationKeyFrame.timestamp();
float k = MathHelper.clamp(h / (endAnimationKeyFrame.timestamp() - lastAnimationKeyFrame.timestamp()), 0.0f, 1.0f);
endAnimationKeyFrame.interpolator().apply(animationCache, k / smooth, animationKeyframes, i, j, strength);
current.transformation().apply(modelPart, animationCache);
})));
});
if (lastParts != null) {
Optional<ModelPart> optionalModelPart = model.findPart(string);
optionalModelPart.ifPresent(modelPart -> parts.forEach(current -> lastParts.forEach(lastPart -> {
AnimationKeyframe[] animationKeyframes = current.keyframes();
AnimationKeyframe[] lastAnimationKeyFrames = lastPart.keyframes();
int i = Math.max(0, MathHelper.binarySearch(0, lastAnimationKeyFrames.length, index -> f <= lastAnimationKeyFrames[index].timestamp()) - 1);
int j = Math.min(animationKeyframes.length - 1, i + 1);
AnimationKeyframe lastAnimationKeyFrame = lastAnimationKeyFrames[i];
AnimationKeyframe endAnimationKeyFrame = animationKeyframes[j];
float h = f - lastAnimationKeyFrame.timestamp();
float k = MathHelper.clamp(h / (endAnimationKeyFrame.timestamp() - lastAnimationKeyFrame.timestamp()), 0.0f, 1.0f);
endAnimationKeyFrame.interpolator().apply(animationCache, k / smooth, animationKeyframes, i, j, strength);
current.transformation().apply(modelPart, animationCache);
})));
}
}); */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ private void tick(CallbackInfo ci) {

@WrapOperation(method = "updatePostDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;sendEntityStatus(Lnet/minecraft/entity/Entity;B)V"))
private void conditionallyCancelDeathAnimationFirstPart(World instance, Entity entity, byte status, Operation<Void> original) {
if (!(entity instanceof DeathAnimation animation) || animation.executeDeathAnimation() == null) {
if (!(entity instanceof DeathAnimation animation) || animation.getDeathAnimation() == null) {
original.call(instance, entity, status);
}
}

@WrapOperation(method = "updatePostDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;remove(Lnet/minecraft/entity/Entity$RemovalReason;)V"))
private void conditionallyCancelDeathAnimationSecondPart(LivingEntity instance, Entity.RemovalReason removalReason, Operation<Void> original) {
if (!(instance instanceof DeathAnimation animation) || animation.executeDeathAnimation() == null) {
if (!(instance instanceof DeathAnimation animation) || animation.getDeathAnimation() == null) {
original.call(instance, removalReason);
}
}
Expand All @@ -60,8 +60,8 @@ private void conditionallyCancelDeathAnimationSecondPart(LivingEntity instance,
private void updateDeath(CallbackInfo ci) {
LivingEntity livingEntity = (LivingEntity) (Object) this;
if (livingEntity instanceof DeathAnimation deathAnimation) {
if (deathAnimation.executeDeathAnimation() != null && this.deathTime - 1 == 0) {
deathAnimation.executeDeathAnimation().run();
if (deathAnimation.getDeathAnimation() != null && this.deathTime - 1 == 0) {
deathAnimation.getDeathAnimation().run();
}
if (this.deathTime == deathAnimation.getDeathTime() && !this.getWorld().isClient()) {
this.world.sendEntityStatus(livingEntity, EntityStatuses.ADD_DEATH_PARTICLES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ private static int conditionallyCancelDeathAnimationRedOverlay(int original, Liv
else {
bool = entity.hurtTime > 0;
}
return OverlayTexture.packUv(OverlayTexture.getU(whiteOverlayProgress), OverlayTexture.getV(bool));
return OverlayTexture.getV(bool);
}
}

@WrapOperation(method = "setupTransforms", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lnet/minecraft/util/math/Quaternion;)V", ordinal = 1))
private void conditionallyCancelDeathAnimationTransform(MatrixStack instance, Quaternion quaternion, Operation<Void> original, @Local(argsOnly = true) T entity) {
if (!(entity instanceof DeathAnimation animation) || animation.executeDeathAnimation() == null) {
if (!(entity instanceof DeathAnimation animation) || animation.getDeathAnimation() == null) {
original.call(instance, quaternion);
}
}
Expand Down

0 comments on commit 55171bb

Please sign in to comment.