Button element

Add a clickable button to the machine gui

The button gui element is used to add a clickable button to the machine gui.

All button elements have a unique string id (that you must specify in the elements properties), when the button is pressed a boolean flag will be written in the machine data. This data can be accessed using Crafttweaker or KubeJS Function requirement.

Simply using data.buttonID will give you a boolean that represent the current state of the button (true for pressed, false for released).

A Button requirement can also be used to make the recipe start only if the button is pressed.

Button elements are defined in json with : "type": "custommachinery:button".

Properties

The button gui element has 4 mandatory properties and 12 optional properties.

Mandatory properties

"type": "custommachinery:button" //Mandatory to define a button element.
X

Name : x

Description :

A positive integer value that define the x axis position of the element to be displayed on the Machine GUI.

Example :

The element will be rendered 100px to the right from the top-left corner of the gui.

"x": 100
Y

Name : y

Description :

A positive integer value that define the y axis position of the element to be displayed on the Machine GUI.

Example :

The element will be rendered 100px to the bottom from the top-left corner of the gui.

"y": 100
Id

Name : id

Description :

A string representing the id of the button, can be used in a Function requirement to check the state of the button, or in a Button requirement to make the recipe start only when the button is pressed.

Example :

The id of the button will be button1 :

"id": "button1"

Optional properties

Texture

Name : texture

Description :

The location of the texture that will be rendered into the GUI.

The location must be referenced by : namespace:path/file.png The texture loader will search for textures in the assets/namespace folder, the .png extension is required or the file will not be found.

The texture can be any size, if the texture size is different from the default size the width and height properties of the element will be automatically changed to fit the texture size if not provided.

If the width and/or height properties of the element are provided, the texture will be stretched to fit the dimensions of the element (it can render weirdly in that case).

Default :

"texture": "custommachinery:textures/gui/base_button.png"

Example :

The file assets/textures/my_texture.png will be used.

"texture": "namespace:textures/my_texture.png"
Texture toogle

Name : texture_toogle

Description :

The location of the texture that will be rendered into the GUI when the button is toogled and pressed.

The location must be referenced by : namespace:path/file.png The texture loader will search for textures in the assets/namespace folder, the .png extension is required or the file will not be found.

The texture can be any size, if the texture size is different from the default size the width and height properties of the element will be automatically changed to fit the texture size if not provided.

If the width and/or height properties of the element are provided, the texture will be stretched to fit the dimensions of the element (it can render weirdly in that case).

Default :

"texture": "custommachinery:textures/gui/base_button_toogle.png"

Example :

The file assets/textures/my_texture.png will be used.

"texture": "namespace:textures/my_texture.png"
Texture hovered

Name : texture_hovered

Description :

The location of the texture that will be rendered into the GUI when the players mouse cursor is hovering the element.

The location must be referenced by : namespace:path/file.png The texture loader will search for textures in the assets/namespace folder, the .png extension is required or the file will not be found.

The texture can be any size, if the texture size is different from the default size the width and height properties of the element will be automatically changed to fit the texture size if not provided.

If the width and/or height properties of the element are provided, the texture will be stretched to fit the dimensions of the element (it can render weirdly in that case).

Default :

"texture_hovered": "custommachinery:textures/gui/base_button_hovered.png"

Example :

The file assets/textures/my_texture.png will be used.

"texture_hovered": "namespace:textures/my_texture.png"
Texture toogle hovered

Name : texture_toogle_hovered

Description :

The location of the texture that will be rendered into the GUI when the button is toogled and the player mouse cursor is hovering it.

The location must be referenced by : namespace:path/file.png The texture loader will search for textures in the assets/namespace folder, the .png extension is required or the file will not be found.

The texture can be any size, if the texture size is different from the default size the width and height properties of the element will be automatically changed to fit the texture size if not provided.

If the width and/or height properties of the element are provided, the texture will be stretched to fit the dimensions of the element (it can render weirdly in that case).

Default :

"texture_toogle_hovered": "custommachinery:textures/gui/base_button_toogle_hovered.png"

Example :

The file assets/textures/my_texture.png will be used.

"texture_hovered": "namespace:textures/my_texture.png"
Width

Name : width

Description :

A positive integer value that define the width of the element on the Machine GUI.

Default :

The same width as the texture specified in the texture property.

Example :

The width of the element will be 100px.

"width": 100
Height

Name : height

Description :

A positive integer value that define the height of the element on the Machine GUI.

Default :

The same height as the texture specified in the texture property.

Example :

The height of the element will be 100px.

"height": 100
Priority

Name : priority

Description :

An integer property that define the priority of the Element to be rendered.

Elements with higher priority will be rendered first. If 2 elements are at the same position the first to be rendered will be under and the last will be above.

Default : 0

Example :

The element will be rendered under each element that have a priority lower than 1000.

"priority": 1000
Tooltips

Name : tooltips

Description :

A list of Text components that will be shown as tooltips when the player mouse cursor hover the element.

Each tooltips of the list will be a new line.

Example :

Replace the default tooltips with a single line that say "Click me !" :

"tooltips": "Click me !"
Toogle

Name : toogle

Description :

A boolean that define whether the button will act as a lever (stay pressed until clicked again).

Default : false

Example :

The button will stay pressed until clicked again :

"toogle": true
Text

Name : text

Description :

A text component that will be rendered on top of the button texture.

Note that by default the button texture is 20x20px square so a text too big will overflow from the button texture.

Default : empty

Example :

The following will add "Click Me !" text on the button :

"text": "Click Me !"

The same in red :

"text": {"text": "Click Me !", "color": "red"}
Item

Name : item

Description :

Add an item to be rendered on top of the button texture.

The item can be specified either with just its id : "minecraft:diamond" Or with a stack :

{"id": "minecraft:diamond", "Count": 4, "tag": "Some NBT"}

Default : empty

Example :

The rendered item will be a gold ingot :

"item": "minecraft:gold_ingot"
Hold time

Name : hold_time

Description :

A positive integer value that represent the time (in ticks) that the button will stay pressed when a player press it in the machine GUI.

Visually the button will not look pressed but internally the machine will keep it pressed until this hold time is expired.

This can be used when a machine need a button to be pressed to start a recipe, but since the machine check recipes only every 20 ticks the player would have to press the button exactly that tick or the recipe won't start.

Default : 1

The button only stay pressed for 1 tick.

Example :

The button will stay pressed for 20 ticks (1 second).

"hold_time": 20

Example

A basic button element using the base texture provided by Custom Machinery with a diamond :

{
    "type": "custommachinery:button",
    "x": 20,
    "y": 20,
    "id": "diamond",
    "item": "minecraft:diamond"
}

Last updated