NextDevv's Docs Help

Alignment

source

enum class Alignment { TOP_LEFT, TOP_CENTER, TOP_RIGHT, CENTER_LEFT, CENTER, CENTER_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT; companion object { fun getIndex(alignment: Alignment, rows: Int): Int { when(alignment) { TOP_LEFT -> return 0 TOP_CENTER -> return 4 TOP_RIGHT -> return 8 CENTER_LEFT -> { val size = rows * 9 val centerIndex = (size / 2) - 5 return centerIndex - 4 } CENTER -> { val size = rows * 9 return (size / 2) - 5 } CENTER_RIGHT -> { val size = rows * 9 val centerIndex = (size / 2) - 5 return centerIndex + 4 } BOTTOM_LEFT -> { val size = rows * 9 return size - 9 } BOTTOM_CENTER -> { val size = rows * 9 return (size - 9) + 4 } BOTTOM_RIGHT -> { val size = rows * 9 return (size - 9) + 8 } } } } }

Description & Properties

The Alignment enum class is used to define the alignment of GUI elements within a GUI. It provides a set of predefined alignment options that can be used to position elements such as buttons, text, and images within a GUI layout. The enum class has the following properties and methods:

  • TOP_LEFT: Aligns elements to the top left corner of the GUI.

  • TOP_CENTER: Aligns elements to the top center of the GUI.

  • TOP_RIGHT: Aligns elements to the top right corner of the GUI.

  • CENTER_LEFT: Aligns elements to the center left of the GUI.

  • CENTER: Aligns elements to the center of the GUI.

  • CENTER_RIGHT: Aligns elements to the center right of the GUI.

  • BOTTOM_LEFT: Aligns elements to the bottom left corner of the GUI.

  • BOTTOM_CENTER: Aligns elements to the bottom center of the GUI.

  • BOTTOM_RIGHT: Aligns elements to the bottom right corner of the GUI.

  • getIndex(alignment: Alignment, rows: Int): A static method that calculates the index of the slot corresponding to the specified alignment and number of rows in the GUI.

The getIndex method takes an Alignment value and the number of rows in the GUI as input and returns the index of the slot that represents the specified alignment within the GUI layout.

Example

You can use the Alignment enum class to position elements within a GUI by calculating the slot index based on the desired alignment. The getIndex method provides a convenient way to determine the slot index for a specific alignment and number of rows in the GUI.

Here is an example of how to use the Alignment enum class in Kotlin:

val alignment = Alignment.TOP_CENTER val rows = 6 val slotIndex = Alignment.getIndex(alignment, rows)

or

val inv = kGui.builder(PLAYER) .setTitle("My GUI") .setRows(6) .setBorder(border) .addItem(itemStack, Alignment.CENTER) .build()

In this example, we create an Alignment enum value representing the top center alignment and specify the number of rows in the GUI. We then use the getIndex method to calculate the slot index corresponding to the specified alignment within the GUI layout. This slot index can be used to position elements such as buttons or items within the GUI at the desired alignment.

By leveraging the Alignment enum class and its getIndex method, you can easily align elements within your GUI layouts and create visually appealing and organized interfaces for players to interact with in Minecraft.

Summary

The Alignment enum class provides a flexible way to define and calculate the alignment of elements within a GUI layout. By using the predefined alignment options and the getIndex method, you can position elements accurately within the GUI based on the desired alignment and number of rows. This allows you to create visually appealing and user-friendly GUIs that enhance the player experience in your Minecraft plugin or mod.

Last modified: 03 July 2024