Skip to content

Commit

Permalink
Make sound played event multi-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 23, 2024
1 parent a4cd653 commit 8606301
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions versions/mappings/forge-1.12.2-1.8.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ net.minecraft.network.play.server.SPacketCustomPayload net.minecraft.network.pla

net.minecraft.util.math.BlockPos net.minecraft.util.BlockPos

net.minecraft.util.SoundCategory net.minecraft.client.audio.SoundCategory

net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent
net.minecraft.util.text.TextFormatting net.minecraft.util.EnumChatFormatting

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.polyfrost.oneconfig.internal.mixin;

import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.audio.SoundManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(SoundManager.class)
public interface SoundManagerAccessorMixin {

@Accessor
SoundHandler getSndHandler();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.polyfrost.oneconfig.internal.mixin;

import net.minecraft.client.audio.ISound;
//#if MC <= 1.8.9
import net.minecraft.client.audio.SoundEventAccessorComposite;
//#endif

import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.audio.SoundManager;
import org.polyfrost.oneconfig.api.event.v1.EventManager;
import org.polyfrost.oneconfig.api.event.v1.events.SoundPlayedEvent;
Expand All @@ -16,14 +20,24 @@ public class SoundManagerMixin {
method = "playSound",
at = @At(
value = "INVOKE",
//#if MC >= 1.12.2
//$$ target = "Lnet/minecraft/client/audio/ISound;createAccessor(Lnet/minecraft/client/audio/SoundHandler;)Lnet/minecraft/client/audio/SoundEventAccessor;"
//#else
target = "Lnet/minecraft/client/audio/SoundHandler;getSound(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/audio/SoundEventAccessorComposite;"
//#endif
),
argsOnly = true
)
private ISound oneconfig$playSound(ISound value) {
SoundEventAccessorComposite accessor = ((SoundManager) (Object) this).sndHandler.getSound(value.getSoundLocation());
//#if MC <= 1.8.9
SoundEventAccessorComposite accessor = ((SoundManagerAccessorMixin) this).getSndHandler().getSound(value.getSoundLocation());
SoundCategory category = (accessor == null ? null : accessor.getSoundCategory());
//#else
//$$ SoundCategory category = value.getCategory();
//#endif

String name = value.getSoundLocation().getResourcePath();
SoundPlayedEvent event = new SoundPlayedEvent(name, (accessor == null ? null : accessor.getSoundCategory()), value);
SoundPlayedEvent event = new SoundPlayedEvent(name, category, value);
EventManager.INSTANCE.post(event);
return event.getSound();
}
Expand Down
1 change: 1 addition & 0 deletions versions/src/main/resources/mixins.oneconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ScoreboardMixin",
"ShaderGroupAccessor",
"SoundManagerMixin",
"SoundManagerAccessorMixin",
"WorldClientMixin",
"SoundManagerMixin",
"compat.OptifineConfigMixin",
Expand Down

0 comments on commit 8606301

Please sign in to comment.