Skip to content

Commit

Permalink
mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jul 11, 2024
1 parent 2da854b commit 8b15a5f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 87 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
maven-group = "band.kessokuteatime"
archives-name = "bounced"
mod = "4.1.0"
mod = "4.1.1"
loader = "fabric"

minecraft = "1.20"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/band/kessokuteatime/bounced/Bounced.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onInitializeClient() {
if (screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen) {
ScreenMouseEvents.beforeMouseClick(screen)
.register((currentScreen, mouseX, mouseY, button) -> {
double centerX = scaledWidth / 2.0, y = 30, width = 310, height = 44;
double centerX = scaledWidth / 2.0, y = 30 + primaryPos(), width = 310, height = 44;
if (!isIntro()
&& mouseX >= centerX - width / 2 && mouseX <= centerX + width / 2
&& mouseY >= y && mouseY <= y + height
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,12 @@
package band.kessokuteatime.bounced.mixin;

import band.kessokuteatime.bounced.Bounced;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* This class is responsible for triggering the title animation before the title screen is rendered.
*/
@Mixin(MinecraftClient.class)
class Trigger {
@Inject(method = "setScreen", at = @At("TAIL"))
private void trigger(Screen screen, CallbackInfo ci) {
if (!(screen instanceof TitleScreen)) Bounced.push();
}
}

/**
* This class is responsible for triggering the title animation when the game starts for the first time.
*/
@Mixin(AccessibilityOnboardingScreen.class)
class AccessibilityOnboardingTrigger {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

/**
* This class is responsible for triggering the animation and animating the splash text.
*/
@Mixin(TitleScreen.class)
public class SplashTextAnimator {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

@Mixin(SplashTextRenderer.class)
class SplashTextTranslator {
class SplashTextAnimator {
/**
* Applies the animation transformation to the splash text.
*/
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/band/kessokuteatime/bounced/mixin/Trigger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package band.kessokuteatime.bounced.mixin;


import band.kessokuteatime.bounced.Bounced;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* This class is responsible for triggering the title animation before the title screen is rendered.
*/
@Mixin(MinecraftClient.class)
public class Trigger {
@Inject(method = "setScreen", at = @At("TAIL"))
private void trigger(Screen screen, CallbackInfo ci) {
if (!(screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen)) Bounced.push();
}
}

/**
* This class is responsible for triggering the title animation when the game starts for the first time.
*/
@Mixin(AccessibilityOnboardingScreen.class)
class AccessibilityOnboardingTrigger {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}

/**
* This class is responsible for triggering the animation and animating the splash text.
*/
@Mixin(TitleScreen.class)
class TitleScreenTrigger {
@Inject(method = "init", at = @At("RETURN"))
private void init(CallbackInfo ci) {
Bounced.init();
}

/**
* Triggers and restarts the animation.
*/
@ModifyArg(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/RotatingCubeMapRenderer;render(FF)V"
), index = 1
)
private float trigger(float progress) {
Bounced.resetWhen(progress > 0.9);
Bounced.update();
return progress;
}
}
33 changes: 17 additions & 16 deletions src/main/resources/bounced.mixins.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"required": true,
"minVersion": "0.8",
"package": "band.kessokuteatime.bounced.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"AccessibilityOnboardingTrigger",
"LogoDrawerAnimator",
"SplashTextAnimator",
"SplashTextTranslator",
"Trigger"
],
"injectors": {
"defaultRequire": 0
}
"required": true,
"minVersion": "0.8",
"package": "band.kessokuteatime.bounced.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
"AccessibilityOnboardingTrigger",
"LogoDrawerAnimator",
"SplashTextAnimator",
"SplashTextTranslator",
"TitleScreenTrigger",
"Trigger"
],
"injectors": {
"defaultRequire": 0
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"depends": {
"fabricloader": "*",
"fabric-api": "*",
"minecraft": "1.20.x"
"minecraft": ["~1.20", "~1.20.1", "~1.20.2"]
},
"suggests": {
"splasher": "*"
Expand Down

0 comments on commit 8b15a5f

Please sign in to comment.