-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Play books without opening the book GUI
- Loading branch information
1 parent
4eb348a
commit 412e9ba
Showing
4 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/the_fireplace/audiobook/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package the_fireplace.audiobook.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ingame.BookScreen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.item.BookItem; | ||
import net.minecraft.util.Hand; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import the_fireplace.audiobook.Audiobook; | ||
import the_fireplace.audiobook.AudiobookLogic; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public abstract class MinecraftClientMixin { | ||
|
||
@Shadow @Nullable public ClientPlayerEntity player; | ||
|
||
@Inject(at = @At(value="HEAD"), method = "handleInputEvents") | ||
private void handleInputEvents(CallbackInfo info) { | ||
if(Audiobook.audiobookKey.isPressed() && player != null) { | ||
//noinspection ConstantConditions | ||
if(player.getStackInHand(Hand.MAIN_HAND).getItem() instanceof BookItem && player.getStackInHand(Hand.MAIN_HAND).hasTag() && player.getStackInHand(Hand.MAIN_HAND).getTag().contains("pages") && !BookScreen.readPages(player.getStackInHand(Hand.MAIN_HAND).getTag()).isEmpty()) | ||
AudiobookLogic.playBook(player.getStackInHand(Hand.MAIN_HAND)); | ||
else if(player.getStackInHand(Hand.OFF_HAND).getItem() instanceof BookItem) | ||
AudiobookLogic.playBook(player.getStackInHand(Hand.OFF_HAND)); | ||
} else if(Audiobook.stopAudiobookKey.isPressed()) | ||
AudiobookLogic.stopNarration(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters