package ru.dbotthepony.mc.otm.item.armor

import net.minecraft.ChatFormatting
import net.minecraft.client.model.HumanoidModel
import net.minecraft.network.chat.Component
import net.minecraft.sounds.SoundEvent
import net.minecraft.sounds.SoundEvents
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.item.*
import net.minecraft.world.item.crafting.Ingredient
import net.minecraft.world.level.Level
import net.minecraftforge.client.extensions.common.IClientItemExtensions
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.model.GravitationStabilizerModel
import java.util.function.Consumer

private object GravitationStabilizerArmorMaterial : ArmorMaterial {
	override fun getDurabilityForType(p_40410_: ArmorItem.Type) = 0
	override fun getDefenseForType(p_40411_: ArmorItem.Type) = 3
	override fun getEnchantmentValue() = 0
	override fun getEquipSound(): SoundEvent = SoundEvents.ARMOR_EQUIP_GENERIC
	override fun getRepairIngredient(): Ingredient = Ingredient.EMPTY

	const val ID = "${OverdriveThatMatters.MOD_ID}:gravitation_stabilizer"

	override fun getName(): String = ID
	override fun getToughness() = 0f
	override fun getKnockbackResistance() = 0f
}

private object GravitationStabilizerArmorRenderProperties : IClientItemExtensions {
	override fun getHumanoidArmorModel(
		entityLiving: LivingEntity,
		itemStack: ItemStack,
		armorSlot: EquipmentSlot,
		_default: HumanoidModel<*>
	): HumanoidModel<*> {
		return GravitationStabilizerModel.getModel()
	}
}

class PortableGravitationStabilizerItem : ArmorItem(GravitationStabilizerArmorMaterial, Type.CHESTPLATE, Properties().stacksTo(1).rarity(Rarity.RARE)) {
	override fun initializeClient(consumer: Consumer<IClientItemExtensions>) {
		super.initializeClient(consumer)
		consumer.accept(GravitationStabilizerArmorRenderProperties)
	}

	override fun appendHoverText(
		p_41421_: ItemStack,
		p_41422_: Level?,
		p_41423_: MutableList<Component>,
		p_41424_: TooltipFlag
	) {
		super.appendHoverText(p_41421_, p_41422_, p_41423_, p_41424_)

		p_41423_.add(DESCRIPTION)
	}

	companion object {
		private val DESCRIPTION = TranslatableComponent("otm.item.blackhole_immunity").withStyle(ChatFormatting.DARK_GRAY)
	}
}
