package xyz.illuc.neuralgiacore.mixin.Tfc;

import net.dries007.tfc.util.climate.Climate;
import net.dries007.tfc.util.climate.OverworldClimateModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(OverworldClimateModel.class)
public class MixinOptimizeClimateUpdate {
    @Redirect(
            method = "onChunkLoad",
            at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")
    )
    private boolean redirectSetBlock(WorldGenLevel level, BlockPos pos, BlockState state, int flags)
    {
        // Replace flag 2 with 18 (2 | 16) to prevent block updates
        // Updating every block on chunk load is shrimply unclampable
        // Also idk if it works :neocatwoozy

        return level.setBlock(pos, state, flags == 2 ? Block.UPDATE_NONE : flags);
    }

    @Redirect(
            method = "onChunkLoad",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/level/WorldGenLevel;getBrightness(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/BlockPos;)I"
            )
    )
    private int skipBrightnessCheck(WorldGenLevel level, LightLayer lightLayer, BlockPos pos)
    {
        return 0;
    }
}
