diff --git a/build.gradle b/build.gradle index edfe7da..04e9d0f 100644 --- a/build.gradle +++ b/build.gradle @@ -221,6 +221,10 @@ processResources { filesMatching("pack.mcmeta") { expand("pack_format": packFormat) } + + filesMatching("sounds.mixins.json") { + expand("version": mcVersion + "-" + loader) + } } jar { diff --git a/src/main/java/dev/imb11/sounds/mixin/ui/CreativeInventorySoundEffects.java b/src/main/java/dev/imb11/sounds/mixin/ui/CreativeInventorySoundEffects.java index f815fc0..15b0587 100644 --- a/src/main/java/dev/imb11/sounds/mixin/ui/CreativeInventorySoundEffects.java +++ b/src/main/java/dev/imb11/sounds/mixin/ui/CreativeInventorySoundEffects.java @@ -92,33 +92,4 @@ protected CreativeInventorySoundEffects(CreativeInventoryScreen.CreativeScreenHa ItemStack stack = this.handler.getCursorStack(); SoundsConfig.get(UISoundsConfig.class).itemClickSoundEffect.playDynamicSound(stack, ItemStackSoundContext.of(DynamicSoundHelper.BlockSoundType.PLACE)); } - - @Mixin(CreativeInventoryScreen.CreativeScreenHandler.class) - public static abstract class CreativeScreenHandlerMixin { - @Unique - private double prevTime = 0L; - @Unique - private float prevValue = -69420f; - - @Shadow - public abstract ItemStack getCursorStack(); - - @Inject(method = "setCursorStack", at = @At("HEAD"), cancellable = false) - public void $item_delete_sound_effect(ItemStack stack, CallbackInfo ci) { - if (MixinStatics.CURRENT_SLOT == MixinStatics.DELETE_ITEM_SLOT && !getCursorStack().isEmpty()) - SoundsConfig.get(UISoundsConfig.class).itemDeleteSoundEffect.playDynamicSound(getCursorStack(), ItemStackSoundContext.of(DynamicSoundHelper.BlockSoundType.HIT)); - } - - @Inject(method = "scrollItems", at = @At("TAIL")) - public void $inventory_scroll_sound_effect(float position, CallbackInfo ci) { - double currentTime = GLFW.glfwGetTime(); - double timeElapsed = currentTime - prevTime; - - if (timeElapsed >= 0.05 && prevValue != position) { - SoundsConfig.get(UISoundsConfig.class).inventoryScrollSoundEffect.playSound(); - prevTime = currentTime; - prevValue = position; - } - } - } } diff --git a/src/main/java/dev/imb11/sounds/mixin/ui/CreativeScreenHandlerMixin.java b/src/main/java/dev/imb11/sounds/mixin/ui/CreativeScreenHandlerMixin.java new file mode 100644 index 0000000..b998ad6 --- /dev/null +++ b/src/main/java/dev/imb11/sounds/mixin/ui/CreativeScreenHandlerMixin.java @@ -0,0 +1,45 @@ +package dev.imb11.sounds.mixin.ui; + +import dev.imb11.sounds.config.SoundsConfig; +import dev.imb11.sounds.config.UISoundsConfig; +import dev.imb11.sounds.dynamic.DynamicSoundHelper; +import dev.imb11.sounds.sound.context.ItemStackSoundContext; +import dev.imb11.sounds.util.MixinStatics; +import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.item.ItemStack; +import org.lwjgl.glfw.GLFW; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(CreativeInventoryScreen.CreativeScreenHandler.class) +public abstract class CreativeScreenHandlerMixin { + @Unique + private double prevTime = 0L; + @Unique + private float prevValue = -69420f; + + @Shadow + public abstract ItemStack getCursorStack(); + + @Inject(method = "setCursorStack", at = @At("HEAD"), cancellable = false) + public void $item_delete_sound_effect(ItemStack stack, CallbackInfo ci) { + if (MixinStatics.CURRENT_SLOT == MixinStatics.DELETE_ITEM_SLOT && !getCursorStack().isEmpty()) + SoundsConfig.get(UISoundsConfig.class).itemDeleteSoundEffect.playDynamicSound(getCursorStack(), ItemStackSoundContext.of(DynamicSoundHelper.BlockSoundType.HIT)); + } + + @Inject(method = "scrollItems", at = @At("TAIL")) + public void $inventory_scroll_sound_effect(float position, CallbackInfo ci) { + double currentTime = GLFW.glfwGetTime(); + double timeElapsed = currentTime - prevTime; + + if (timeElapsed >= 0.05 && prevValue != position) { + SoundsConfig.get(UISoundsConfig.class).inventoryScrollSoundEffect.playSound(); + prevTime = currentTime; + prevValue = position; + } + } +} diff --git a/src/main/resources/sounds.mixins.json b/src/main/resources/sounds.mixins.json index 6a7e42d..4b86caf 100644 --- a/src/main/resources/sounds.mixins.json +++ b/src/main/resources/sounds.mixins.json @@ -16,7 +16,7 @@ "compat.InventorioCompatMixin", "ui.AnvilTypingEffect", "ui.CreativeInventorySoundEffects", - "ui.CreativeInventorySoundEffects$CreativeScreenHandlerMixin", + "ui.CreativeScreenHandlerMixin", "ui.HotbarSoundEffects", "ui.ImageRenderManagerMixin", "ui.ItemDragSoundEffect", @@ -39,5 +39,6 @@ ], "injectors": { "defaultRequire": 1 - } + }, + "refmap": "Sounds-${version}-refmap.json" }