Skip to content

Commit

Permalink
Add AnimationUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Mar 29, 2024
1 parent 8537803 commit e75bad1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mmodding.mmodding_lib.library.client.utils;

import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.quiltmc.loader.api.minecraft.ClientOnly;

@ClientOnly
public class AnimationUtils {

public boolean isMoving(LivingEntity livingEntity, float limbSwingAmount, float motionThreshold) {
Vec3d velocity = livingEntity.getVelocity();
float averageVelocity = (MathHelper.abs((float) velocity.x) + MathHelper.abs((float) velocity.z)) / 2f;
return averageVelocity >= motionThreshold && limbSwingAmount != 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mmodding.mmodding_lib.library.utils;

import net.minecraft.util.math.MathHelper;

public class CycledInteger {

private final int max;
Expand All @@ -18,7 +16,7 @@ public CycledInteger(int value, int max) {
}

public int add(int value) {
return this.value = MathHelper.clamp(this.value + value, 0, this.max);
return this.value = this.value + value > this.max ? this.value + value - this.max : this.value + value;
}

public int get() {
Expand Down

0 comments on commit e75bad1

Please sign in to comment.