/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.llamalad7.mixinextras.sugar.Local
 *  meteordevelopment.orbit.ICancellable
 *  net.minecraft.class_1113
 *  net.minecraft.class_1117
 *  net.minecraft.class_1140
 *  net.minecraft.class_1140$class_11518
 *  org.spongepowered.asm.mixin.Mixin
 *  org.spongepowered.asm.mixin.Shadow
 *  org.spongepowered.asm.mixin.injection.At
 *  org.spongepowered.asm.mixin.injection.Inject
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfo
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
 */
package meteordevelopment.meteorclient.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.PlaySoundEvent;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.misc.SoundBlocker;
import meteordevelopment.orbit.ICancellable;
import net.minecraft.class_1113;
import net.minecraft.class_1117;
import net.minecraft.class_1140;
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value={class_1140.class})
public abstract class SoundSystemMixin {
    @Shadow
    public abstract void method_19753(class_1113 var1);

    @Inject(method={"method_4854(Lnet/minecraft/class_1113;)Lnet/minecraft/class_1140$class_11518;"}, at={@At(value="HEAD")}, cancellable=true)
    private void onPlay(class_1113 soundInstance, CallbackInfoReturnable<class_1140.class_11518> cir) {
        PlaySoundEvent event = (PlaySoundEvent)MeteorClient.EVENT_BUS.post((ICancellable)PlaySoundEvent.get(soundInstance));
        if (event.isCancelled()) {
            cir.cancel();
        }
    }

    @Inject(method={"method_4857()V"}, at={@At(value="INVOKE", target="Lnet/minecraft/class_1117;method_16896()V", ordinal=0)})
    private void onTick(CallbackInfo ci, @Local class_1117 tickableSoundInstance) {
        if (Modules.get().get(SoundBlocker.class).shouldBlock((class_1113)tickableSoundInstance)) {
            this.method_19753((class_1113)tickableSoundInstance);
        }
    }
}

