diff --git a/build.gradle b/build.gradle index 9f31731..a78d1fd 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ version = project.mod_version group = project.maven_group repositories { + maven { url 'https://jitpack.io' } } dependencies { @@ -15,6 +16,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + implementation include("com.github.KrLite:Equator-Utils:${project.equator_utils_version}") } processResources { diff --git a/gradle.properties b/gradle.properties index db45dba..d1492a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,3 +12,4 @@ archives_base_name = bounced-1.19 # Dependencies fabric_version = 0.71.0+1.19.3 +equator_utils_version = v1.1.0 diff --git a/src/main/java/net/krlite/bounced/Bounced.java b/src/main/java/net/krlite/bounced/Bounced.java index 260c37b..f211e63 100644 --- a/src/main/java/net/krlite/bounced/Bounced.java +++ b/src/main/java/net/krlite/bounced/Bounced.java @@ -1,6 +1,8 @@ package net.krlite.bounced; import net.fabricmc.api.ModInitializer; +import net.krlite.equator.util.Pusher; +import net.krlite.equator.util.Timer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,63 +13,6 @@ public class Bounced implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Pusher PUSHER = new Pusher(true); - public record Timer(long origin, long lasting) { - public Timer(long lasting) { - this(System.currentTimeMillis(), lasting); - } - - public Timer reset() { - return new Timer(lasting); - } - - public long queue() { - return Math.min(queueElapsed(), lasting); - } - - public long queueElapsed() { - return System.currentTimeMillis() - origin; - } - } - - public record Pusher(AtomicBoolean ready) { - public Pusher(boolean ready) { - this(new AtomicBoolean(ready)); - } - - public void push() { - ready.set(true); - } - - public boolean pull() { - return ready.get() && ready.getAndSet(false); - } - - public void and(boolean and, Runnable runnable) { - if (and && pull()) runnable.run(); - } - } - @Override - public void onInitialize() { - } - - /** - * Easing bounce function out, for pretty animations. - * @param origin The origin value. - * @param shift The shift value. - * @param timer The timer. - * @return The eased value. - */ - public static double easeOutBounce(double origin, double shift, Timer timer) { - double progress = timer.queue(); - if ((progress /= timer.lasting()) <= (1 / 2.75)) { - return shift * 7.5625 * Math.pow(progress, 2) + origin; - } else if (progress < (2 / 2.75)) { - return shift * (7.5625 * (progress -= (1.5 / 2.75)) * progress + 0.75) + origin; - } else if (progress < (2.5 / 2.75)) { - return shift * (7.5625 * (progress -= (2.25 / 2.75)) * progress + 0.9375) + origin; - } else { - return shift * (7.5625 * (progress -= (2.625 / 2.75)) * progress + 0.984375) + origin; - } - } + public void onInitialize() {} } diff --git a/src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java b/src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java index c2d2a4b..e77bc7e 100644 --- a/src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java +++ b/src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java @@ -1,6 +1,7 @@ package net.krlite.bounced.mixin; -import net.krlite.bounced.Bounced; +import net.krlite.equator.math.EasingFunctions; +import net.krlite.equator.util.Timer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.TitleScreen; @@ -30,7 +31,7 @@ private void trigger(Screen screen, CallbackInfo ci) { */ @Mixin(TitleScreen.class) public class MinecraftAnimator { - private Bounced.Timer timer = new Bounced.Timer(853); + private Timer timer = new Timer(853); private final double offset = MinecraftClient.getInstance().getWindow().getScaledHeight() / 3.5; private double yPos; @@ -67,7 +68,7 @@ private float trigger(float alpha) { ) ) private void animate(MatrixStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo ci) { - yPos = Bounced.easeOutBounce(-offset, offset, timer); + yPos = EasingFunctions.Bounce.easeOut(timer, offset) - offset; } /** diff --git a/src/main/resources/bounced.mixins.json b/src/main/resources/bounced.mixins.json index 0662894..1a48b16 100644 --- a/src/main/resources/bounced.mixins.json +++ b/src/main/resources/bounced.mixins.json @@ -10,6 +10,6 @@ "Trigger" ], "injectors": { - "defaultRequire": 1 + "defaultRequire": 0 } }