Rohan Verma



Commit Diff


commit - b5f08f15ef3b29e99dba8e770deec84d782432b1
commit + cd244aec45f78551187b79801c380b9f622225be
blob - 2fdb29677f7c9d3eebd2bf0b174f0bf28c5b6849
blob + 52d7997f6730ad507b16510366f1ff0495696c60
--- src/main/java/com/hattolo/consolesounds/mixin/ExitScreenMixin.java
+++ src/main/java/com/hattolo/consolesounds/mixin/ExitScreenMixin.java
@@ -3,8 +3,10 @@ package com.hattolo.consolesounds.mixin;
 import com.hattolo.consolesounds.ConsoleSoundsClient;
 import com.hattolo.consolesounds.ConsoleSoundsConfig;
 import me.shedaniel.autoconfig.AutoConfig;
+import net.fabricmc.fabric.mixin.networking.accessor.MinecraftClientAccessor;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.widget.ClickableWidget;
 import net.minecraft.client.sound.PositionedSoundInstance;
 import org.lwjgl.glfw.GLFW;
 import org.spongepowered.asm.mixin.Mixin;
@@ -16,20 +18,12 @@ import org.spongepowered.asm.mixin.injection.callback.
 public class ExitScreenMixin {
     @Inject(at = @At("RETURN"), method = "keyPressed")
     private void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
+        var screen = (Screen) (Object) this;
+
         //System.out.println("Key pressed");
-        if (cir.getReturnValue()) {
-            if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_BACKSPACE || keyCode == GLFW.GLFW_KEY_DELETE || keyCode == GLFW.GLFW_KEY_HOME || keyCode == GLFW.GLFW_KEY_END || keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_RIGHT || keyCode == GLFW.GLFW_KEY_UP || keyCode == GLFW.GLFW_KEY_DOWN) return;
-            if (modifiers == GLFW.GLFW_MOD_CONTROL) return;
-
+        if (keyCode == GLFW.GLFW_KEY_ESCAPE && screen.shouldCloseOnEsc()) {
             //System.out.println("Play sound");
             if (AutoConfig.getConfigHolder(ConsoleSoundsConfig.class).getConfig().playSoundOnMenuExit) MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleSoundsClient.UI_BACK_EVENT, 1.0F));
         }
-        /*
-        System.out.println("Key pressed");
-        if (keyCode == GLFW.GLFW_KEY_ESCAPE && Screen.shouldCloseOnEsc()) {
-            System.out.println("Play sound");
-            MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleModClient.UI_BACK_EVENT, 1.0F));
-        }
-         */
     }
 }
blob - af6e2df1153c0ae6cea1867d7f52f278533b4591
blob + 8d5a1160f9475ceb05307443338f7a716524ba3b
--- src/main/java/com/hattolo/consolesounds/mixin/ScrollSliderWidgetMixin.java
+++ src/main/java/com/hattolo/consolesounds/mixin/ScrollSliderWidgetMixin.java
@@ -8,25 +8,26 @@ import net.minecraft.client.sound.PositionedSoundInsta
 import net.minecraft.client.gui.widget.SliderWidget;
 import net.minecraft.util.math.MathHelper;
 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;
 
 @Mixin(SliderWidget.class)
 public class ScrollSliderWidgetMixin {
-    double oldValue = -9999;
+    @Shadow protected double value;
 
     @Inject(at = @At("HEAD"), method = "setValue")
-    private void init(double value, CallbackInfo ci) {
-        double v = MathHelper.clamp(roundDown2(value), 0.0D, 1.0D);
-        double ov = MathHelper.clamp(roundDown2(oldValue), 0.0D, 1.0D);
+    private void setValue(double newValue, CallbackInfo ci) {
+        double v = MathHelper.clamp(roundDown2(newValue), 0.0D, 1.0D);
+        double ov = MathHelper.clamp(roundDown2(value), 0.0D, 1.0D);
 
         if (v != ov && AutoConfig.getConfigHolder(ConsoleSoundsConfig.class).getConfig().enableSliderSounds) MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleSoundsClient.UI_SCROLL_EVENT, 1.0F));
-        oldValue = value;
 
         //System.out.println("value: " + value + " oldvalue: " + oldValue + " v: " + v + " ov: " + ov);
     }
 
+    // makes decimals not go beyond the hundredths place
     private static double roundDown2(double d) {
         return Math.floor(d * 1e2) / 1e2;
     }
blob - 17c0006724fb1ff1f3725c299ae945641a925a8d
blob + dec99550e4e5b773c74865f28a896990ac9b9f28
--- src/main/java/com/hattolo/consolesounds/mixin/SelectClickableWidgetMixin.java
+++ src/main/java/com/hattolo/consolesounds/mixin/SelectClickableWidgetMixin.java
@@ -7,6 +7,7 @@ import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.widget.ClickableWidget;
 import net.minecraft.client.sound.PositionedSoundInstance;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@@ -22,8 +23,11 @@ public class SelectClickableWidgetMixin {
 
 	@Inject(at = @At("RETURN"), method = "isHovered")
 	private void isHovered(CallbackInfoReturnable<Boolean> cir) {
+		var widget = (ClickableWidget) (Object) this;
+
 		if (cir.getReturnValue()) {
-			if (selected == false) {
+			if (!widget.active) return;
+			if (!selected) {
 				selected = true;
 				if (AutoConfig.getConfigHolder(ConsoleSoundsConfig.class).getConfig().enableHoverSounds) MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleSoundsClient.UI_SELECT_EVENT, randFloat(0.9f, 1.1f)));
 			}
blob - da69566104f134a1fbaa432ccdca2b8d34cdf812
blob + 432d3de4e2beff3adb361229e40ea27ef29cd509
--- src/main/java/com/hattolo/consolesounds/mixin/SlotClickedRecipeBookMixin.java
+++ src/main/java/com/hattolo/consolesounds/mixin/SlotClickedRecipeBookMixin.java
@@ -1,26 +1,35 @@
 package com.hattolo.consolesounds.mixin;
 
 import com.hattolo.consolesounds.ConsoleSoundsClient;
+import com.hattolo.consolesounds.ConsoleSoundsConfig;
+import me.shedaniel.autoconfig.AutoConfig;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.screen.ingame.CraftingScreen;
+import net.minecraft.client.gui.screen.recipebook.RecipeBookGhostSlots;
 import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
 import net.minecraft.client.sound.PositionedSoundInstance;
+import net.minecraft.screen.AbstractRecipeScreenHandler;
 import net.minecraft.screen.slot.Slot;
 import net.minecraft.sound.SoundEvents;
 import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Final;
 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;
 
-// unused mixin
-
 @Mixin(RecipeBookWidget.class)
 public class SlotClickedRecipeBookMixin {
+    @Shadow protected AbstractRecipeScreenHandler<?> craftingScreenHandler;
+    @Shadow @Final protected RecipeBookGhostSlots ghostSlots;
+
     @Inject(at = @At("HEAD"), method = "slotClicked")
-    private void init(@Nullable Slot slot, CallbackInfo ci) {
-        if (slot != null && slot.id < 4) {
-            MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleSoundsClient.UI_FAIL_EVENT, 1.0F));
+    private void slotClicked(@Nullable Slot slot, CallbackInfo ci) {
+        if (slot != null && slot.id < craftingScreenHandler.getCraftingSlotCount()) {
+            if (ghostSlots.getSlotCount() > 0) {
+                if (AutoConfig.getConfigHolder(ConsoleSoundsConfig.class).getConfig().enableCraftingSounds) MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(ConsoleSoundsClient.UI_FAIL_EVENT, 1.0F));
+            }
         }
     }
 }
blob - 2d477840540ec29e483157cca17a72b727c0f517
blob + c4f730d38a0658057aa1e187f705ca73768a1c81
--- src/main/resources/consolemod.mixins.json
+++ src/main/resources/consolemod.mixins.json
@@ -14,6 +14,7 @@
     "ClickHandledScreenMixin",
     "ClickCreativeInventoryScreenMixin",
     "CraftItemStackMixin",
+    "SlotClickedRecipeBookMixin",
     "OpenPauseMenuMixin",
     "ScrollSliderWidgetMixin"
   ],