QuickMath/src/main/java/io/gitlab/jfronny/quickmath/mixin/MathHelperMixin.java

55 lines
1.9 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.quickmath.mixin;
2020-08-06 23:55:17 +02:00
import net.minecraft.util.math.MathHelper;
2023-03-14 21:18:06 +01:00
import net.minecraft.util.math.random.Random;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
2021-05-29 15:54:38 +02:00
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2020-08-06 23:55:17 +02:00
@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 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
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
2022-06-08 11:18:34 +02:00
@ModifyVariable(method = "nextInt(Lnet/minecraft/util/math/random/Random;II)I", at = @At("HEAD"), argsOnly = true, ordinal = 0)
2021-05-29 15:54:38 +02:00
private static int adjustRandomDoubleParam(int min) {
return Math.max(min - 1, 0);
2020-08-06 23:55:17 +02:00
}
2022-06-08 11:18:34 +02:00
@Inject(method = "nextFloat(Lnet/minecraft/util/math/random/Random;FF)F", at = @At("TAIL"), cancellable = true)
2021-05-29 15:54:38 +02:00
private static void adjustRandomFloat(CallbackInfoReturnable<Float> ci) {
ci.setReturnValue(ci.getReturnValue() * 0.9f);
2020-08-06 23:55:17 +02:00
}
2022-06-08 11:18:34 +02:00
@ModifyVariable(method = "nextDouble(Lnet/minecraft/util/math/random/Random;DD)D", at = @At("HEAD"), argsOnly = true, ordinal = 0)
2021-05-29 15:54:38 +02:00
private static double adjustRandomDoubleParam(double min) {
return min - 1;
}
2022-06-08 11:18:34 +02:00
@Inject(method = "nextDouble(Lnet/minecraft/util/math/random/Random;DD)D", at = @At("TAIL"), cancellable = true)
2021-05-29 15:54:38 +02:00
private static void adjustRandomDouble(CallbackInfoReturnable<Double> ci) {
ci.setReturnValue((double) floor(ci.getReturnValue()));
2020-08-06 23:55:17 +02:00
}
}