From 817e5a0b9e3ec382e32a58f17c11b41510ebd352 Mon Sep 17 00:00:00 2001 From: JFronny Date: Sat, 16 Oct 2021 17:28:07 +0200 Subject: [PATCH] This is art --- .gitlab-ci.yml | 21 +++++++++------- gradle.properties | 6 ++--- .../io/gitlab/jfronny/quickmeth/MathUtil.java | 24 +++++++++---------- .../io/gitlab/jfronny/quickmeth/SinUtil.java | 21 ++++++++++++++++ .../quickmeth/mixin/MathHelperMixin.java | 13 ++++++---- .../quickmeth/mixin/MathHelperMixin2.java | 6 ++--- .../mixin/MixinPerlinNoiseSampler.java | 12 +++++----- .../mixin/MixinSimplexNoiseSampler.java | 10 ++++---- 8 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 src/main/java/io/gitlab/jfronny/quickmeth/SinUtil.java diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d27849f..8d5ce9a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,23 +6,28 @@ variables: before_script: - export GRADLE_USER_HOME=`pwd`/.gradle +stages: + - build + - deploy + build_test: - stage: deploy + stage: build script: - - gradle --build-cache assemble + - gradle --build-cache build - cp build/libs/* ./ - - rm *-dev.jar + - rm *-maven.jar *-sources.jar *-sources-dev.jar + - mv *-dev.jar dev.zip - mv *.jar latest.jar + - mv dev.zip latest-dev.jar artifacts: paths: - build/libs - latest.jar - only: - - master + - latest-dev.jar deploy: + rules: + - if: $CI_COMMIT_TAG && '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^master/' stage: deploy - when: manual script: - - gradle --build-cache publishModrinth - - gradle --build-cache curseforge + - gradle --build-cache build curseforge modrinth diff --git a/gradle.properties b/gradle.properties index fdb5176..11c7bdc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,17 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G # Fabric Properties -# check these on https://modmuss50.me/fabric.html +# check these on https://fabricmc.net/versions.html minecraft_version=1.17.1 yarn_mappings=build.61 loader_version=0.12.1 # Mod Properties -mod_version=1.3.0 +mod_version=1.4.0 maven_group=io.jfronny.gitlab archives_base_name=quickmeth # Dependencies fabric_version=0.40.6+1.17 -jfapi_version=2.0.1 +jfapi_version=2.1.1 modrinth_id=hRVfXPJj modrinth_required_dependencies= diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/MathUtil.java b/src/main/java/io/gitlab/jfronny/quickmeth/MathUtil.java index 2e6473b..773040b 100644 --- a/src/main/java/io/gitlab/jfronny/quickmeth/MathUtil.java +++ b/src/main/java/io/gitlab/jfronny/quickmeth/MathUtil.java @@ -3,35 +3,35 @@ package io.gitlab.jfronny.quickmeth; import net.minecraft.util.math.MathHelper; public class MathUtil { - public static double BoxedInvert(double min, double max, double value) { + public static double boxedInvert(double min, double max, double value) { return max - value + min; } - public static double BoxedInvert(double value) { - return BoxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); + public static double boxedInvert(double value) { + return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); } - public static float BoxedInvert(float min, float max, float value) { + public static float boxedInvert(float min, float max, float value) { return max - value + min; } - public static float BoxedInvert(float value) { - return BoxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); + public static float boxedInvert(float value) { + return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); } - public static long BoxedInvert(long min, long max, long value) { + public static long boxedInvert(long min, long max, long value) { return max - value + min; } - public static long BoxedInvert(long value) { - return BoxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); + public static long boxedInvert(long value) { + return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); } - public static int BoxedInvert(int min, int max, int value) { + public static int boxedInvert(int min, int max, int value) { return max - value + min; } - public static int BoxedInvert(int value) { - return BoxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); + public static int boxedInvert(int value) { + return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value); } } diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/SinUtil.java b/src/main/java/io/gitlab/jfronny/quickmeth/SinUtil.java new file mode 100644 index 0000000..646aa85 --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/quickmeth/SinUtil.java @@ -0,0 +1,21 @@ +package io.gitlab.jfronny.quickmeth; + +// https://github.com/FwuffyPetsOwO/FastMathFabric/blob/main/src/main/java/net/FwuffyPetsOwO/FastMath/FastMath.java +public class SinUtil { + private static final float[] SIN_TABLE_FAST = new float[4096]; + private static final float radToIndex = roundToFloat(651.8986469044033D); + + static { + for (int j = 0; j < SIN_TABLE_FAST.length; ++j) { + SIN_TABLE_FAST[j] = roundToFloat(Math.sin((double) j * Math.PI * 2.0D / 4096.0D)); + } + } + + public static float sin(float value) { + return SIN_TABLE_FAST[(int) (value * radToIndex) & 4095]; + } + + public static float roundToFloat(double d) { + return (float) ((double) Math.round(d * 1.0E8D) / 1.0E8D); + } +} diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin.java b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin.java index 0194135..983979c 100644 --- a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin.java +++ b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin.java @@ -1,6 +1,7 @@ package io.gitlab.jfronny.quickmeth.mixin; import io.gitlab.jfronny.quickmeth.MathUtil; +import io.gitlab.jfronny.quickmeth.SinUtil; import net.minecraft.util.math.MathHelper; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -16,13 +17,17 @@ import java.util.Random; @Mixin(MathHelper.class) public abstract class MathHelperMixin { @Shadow @Final private static Random RANDOM; - @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; } @Inject(method = "sin(F)F", at = @At("TAIL"), cancellable = true) private static void invertSin(CallbackInfoReturnable ci) { - ci.setReturnValue(MathUtil.BoxedInvert(ci.getReturnValue())); + ci.setReturnValue(MathUtil.boxedInvert(ci.getReturnValue())); + } + + @Overwrite + public static float sin(float f) { + return SinUtil.sin(f); } @Overwrite @@ -100,11 +105,11 @@ public abstract class MathHelperMixin { @Overwrite public static long clamp(long value, long min, long max) { - return MathUtil.BoxedInvert(Math.max(Math.min(value, max), min), max, min); + 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 ci) { - ci.setReturnValue(MathUtil.BoxedInvert(ci.getReturnValue(), end, start)); + ci.setReturnValue(MathUtil.boxedInvert(ci.getReturnValue(), end, start)); } } diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin2.java b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin2.java index ccd33cf..f47b6ec 100644 --- a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin2.java +++ b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MathHelperMixin2.java @@ -30,8 +30,8 @@ public class MathHelperMixin2 { ci.setReturnValue(ci.getReturnValue() / 2 + 1); } - @Overwrite + /*@Overwrite public static float clamp(float value, float min, float max) { - return MathUtil.BoxedInvert(Math.max(Math.min(value, max), min), max, min); - } + return MathUtil.boxedInvert(min, max, Math.max(Math.min(value, max), min)); + }*/ } diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinPerlinNoiseSampler.java b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinPerlinNoiseSampler.java index b950f75..9ccf183 100644 --- a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinPerlinNoiseSampler.java +++ b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinPerlinNoiseSampler.java @@ -12,33 +12,33 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public abstract class MixinPerlinNoiseSampler { @ModifyVariable(method = "sample(IIIDDDD)D", at = @At("HEAD"), argsOnly = true, ordinal = 0) private double sampleAdjustX(double localX) { - return MathUtil.BoxedInvert(localX); + return MathUtil.boxedInvert(localX); } @ModifyVariable(method = "sampleDerivative(IIIDDD[D)D", at = @At("HEAD"), argsOnly = true, ordinal = 0) private double derivAdjustX(double localX) { - return MathUtil.BoxedInvert(localX); + return MathUtil.boxedInvert(localX); } //Once again, the y parameter is ignored because mixin @ModifyVariable(method = "sample(IIIDDDD)D", at = @At("HEAD"), argsOnly = true, ordinal = 2) private double sampleAdjustZ(double localZ) { - return MathUtil.BoxedInvert(localZ); + return MathUtil.boxedInvert(localZ); } @ModifyVariable(method = "sampleDerivative(IIIDDD[D)D", at = @At("HEAD"), argsOnly = true, ordinal = 2) private double derivAdjustZ(double localZ) { - return MathUtil.BoxedInvert(localZ); + return MathUtil.boxedInvert(localZ); } @Inject(method = "sample(IIIDDDD)D", at = @At("TAIL"), cancellable = true) private void sampleAsjustResult(CallbackInfoReturnable ret) { - ret.setReturnValue(MathUtil.BoxedInvert(ret.getReturnValue())); + ret.setReturnValue(MathUtil.boxedInvert(ret.getReturnValue())); } @Inject(method = "sampleDerivative(IIIDDD[D)D", at = @At("TAIL"), cancellable = true) private void derivAsjustResult(CallbackInfoReturnable ret) { - ret.setReturnValue(MathUtil.BoxedInvert(ret.getReturnValue())); + ret.setReturnValue(MathUtil.boxedInvert(ret.getReturnValue())); } } diff --git a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java index 78d7b90..805911a 100644 --- a/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java +++ b/src/main/java/io/gitlab/jfronny/quickmeth/mixin/MixinSimplexNoiseSampler.java @@ -12,12 +12,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public abstract class MixinSimplexNoiseSampler { @Inject(method = "sample(DD)D", at = @At("TAIL"), cancellable = true) private void sampleAdjust(CallbackInfoReturnable ret) { - ret.setReturnValue(MathUtil.BoxedInvert(ret.getReturnValue())); + ret.setReturnValue(MathUtil.boxedInvert(ret.getReturnValue())); } @ModifyVariable(method = "sample(DD)D", at = @At("HEAD"), argsOnly = true, ordinal = 0) private double sampleAdjustX(double x) { - return MathUtil.BoxedInvert(x); + return MathUtil.boxedInvert(x); } // The y parameter is ignored here because otherwise this will crash. I don't know why. @@ -28,16 +28,16 @@ public abstract class MixinSimplexNoiseSampler { @ModifyVariable(method = "grad(IDDDD)D", at = @At("HEAD"), argsOnly = true, ordinal = 0) private double gradAdjustX(double x) { - return MathUtil.BoxedInvert(x); + return MathUtil.boxedInvert(x); } // The y parameter is ignored here because otherwise this will crash. I don't know why. @ModifyVariable(method = "grad(IDDDD)D", at = @At("HEAD"), argsOnly = true, ordinal = 2) private double gradAdjustZ(double z) { - return MathUtil.BoxedInvert(z); + return MathUtil.boxedInvert(z); } @Inject(method = "dot([IDDD)D", at = @At("TAIL"), cancellable = true) private static void dotAdjust(CallbackInfoReturnable ret) { - ret.setReturnValue(MathUtil.BoxedInvert(ret.getReturnValue())); + ret.setReturnValue(MathUtil.boxedInvert(ret.getReturnValue())); } }