From fa84ac70348d6d7c42daca10d75116870130fcb3 Mon Sep 17 00:00:00 2001 From: The_Fireplace Date: Tue, 20 Jul 2021 19:12:22 -0500 Subject: [PATCH] Narration can now be cancelled on the title screen --- changelog.txt | 3 ++- .../audiobook/mixin/MinecraftClientMixin.java | 2 +- .../audiobook/mixin/ScreenMixin.java | 23 +++++++++++++++++++ src/main/resources/audiobook.mixins.json | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/the_fireplace/audiobook/mixin/ScreenMixin.java diff --git a/changelog.txt b/changelog.txt index 5e78fbd..14e2ffe 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,2 +1,3 @@ Change license to MPL-2.0 -Add Russian translation (kyrtion) \ No newline at end of file +Add Russian translation (kyrtion) +Narration can now be cancelled on the title screen \ No newline at end of file diff --git a/src/main/java/the_fireplace/audiobook/mixin/MinecraftClientMixin.java b/src/main/java/the_fireplace/audiobook/mixin/MinecraftClientMixin.java index c88f555..f7d18e6 100644 --- a/src/main/java/the_fireplace/audiobook/mixin/MinecraftClientMixin.java +++ b/src/main/java/the_fireplace/audiobook/mixin/MinecraftClientMixin.java @@ -29,7 +29,7 @@ private void handleInputEvents(CallbackInfo info) { } else if (AudiobookLogic.isReadableBook(player.getStackInHand(Hand.OFF_HAND))) { AudiobookLogic.playBook(player.getStackInHand(Hand.OFF_HAND)); } - } else if(Audiobook.stopAudiobookKey.isPressed()) { + } else if (Audiobook.stopAudiobookKey.isPressed()) { AudiobookLogic.stopNarration(); } } diff --git a/src/main/java/the_fireplace/audiobook/mixin/ScreenMixin.java b/src/main/java/the_fireplace/audiobook/mixin/ScreenMixin.java new file mode 100644 index 0000000..75daa0b --- /dev/null +++ b/src/main/java/the_fireplace/audiobook/mixin/ScreenMixin.java @@ -0,0 +1,23 @@ +package the_fireplace.audiobook.mixin; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; +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.callback.CallbackInfoReturnable; +import the_fireplace.audiobook.Audiobook; +import the_fireplace.audiobook.AudiobookLogic; + +@Environment(EnvType.CLIENT) +@Mixin(Screen.class) +public final class ScreenMixin { + + @Inject(at = @At(value="HEAD"), method = "keyPressed") + private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable cir) { + if (Audiobook.stopAudiobookKey.matchesKey(keyCode, scanCode)) { + AudiobookLogic.stopNarration(); + } + } +} diff --git a/src/main/resources/audiobook.mixins.json b/src/main/resources/audiobook.mixins.json index b6d6e01..9c16ca5 100644 --- a/src/main/resources/audiobook.mixins.json +++ b/src/main/resources/audiobook.mixins.json @@ -5,7 +5,8 @@ "compatibilityLevel": "JAVA_8", "client": [ "BookScreenMixin", - "MinecraftClientMixin" + "MinecraftClientMixin", + "ScreenMixin" ], "injectors": { "defaultRequire": 1