Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jan 5, 2023
1 parent 01f2c4b commit 5bb03cb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 62 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ version = project.mod_version
group = project.maven_group

repositories {
maven { url 'https://jitpack.io' }
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
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 {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 3 additions & 58 deletions src/main/java/net/krlite/bounced/Bounced.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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() {}
}
7 changes: 4 additions & 3 deletions src/main/java/net/krlite/bounced/mixin/MinecraftAnimator.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bounced.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"Trigger"
],
"injectors": {
"defaultRequire": 1
"defaultRequire": 0
}
}

0 comments on commit 5bb03cb

Please sign in to comment.