package asm.mixins;

import dev.crucifixbeta.mod.modules.impl.render.Ambience;
import java.awt.Color;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Precipitation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Environment(EnvType.CLIENT)
@Mixin({Biome.class})
public class MixinBiome {
   @Inject(
      method = {"getFogColor"},
      at = {@At("HEAD")},
      cancellable = true
   )
   private void hookGetFogColor(CallbackInfoReturnable<Integer> cir) {
      if (Ambience.INSTANCE.isOn() && Ambience.INSTANCE.dimensionColor.booleanValue) {
         Color var2 = Ambience.INSTANCE.dimensionColor.getValue();
         cir.setReturnValue(var2.getRGB());
      }
   }

   @Inject(
      method = {"getPrecipitation"},
      at = {@At("HEAD")},
      cancellable = true
   )
   private void hookGetPrecipitation(BlockPos pos, CallbackInfoReturnable<Precipitation> cir) {
      if (Ambience.INSTANCE != null && Ambience.INSTANCE.shouldControlWeather()) {
         cir.setReturnValue(Ambience.INSTANCE.getPrecipitation());
      }
   }
}
