diff --git a/README.md b/README.md index a7577eb..92c0661 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation("com.github.DebitCardz:mc-chestui-plus:1.4.4") + implementation("com.github.DebitCardz:mc-chestui-plus:1.4.5") } ``` ### Maven @@ -34,7 +34,7 @@ dependencies { com.github.DebitCardz mc-chestui-plus - 1.4.4 + 1.4.5 ``` diff --git a/build.gradle.kts b/build.gradle.kts index d71d797..70eb7e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv(" val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") group = "me.tech" -version = "1.4.4" +version = "1.4.5" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt b/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt index bd6511c..534b0ab 100644 --- a/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt +++ b/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt @@ -21,6 +21,18 @@ fun GUI.Slot.item( return guiItem(type, builder) } +/** + * Construct a [ItemStack] to be placed in a [GUI.Slot]. + * @param stack item stack. + * @param builder [GUIItem] builder. + */ +fun GUI.Slot.item( + stack: ItemStack, + builder: GUIItem.() -> Unit = {} +): GUIItem { + return guiItem(stack, builder) +} + /** * Construct a [ItemStack] to be placed in a [GUI.Slot]. * @param type material type. @@ -33,14 +45,30 @@ fun guiItem( return GUIItem(type).apply(builder) } -open class GUIItem( - type: Material +/** + * Construct a [ItemStack] to be placed in a [GUI.Slot]. + * @param stack item stack. + * @param builder [GUIItem] builder. + */ +fun guiItem( + stack: ItemStack, + builder: GUIItem.() -> Unit = {} +): GUIItem { + return GUIItem(stack).apply(builder) +} + + +open class GUIItem constructor( + private val itemStack: ItemStack ) { + constructor(type: Material) + : this(ItemStack(type, 1)) + /** * [ItemStack] of the [GUIItem]. */ - var stack = ItemStack(type, 1) - private set + val stack: ItemStack + get() = itemStack.clone() /** * [ItemMeta] of the [GUIItem]. @@ -53,20 +81,12 @@ open class GUIItem( */ var removeParentItalics = true - /** - * Modify the [ItemStack] of the [GUIItem]. - * @param builder [ItemStack] builder. - */ - fun stack(builder: ItemStack.() -> Unit) { - stack.apply(builder) - } - /** * Modify the [Material] of the [GUIItem]. * @param material [Material] to set to. */ fun material(material: Material) { - stack.type = material + itemStack.type = material } /** @@ -81,7 +101,7 @@ open class GUIItem( value } - stack.editMeta { + itemStack.editMeta { it.displayName(name) } } @@ -98,7 +118,7 @@ open class GUIItem( value } - stack.editMeta { + itemStack.editMeta { it.lore(sanitizeLore(lore)) } } @@ -107,9 +127,9 @@ open class GUIItem( * Current [ItemStack] size. */ var amount: Int - get() = stack.amount + get() = itemStack.amount set(value) { - stack.amount = value + itemStack.amount = value } /** @@ -117,7 +137,7 @@ open class GUIItem( */ var glowing: Boolean = false set(value) { - stack.editMeta { + itemStack.editMeta { if(value) { it.addEnchant(Enchantment.ARROW_INFINITE, 0, true) it.addItemFlags(ItemFlag.HIDE_ENCHANTS) @@ -136,7 +156,7 @@ open class GUIItem( var customModelData: Int get() = itemMeta.customModelData set(value) { - stack.editMeta { + itemStack.editMeta { it.setCustomModelData(value) } }