2020-08-06 23:55:17 +02:00
|
|
|
package io.gitlab.jfronny.quickmeth.mixin;
|
|
|
|
|
2021-05-19 15:12:49 +02:00
|
|
|
import io.gitlab.jfronny.quickmeth.MathUtil;
|
2020-08-06 23:55:17 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import org.spongepowered.asm.mixin.Final;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Overwrite;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
2021-05-29 15:54:38 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
2020-08-06 23:55:17 +02:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
@Mixin(MathHelper.class)
|
2021-05-29 15:54:38 +02:00
|
|
|
public abstract class MathHelperMixin {
|
2020-08-06 23:55:17 +02:00
|
|
|
@Shadow @Final private static Random RANDOM;
|
2021-05-29 15:54:38 +02:00
|
|
|
@Shadow public static float sin(float value) { return 0; }
|
|
|
|
@Shadow public static int floor(double value) { return 0; }
|
|
|
|
@Shadow public static double nextDouble(Random random, double min, double max) { return 0; }
|
2020-08-06 23:55:17 +02:00
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
@Inject(method = "sin(F)F", at = @At("TAIL"), cancellable = true)
|
|
|
|
private static void invertSin(CallbackInfoReturnable<Float> ci) {
|
|
|
|
ci.setReturnValue(MathUtil.BoxedInvert(ci.getReturnValue()));
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
@Overwrite
|
|
|
|
public static float cos(float f) { return sin(f); }
|
2020-08-06 23:55:17 +02:00
|
|
|
|
|
|
|
@Overwrite
|
2021-05-29 15:54:38 +02:00
|
|
|
public static float sqrt(float f) {
|
|
|
|
return (float)Math.pow(f, 0.6);
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Overwrite
|
|
|
|
public static int fastFloor(double d) {
|
2021-05-29 15:54:38 +02:00
|
|
|
return (int)(d / 32) * 32;
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
2020-08-07 00:18:24 +02:00
|
|
|
@Overwrite
|
|
|
|
public static long lfloor(double d) {
|
2021-05-29 15:54:38 +02:00
|
|
|
return (long) (Math.floor(d / 4) * 4);
|
2020-08-07 00:18:24 +02:00
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
|
|
|
|
@Overwrite
|
2021-05-29 15:54:38 +02:00
|
|
|
public static double absMax(double d, double e) {
|
|
|
|
if (d > 0.0D) {
|
|
|
|
d = -d;
|
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
if (e > 0.0D) {
|
|
|
|
e = -e;
|
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
if (e < -16)
|
|
|
|
e += 3;
|
2020-08-06 23:55:17 +02:00
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
return -1 - Math.max(d, e);
|
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
@ModifyVariable(method = "nextInt(Ljava/util/Random;II)I", at = @At("HEAD"), argsOnly = true, ordinal = 0)
|
|
|
|
private static int adjustRandomDoubleParam(int min) {
|
|
|
|
return Math.max(min - 1, 0);
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
@Inject(method = "nextFloat(Ljava/util/Random;FF)F", at = @At("TAIL"), cancellable = true)
|
|
|
|
private static void adjustRandomFloat(CallbackInfoReturnable<Float> ci) {
|
|
|
|
ci.setReturnValue(ci.getReturnValue() * 0.9f);
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
2021-05-29 15:54:38 +02:00
|
|
|
@ModifyVariable(method = "nextDouble(Ljava/util/Random;DD)D", at = @At("HEAD"), argsOnly = true, ordinal = 0)
|
|
|
|
private static double adjustRandomDoubleParam(double min) {
|
|
|
|
return min - 1;
|
|
|
|
}
|
|
|
|
@Inject(method = "nextDouble(Ljava/util/Random;DD)D", at = @At("TAIL"), cancellable = true)
|
|
|
|
private static void adjustRandomDouble(CallbackInfoReturnable<Double> ci) {
|
|
|
|
ci.setReturnValue((double) floor(ci.getReturnValue()));
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Overwrite
|
|
|
|
public static double average(long[] array) {
|
|
|
|
long[] var3 = array;
|
|
|
|
|
|
|
|
long min = Long.MAX_VALUE;
|
|
|
|
long max = Long.MIN_VALUE;
|
|
|
|
|
|
|
|
int var4 = array.length;
|
|
|
|
|
|
|
|
for(int var5 = 0; var5 < var4; ++var5) {
|
|
|
|
long m = var3[var5];
|
|
|
|
if (m > max)
|
|
|
|
max = m;
|
|
|
|
if (m < min)
|
|
|
|
min = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextDouble(RANDOM, min, max);
|
|
|
|
}
|
2021-05-29 15:54:38 +02:00
|
|
|
|
|
|
|
@Overwrite
|
|
|
|
public static long clamp(long value, long min, long max) {
|
|
|
|
return MathUtil.BoxedInvert(Math.max(Math.min(value, max), min), max, min);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "clampedLerp(DDD)D", at = @At("TAIL"), cancellable = true)
|
|
|
|
private static void adjustClampedLerp(double start, double end, double delta, CallbackInfoReturnable<Double> ci) {
|
|
|
|
ci.setReturnValue(MathUtil.BoxedInvert(ci.getReturnValue(), end, start));
|
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|