/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.llamalad7.mixinextras.injector.ModifyExpressionValue
 *  com.llamalad7.mixinextras.injector.v2.WrapWithCondition
 *  net.minecraft.class_10055
 *  net.minecraft.class_1007
 *  net.minecraft.class_1058
 *  net.minecraft.class_11659
 *  net.minecraft.class_11890
 *  net.minecraft.class_12249
 *  net.minecraft.class_1921
 *  net.minecraft.class_2960
 *  net.minecraft.class_4587
 *  net.minecraft.class_5617$class_5618
 *  net.minecraft.class_583
 *  net.minecraft.class_591
 *  net.minecraft.class_630
 *  net.minecraft.class_922
 *  org.spongepowered.asm.mixin.Mixin
 *  org.spongepowered.asm.mixin.Unique
 *  org.spongepowered.asm.mixin.injection.At
 *  org.spongepowered.asm.mixin.injection.Inject
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfo
 */
package meteordevelopment.meteorclient.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.mixininterface.IVec3d;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.Chams;
import meteordevelopment.meteorclient.utils.player.Rotations;
import net.minecraft.class_10055;
import net.minecraft.class_1007;
import net.minecraft.class_1058;
import net.minecraft.class_11659;
import net.minecraft.class_11890;
import net.minecraft.class_12249;
import net.minecraft.class_1921;
import net.minecraft.class_2960;
import net.minecraft.class_4587;
import net.minecraft.class_5617;
import net.minecraft.class_583;
import net.minecraft.class_591;
import net.minecraft.class_630;
import net.minecraft.class_922;
import org.spongepowered.asm.mixin.Mixin;
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(value={class_1007.class})
public abstract class PlayerEntityRendererMixin<AvatarlikeEntity extends class_11890>
extends class_922<AvatarlikeEntity, class_10055, class_591> {
    @Unique
    private Chams chams;

    public PlayerEntityRendererMixin(class_5617.class_5618 ctx, class_591 model, float shadowRadius) {
        super(ctx, (class_583)model, shadowRadius);
    }

    @Inject(method={"<init>"}, at={@At(value="RETURN")})
    private void init$chams(CallbackInfo info) {
        this.chams = Modules.get().get(Chams.class);
    }

    @Inject(method={"method_62604(Lnet/minecraft/class_11890;Lnet/minecraft/class_10055;F)V"}, at={@At(value="RETURN")})
    private void updateRenderState$scale(AvatarlikeEntity player, class_10055 state, float f, CallbackInfo ci) {
        if (!this.chams.isActive() || !this.chams.players.get().booleanValue()) {
            return;
        }
        if (this.chams.ignoreSelf.get().booleanValue() && player == MeteorClient.mc.field_1724) {
            return;
        }
        float v = this.chams.playersScale.get().floatValue();
        state.field_53453 *= v;
        if (state.field_53338 != null) {
            ((IVec3d)state.field_53338).meteor$setY(state.field_53338.field_1351 + (double)(player.method_17682() * v - player.method_17682()));
        }
    }

    @ModifyExpressionValue(method={"method_23205"}, at={@At(value="INVOKE", target="Lnet/minecraft/class_12249;method_76000(Lnet/minecraft/class_2960;)Lnet/minecraft/class_1921;")})
    private class_1921 renderArm$texture(class_1921 original, class_4587 matrixStack, class_11659 entityRenderCommandQueue, int light, class_2960 skinTexture, class_630 modelPart, boolean sleeveVisible) {
        if (this.chams.isActive() && this.chams.hand.get().booleanValue()) {
            class_2960 texture = this.chams.handTexture.get() != false ? skinTexture : Chams.BLANK;
            return class_12249.method_76000((class_2960)texture);
        }
        return original;
    }

    @WrapWithCondition(method={"method_23205"}, at={@At(value="INVOKE", target="Lnet/minecraft/class_11659;method_73491(Lnet/minecraft/class_630;Lnet/minecraft/class_4587;Lnet/minecraft/class_1921;IILnet/minecraft/class_1058;)V")})
    private boolean renderArm$color(class_11659 instance, class_630 modelPart, class_4587 matrixStack, class_1921 renderLayer, int light, int uv, class_1058 sprite) {
        if (this.chams.isActive() && this.chams.hand.get().booleanValue()) {
            instance.method_73492(modelPart, matrixStack, renderLayer, light, uv, null, this.chams.handColor.get().getPacked(), null);
            return false;
        }
        return true;
    }

    @Inject(method={"method_62604(Lnet/minecraft/class_11890;Lnet/minecraft/class_10055;F)V"}, at={@At(value="RETURN")})
    private void updateRenderState$rotations(AvatarlikeEntity player, class_10055 state, float f, CallbackInfo info) {
        if (Rotations.rotating && player == MeteorClient.mc.field_1724) {
            state.field_53447 = 0.0f;
            state.field_53446 = Rotations.serverYaw;
            state.field_53448 = Rotations.serverPitch;
        }
    }
}

