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

import net.minecraft.sounds.SoundEvent
import net.minecraft.sounds.SoundEvents
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.item.ArmorItem
import net.minecraft.world.item.ArmorMaterial
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.crafting.Ingredient
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.registry.MItemTags

private object SimpleTritaniumArmorMaterial : ArmorMaterial {
	override fun getDurabilityForType(p_40410_: ArmorItem.Type): Int {
		return when (p_40410_) {
			ArmorItem.Type.HELMET -> 380
			ArmorItem.Type.CHESTPLATE -> 590
			ArmorItem.Type.LEGGINGS -> 500
			ArmorItem.Type.BOOTS -> 420
			else -> throw IllegalArgumentException("yo dude what the fuck $p_40410_")
		}
	}

	override fun getDefenseForType(p_40411_: ArmorItem.Type): Int {
		return when (p_40411_) {
			ArmorItem.Type.HELMET -> 2
			ArmorItem.Type.CHESTPLATE -> 6
			ArmorItem.Type.LEGGINGS -> 7
			ArmorItem.Type.BOOTS -> 2
			else -> throw IllegalArgumentException("yo dude what the fuck $p_40411_")
		}
	}

	override fun getEnchantmentValue() = 9
	override fun getEquipSound(): SoundEvent = SoundEvents.ARMOR_EQUIP_IRON
	override fun getRepairIngredient(): Ingredient = Ingredient.of(MItemTags.TRITANIUM_INGOTS)

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

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

class SimpleTritaniumArmorItem(slot: Type) : ArmorItem(SimpleTritaniumArmorMaterial, slot, Properties().stacksTo(1)) {
	override fun getArmorTexture(stack: ItemStack, entity: Entity?, slot: EquipmentSlot, type: String?): String? {
		if (type != "overlay" || slot == EquipmentSlot.FEET)
			return when (slot) {
				EquipmentSlot.LEGS -> "${OverdriveThatMatters.MOD_ID}:textures/models/armor/tritanium_simple_layer_2.png"
				EquipmentSlot.FEET, EquipmentSlot.CHEST, EquipmentSlot.HEAD -> "${OverdriveThatMatters.MOD_ID}:textures/models/armor/tritanium_simple_layer_1.png"
				else -> throw IllegalArgumentException("Invalid slot $slot")
			}

		return null
	}
}
