/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.caffeinemc.mods.sodium.client.model.light.data.LightDataAccess
 *  net.minecraft.class_1920
 *  net.minecraft.class_1944
 *  net.minecraft.class_2338
 *  net.minecraft.class_2338$class_2339
 *  net.minecraft.class_2680
 *  org.spongepowered.asm.mixin.Final
 *  org.spongepowered.asm.mixin.Mixin
 *  org.spongepowered.asm.mixin.Shadow
 *  org.spongepowered.asm.mixin.Unique
 *  org.spongepowered.asm.mixin.injection.At
 *  org.spongepowered.asm.mixin.injection.Inject
 *  org.spongepowered.asm.mixin.injection.ModifyVariable
 *  org.spongepowered.asm.mixin.injection.callback.CallbackInfo
 */
package meteordevelopment.meteorclient.mixin.sodium;

import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.Fullbright;
import meteordevelopment.meteorclient.systems.modules.render.Xray;
import net.caffeinemc.mods.sodium.client.model.light.data.LightDataAccess;
import net.minecraft.class_1920;
import net.minecraft.class_1944;
import net.minecraft.class_2338;
import net.minecraft.class_2680;
import org.spongepowered.asm.mixin.Final;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value={LightDataAccess.class}, remap=false)
public abstract class SodiumLightDataAccessMixin {
    @Unique
    private static final int FULL_LIGHT = 4095;
    @Shadow
    protected class_1920 level;
    @Shadow
    @Final
    private class_2338.class_2339 pos;
    @Unique
    private Xray xray;
    @Unique
    private Fullbright fb;

    @Inject(method={"<init>"}, at={@At(value="TAIL")})
    private void onInit(CallbackInfo info) {
        this.xray = Modules.get().get(Xray.class);
        this.fb = Modules.get().get(Fullbright.class);
    }

    @ModifyVariable(method={"compute"}, at=@At(value="TAIL"), name={"bl"})
    private int compute_modifyBL(int light) {
        class_2680 state;
        if (this.xray.isActive() && !this.xray.isBlocked((state = this.level.method_8320((class_2338)this.pos)).method_26204(), (class_2338)this.pos)) {
            return 4095;
        }
        return light;
    }

    @ModifyVariable(method={"compute"}, at=@At(value="STORE"), name={"sl"})
    private int compute_assignSL(int sl) {
        return Math.max(this.fb.getLuminance(class_1944.field_9284), sl);
    }

    @ModifyVariable(method={"compute"}, at=@At(value="STORE"), name={"bl"})
    private int compute_assignBL(int bl) {
        return Math.max(this.fb.getLuminance(class_1944.field_9282), bl);
    }
}

