Skip to content

Commit

Permalink
fix some animation crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Sep 26, 2023
1 parent 9c6f6e0 commit ecb11b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ public boolean isInBounds(Vector2fc position) {
public boolean fingerDown(Vector2fc position) {
KanziConfig config = KanziConfig.INSTANCE.instance();

LocalPlayer player = minecraft().player;
Vector2f distFromCenter = distFromCenter(position);
double touchAngle = Math.atan2(distFromCenter.y(), distFromCenter.x());
Vector2f freeLookDirection = new Vector2f((float) Math.cos(touchAngle), (float) Math.sin(touchAngle));

if (movementAnimation != null) {
if (!movementAnimation.isThisDone())
if (!movementAnimation.isThisDone()) {
return false;
if (resetAnimation != null && resetAnimation.isCurrentlyPlaying())
}
if (resetAnimation != null && resetAnimation.isCurrentlyPlaying()) {
return false;
}
resetAnimation = null;
movementAnimation = null;
}

TouchInput.INSTANCE.cancelMining();

LocalPlayer player = minecraft().player;
Vector2f distFromCenter = distFromCenter(position);
double touchAngle = Math.atan2(distFromCenter.y(), distFromCenter.x());
Vector2f freeLookDirection = new Vector2f((float) Math.cos(touchAngle), (float) Math.sin(touchAngle));

float x = freeLookDirection.x();
float y = freeLookDirection.y();

Expand All @@ -56,22 +58,27 @@ public boolean fingerDown(Vector2fc position) {
if (resetDelay != null && resetDelay.isCurrentlyPlaying())
resetDelay.startAgain();

movementAnimation = Animator.INSTANCE.play(new Animator.AnimationInstance(calculateTickDuration(config.touchLookDegreesPerTap), Animator::easeOutSin)
.addContinualConsumer(f -> player.turn(f / 0.15, 0.0), 0, config.touchLookDegreesPerTap * Math.signum(x)));
int animationTickDuration = calculateTickDuration(config.touchLookDegreesPerTap);
if (animationTickDuration > 0) {
movementAnimation = Animator.INSTANCE.play(new Animator.AnimationInstance(animationTickDuration, Animator::linear)
.addContinualConsumer(f -> player.turn(f / 0.15, 0.0), 0, config.touchLookDegreesPerTap * Math.signum(x)));
}
} else if (Math.abs(y) > Math.abs(x)) {
if (resetDelay != null && resetDelay.isCurrentlyPlaying())
resetDelay.cancelFamily();

int degrees = (int) (Mth.clamp(player.getXRot() + config.touchLookDegreesPerTap * Math.signum(y), -config.maxMinVerticalDegrees, config.maxMinVerticalDegrees) - player.getXRot());
int animationTicks = calculateTickDuration(degrees);

if (degrees != 0) {
movementAnimation = Animator.INSTANCE.play(new Animator.AnimationInstance(calculateTickDuration(degrees), Animator::easeOutSin)
if (animationTicks > 0) {
movementAnimation = Animator.INSTANCE.play(new Animator.AnimationInstance(animationTicks, Animator::linear)
.addContinualConsumer(f -> player.turn(0.0, f / 0.15), 0, config.touchLookDegreesPerTap * Math.signum(y))
);

int resetDegrees = (int) -(player.getXRot() + degrees);
if (resetDegrees != 0) {
resetAnimation = new Animator.AnimationInstance(calculateTickDuration(resetDegrees), Animator::easeOutSin)
int resetAnimationTicks = calculateTickDuration(resetDegrees);
if (resetAnimationTicks > 0) {
resetAnimation = new Animator.AnimationInstance(resetAnimationTicks, Animator::linear)
.addContinualConsumer(f -> player.turn(0.0, f / 0.15), 0, resetDegrees);
if (resetDelay != null && resetDelay.isCurrentlyPlaying()) {
resetDelay.startAgain();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.isxander.kanzicontrol.mixins;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
Expand All @@ -13,6 +14,9 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.GameType;
Expand Down Expand Up @@ -94,4 +98,9 @@ private void modifyRenderType(LevelRenderer instance, PoseStack matrices, Vertex
);
}
}

@ModifyVariable(method = "addParticleInternal(Lnet/minecraft/core/particles/ParticleOptions;ZZDDDDDD)Lnet/minecraft/client/particle/Particle;", at = @At("HEAD"), argsOnly = true, ordinal = 0)
private boolean shouldIgnoreParticleDistanceCheck(boolean alwaysSpawn, ParticleOptions params) {
return alwaysSpawn || params.getType() == ParticleTypes.HAPPY_VILLAGER;
}
}

0 comments on commit ecb11b8

Please sign in to comment.