package ru.dbotthepony.mc.otm.mixin.compat.ad_astra;

import earth.terrarium.ad_astra.common.entity.system.EntityTemperatureSystem;
import earth.terrarium.ad_astra.common.util.ModUtils;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
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.CallbackInfo;
import ru.dbotthepony.mc.otm.config.ServerCompatConfig;

// STAHP!
@Mixin(EntityTemperatureSystem.class)
public class EntityTemperatureSystemMixin {
	@Inject(
		method = "temperatureTick(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/server/level/ServerLevel;)V",
		at = @At("HEAD"),
		cancellable = true,
		remap = false
	)
	private static void temperatureTick(LivingEntity entity, ServerLevel level, CallbackInfo hook) {
		if (ServerCompatConfig.AdAstra.INSTANCE.getWHATS_UP_WITH_TEMPERATURE() && !ModUtils.planetHasAtmosphere(level)) {
			hook.cancel();
		}
	}
}
