Skip to content

Commit

Permalink
fix: Mixin refmap issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
IMB11 committed Aug 18, 2024
1 parent 025b94d commit eeef57c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 31 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ processResources {
filesMatching("pack.mcmeta") {
expand("pack_format": packFormat)
}

filesMatching("sounds.mixins.json") {
expand("version": mcVersion + "-" + loader)
}
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 3 additions & 2 deletions src/main/resources/sounds.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"compat.InventorioCompatMixin",
"ui.AnvilTypingEffect",
"ui.CreativeInventorySoundEffects",
"ui.CreativeInventorySoundEffects$CreativeScreenHandlerMixin",
"ui.CreativeScreenHandlerMixin",
"ui.HotbarSoundEffects",
"ui.ImageRenderManagerMixin",
"ui.ItemDragSoundEffect",
Expand All @@ -39,5 +39,6 @@
],
"injectors": {
"defaultRequire": 1
}
},
"refmap": "Sounds-${version}-refmap.json"
}

0 comments on commit eeef57c

Please sign in to comment.