Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
DebitCardz committed Jan 1, 2024
2 parents a78dcb1 + e6adba8 commit 836c3e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@ dependencies {
<dependency>
<groupId>com.github.DebitCardz</groupId>
<artifactId>mc-chestui-plus</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>
</dependency>

```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
58 changes: 39 additions & 19 deletions src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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].
Expand All @@ -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
}

/**
Expand All @@ -81,7 +101,7 @@ open class GUIItem(
value
}

stack.editMeta {
itemStack.editMeta {
it.displayName(name)
}
}
Expand All @@ -98,7 +118,7 @@ open class GUIItem(
value
}

stack.editMeta {
itemStack.editMeta {
it.lore(sanitizeLore(lore))
}
}
Expand All @@ -107,17 +127,17 @@ open class GUIItem(
* Current [ItemStack] size.
*/
var amount: Int
get() = stack.amount
get() = itemStack.amount
set(value) {
stack.amount = value
itemStack.amount = value
}

/**
* Whether the [ItemStack] is glowing.
*/
var glowing: Boolean = false
set(value) {
stack.editMeta {
itemStack.editMeta {
if(value) {
it.addEnchant(Enchantment.ARROW_INFINITE, 0, true)
it.addItemFlags(ItemFlag.HIDE_ENCHANTS)
Expand All @@ -136,7 +156,7 @@ open class GUIItem(
var customModelData: Int
get() = itemMeta.customModelData
set(value) {
stack.editMeta {
itemStack.editMeta {
it.setCustomModelData(value)
}
}
Expand Down

0 comments on commit 836c3e4

Please sign in to comment.