/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_1297
 *  net.minecraft.class_1297$class_5529
 *  net.minecraft.class_2246
 *  net.minecraft.class_2338
 *  net.minecraft.class_2350
 *  net.minecraft.class_2680
 *  net.minecraft.class_638
 *  org.jetbrains.annotations.Nullable
 *  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.ModifyArgs
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfo
 *  org.spongepowered.asm.mixin.injection.invoke.arg.Args
 */
package meteordevelopment.meteorclient.mixin;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.EntityAddedEvent;
import meteordevelopment.meteorclient.events.entity.EntityRemovedEvent;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.NoRender;
import net.minecraft.class_1297;
import net.minecraft.class_2246;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_2680;
import net.minecraft.class_638;
import org.jetbrains.annotations.Nullable;
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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(value={class_638.class})
public abstract class ClientWorldMixin {
    @Shadow
    @Nullable
    public abstract class_1297 method_8469(int var1);

    @Inject(method={"method_53875"}, at={@At(value="TAIL")})
    private void onAddEntity(class_1297 entity, CallbackInfo info) {
        if (entity != null) {
            MeteorClient.EVENT_BUS.post((Object)EntityAddedEvent.get(entity));
        }
    }

    @Inject(method={"method_2945"}, at={@At(value="HEAD")})
    private void onRemoveEntity(int entityId, class_1297.class_5529 removalReason, CallbackInfo info) {
        if (this.method_8469(entityId) != null) {
            MeteorClient.EVENT_BUS.post((Object)EntityRemovedEvent.get(this.method_8469(entityId)));
        }
    }

    @ModifyArgs(method={"method_2941"}, at=@At(value="INVOKE", target="Lnet/minecraft/class_638;method_2943(IIIILnet/minecraft/class_5819;Lnet/minecraft/class_2248;Lnet/minecraft/class_2338$class_2339;)V"))
    private void doRandomBlockDisplayTicks(Args args) {
        if (Modules.get().get(NoRender.class).noBarrierInvis()) {
            args.set(5, (Object)class_2246.field_10499);
        }
    }

    @Inject(method={"method_31595"}, at={@At(value="HEAD")}, cancellable=true)
    private void onAddBlockBreakParticles(class_2338 blockPos, class_2680 state, CallbackInfo info) {
        if (Modules.get().get(NoRender.class).noBlockBreakParticles()) {
            info.cancel();
        }
    }

    @Inject(method={"method_74254"}, at={@At(value="HEAD")}, cancellable=true)
    private void onAddBlockBreakingParticles(class_2338 blockPos, class_2350 direction, CallbackInfo info) {
        if (Modules.get().get(NoRender.class).noBlockBreakParticles()) {
            info.cancel();
        }
    }
}

