diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt index e7b893e..8b420c2 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt @@ -39,7 +39,7 @@ abstract class CustomItem(protected val plugin: CustomItemPlugin, private val it * @param item The existing item. The material of this item must match the material of the custom item. * @return The transformed `ItemStack`. */ - fun toItem(item: ItemStack): ItemStack { + open fun toItem(item: ItemStack): ItemStack { require(item.type == material) { "Cannot transform item of material " + item.type + " to item of material " + material.name + "." } item.editMeta { meta: ItemMeta -> diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/TexturedItem.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/TexturedItem.kt new file mode 100644 index 0000000..fad00f5 --- /dev/null +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/TexturedItem.kt @@ -0,0 +1,30 @@ +package foundation.esoteric.minecraft.plugins.library.item + +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import java.nio.file.Path + +class TexturedItem : CustomItem { + + companion object { + val startingModelData = 7919 + var texturedItems: Int = 0 + } + + constructor(plugin: CustomItemPlugin, itemId: String, material: Material, resourcePath: Path) : super(plugin, itemId, material) { + texturedItems++ + } + + constructor(plugin: CustomItemPlugin, itemId: String, material: Material, resourcePath: String) : this(plugin, itemId, material, Path.of(resourcePath)) + + override fun toItem(item: ItemStack): ItemStack { + super.toItem(item) + + item.editMeta { + meta -> + meta.setCustomModelData(startingModelData + texturedItems) + } + + return item + } +}