-
Notifications
You must be signed in to change notification settings - Fork 6
2. GUIItem
Tech edited this page Aug 26, 2023
·
1 revision
A GUIItem refers to the actual ItemStack displayed in a GUIComponent.
We use the assigned item helper function in order to initialize a new GUIItem, the GUIItem can take many different properties to modify the way it is rendered in the UI.
A GUIItem can modify the following properties:
- name (Component)
- lore (List<Component>)
- amount (Int)
- skullOwner (OfflinePlayer)
- playerProfile (PlayerProfile)
- glowing (Boolean)
- customModelData (Int)
- removeParentItalics (Boolean)
The removeParentItalics property is one added because Minecraft by default automatically italicizes ItemStack lore, to remove this the parent italics by Minecraft are removed, if you want to revert this functionality simply assign removeParentItalics to false.
fun render(): GUI {
return gui(
plugin = instance,
title = Component.text("Rendered UI"),
type = GUIType.Chest(rows = 3)
) {
slot(1, 1) {
item = item(Material.CAKE) {
name = Component.text("Rendered Cake!")
}
}
}
}The item helper function takes a Material as a parameter for what type of item should be rendered.
fun render(): GUI {
return gui(
plugin = instance,
title = Component.text("Rendered UI"),
type = GUIType.Chest(rows = 3)
) {
slot(1, 1) {
item = item(Material.CAKE) {
name = Component.text("Rendered Cake!")
lore = listOf(
Component.text("Line 1"),
Component.empty(),
Component.text("Next Line!")
)
}
}
}
}fun render(): GUI {
return gui(
plugin = instance,
title = Component.text("Rendered UI"),
type = GUIType.Chest(rows = 3)
) {
slot(1, 1) {
item = item(Material.CAKE) {
name = Component.text("Rendered Cake!")
glowing = true
}
}
}
}We can also make the GUIItem conditionally glow if we instead pass a Boolean to the glowing property.