-
Notifications
You must be signed in to change notification settings - Fork 0
Creating Your First Slate
Slate is designed to be super simple.
val slate = slate()
slate.open(player)
This is all you need to create a slate! Admittedly, it won't be too interesting:
You'll notice that your slate is completely blank so far, including any text. Fix this by adding a title!
We will convert the slate()
initialiser into a block function, and set the title from there.
val slate = slate {
title = Text.literal("Hello, world!")
}
And now your slate has a title!
What is a custom screen without some items? We call each slot a "tile", all of which lie on a "tile grid". The tile grid can be accessed like such:
slate {
tiles {
//
}
}
Let's add a tile on the 5th column of the 3rd row of the slate:
slate {
tiles {
this[4, 2] = tile(Items.STONE) // (x, y) coordinates are indexes
}
}
Tip
You can also access tiles on the grid by index, set hotbar slots, or clear the tile grid entirely, to name a few examples. See the TileGrid
javadoc for everything that is available to you.
You can now see your stone item appearing on the slate!
You will notice that upon hovering your new tile, it has no tooltip at all. This is because we need to define one. Tooltips are one of many properties we can set on a tile.
Here's a tile called "Click Me!" which sends the player a message when it is clicked.
tile(Items.STONE) {
tooltip("Click Me!")
onGenericClick { slate, tile, context ->
val player = context.player
player.sendMessage(Text.literal("Oh, you clicked me!"))
}
}
You've made your first slate! I hope that was as simple as it comes. With only 12 lines of code, you can define a custom screen with a tile and a title.
Here's the full code we created:
val slate = slate {
title = Text.literal("Hello, world!")
tiles {
this[4, 2] = tile(Items.STONE) {
tooltip("Click Me!")
onGenericClick { slate, tile, context ->
val player = context.player
player.sendMessage(Text.literal("Oh, you clicked me!"))
}
}
}
}
slate.open(player)
Tip
Tiles and titles are both updated dynamically for clients. This means you can modify those values and changes will be reflected for players without any extra method calls.