109 lines
4.0 KiB
Kotlin
109 lines
4.0 KiB
Kotlin
package dev.zxq5.items.template
|
|
|
|
import dev.zxq5.Fantasysmp
|
|
import dev.zxq5.util.resourceKey
|
|
import net.minecraft.core.Holder
|
|
import net.minecraft.resources.ResourceKey
|
|
import net.minecraft.sounds.SoundEvent
|
|
import net.minecraft.tags.TagKey
|
|
import net.minecraft.world.entity.EquipmentSlot
|
|
import net.minecraft.world.entity.player.Player
|
|
import net.minecraft.world.item.Item
|
|
import net.minecraft.world.item.ToolMaterial
|
|
import net.minecraft.world.item.equipment.ArmorMaterial
|
|
import net.minecraft.world.item.equipment.ArmorMaterials
|
|
import net.minecraft.world.item.equipment.ArmorType
|
|
import net.minecraft.world.item.equipment.EquipmentAsset
|
|
|
|
abstract class GenericGearSet: GenericItemSet() {
|
|
abstract val materialName: String
|
|
|
|
abstract val armorSet: ArmorSet
|
|
|
|
open val equipmentAssetSpec: EquipmentAssetSpec
|
|
get() = EquipmentAssetSpec(
|
|
layers = mapOf(
|
|
"humanoid" to listOf(EquipmentLayer("${Fantasysmp.MOD_ID}:$materialName")),
|
|
"humanoid_leggings" to listOf(EquipmentLayer("${Fantasysmp.MOD_ID}:$materialName")),
|
|
)
|
|
)
|
|
|
|
open val materialKey: ResourceKey<EquipmentAsset>
|
|
get() = materialName.resourceKey()
|
|
|
|
open val materialDefinition: GearMaterialDef
|
|
get() = GearMaterialDef.NETHERITE
|
|
|
|
val toolMaterial: ToolMaterial by lazy {
|
|
materialDefinition.toToolMaterial()
|
|
}
|
|
|
|
val armorMaterial: ArmorMaterial by lazy {
|
|
materialDefinition.toArmorMaterial()
|
|
}
|
|
|
|
open fun fullSetEquippedBy(p: Player) =
|
|
p.getItemBySlot(EquipmentSlot.HEAD).item == armorSet.helmet &&
|
|
p.getItemBySlot(EquipmentSlot.CHEST).item == armorSet.chestplate &&
|
|
p.getItemBySlot(EquipmentSlot.LEGS).item == armorSet.leggings &&
|
|
p.getItemBySlot(EquipmentSlot.FEET).item == armorSet.boots
|
|
}
|
|
|
|
data class ArmorSet(
|
|
val helmet: Item,
|
|
val chestplate: Item,
|
|
val leggings: Item,
|
|
val boots: Item,
|
|
)
|
|
|
|
data class GearMaterialDef(
|
|
val durability: Int = ArmorMaterials.NETHERITE.durability,
|
|
val defence: Map<ArmorType, Int> = ArmorMaterials.NETHERITE.defense,
|
|
val enchantability: Int = ArmorMaterials.NETHERITE.enchantmentValue,
|
|
val equipSound: Holder<SoundEvent> = ArmorMaterials.NETHERITE.equipSound,
|
|
val toughness: Float = ArmorMaterials.NETHERITE.toughness,
|
|
val knockbackResistance: Float = ArmorMaterials.NETHERITE.knockbackResistance,
|
|
val repairIngredient: TagKey<Item> = ArmorMaterials.NETHERITE.repairIngredient,
|
|
val assetId: ResourceKey<EquipmentAsset> = ArmorMaterials.NETHERITE.assetId,
|
|
) {
|
|
companion object {
|
|
val NETHERITE = GearMaterialDef(
|
|
durability = ArmorMaterials.NETHERITE.durability,
|
|
defence = ArmorMaterials.NETHERITE.defense,
|
|
enchantability = ArmorMaterials.NETHERITE.enchantmentValue,
|
|
equipSound = ArmorMaterials.NETHERITE.equipSound,
|
|
toughness = ArmorMaterials.NETHERITE.toughness,
|
|
knockbackResistance = ArmorMaterials.NETHERITE.knockbackResistance,
|
|
repairIngredient = ArmorMaterials.NETHERITE.repairIngredient,
|
|
assetId = ArmorMaterials.NETHERITE.assetId,
|
|
)
|
|
val DIAMOND = GearMaterialDef(
|
|
durability = ArmorMaterials.DIAMOND.durability,
|
|
defence = ArmorMaterials.DIAMOND.defense,
|
|
enchantability = ArmorMaterials.DIAMOND.enchantmentValue,
|
|
equipSound = ArmorMaterials.DIAMOND.equipSound,
|
|
toughness = ArmorMaterials.DIAMOND.toughness,
|
|
knockbackResistance = ArmorMaterials.DIAMOND.knockbackResistance,
|
|
repairIngredient = ArmorMaterials.DIAMOND.repairIngredient,
|
|
assetId = ArmorMaterials.DIAMOND.assetId,
|
|
)
|
|
}
|
|
}
|
|
|
|
fun GearMaterialDef.toArmorMaterial(): ArmorMaterial {
|
|
return ArmorMaterial(
|
|
durability,
|
|
defence,
|
|
enchantability,
|
|
equipSound,
|
|
toughness,
|
|
knockbackResistance,
|
|
repairIngredient,
|
|
assetId,
|
|
)
|
|
}
|
|
|
|
fun GearMaterialDef.toToolMaterial(): ToolMaterial {
|
|
TODO()
|
|
}
|