Bar element

Add a bar that fills depending on a number value stored in the machine.

The bar gui element can be used to display a number in the form of a fillable bar (the default texture is the same one as the energy gui element).

The number value must be stored in the machine data, which is accessible only by using Crafttweaker or KubeJS scripts.

Example: setting a number in the data from a script

.requireFunctionEachTicks(ctx => {
    //Set the variable named "amount" to 10
    //"amount" can be replaced by anything else,
    //as long as it match the ID specified in the bar gui element properties.
    ctx.machine.data.amount = 10;
    
    return ctx.success()
})

Bar elements are defined in json with : "type": "custommachinery:bar".

Properties

The bar gui element has 4 mandatory properties and 10 optional properties.

Mandatory properties

"type": "custommachinery:bar" //Mandatory to define a bar 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 that define the name of the number variable in the machine data that should be used for filling the bar.

If the machine data doesn't contain any number value with this id the number shown by the bar will always be 0.

The number variable must be at the higher level of the machine data :

// This is OK
machine.data.amount = 10

// This won't work
machine.data.something.amount = 10

Example :

The bar gui element will show the number variable named "amount" from the machine data :

"id": "amount"

Optional properties

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
Empty texture

Name : texture_empty

Description :

Point to a texture to use as the empty element texture. The texture must be loaded in-game with a resource pack or a loader mod.

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_empty": "custommachinery:textures/gui/base_energy_storage_empty"

Example :

"texture_empty": "namespace:textures/energy_element_texture_empty.png"

The element will search for a texture located in assets/namespace/textures/energy_element_texture_empty.png

The .png extension is mandatory.

Filled texture

Name : texture_filled

Description :

Point to a texture to use as the filled element texture. The texture must be loaded in-game with a resource pack or a loader mod.

The filled texture will be rendered on top on the empty texture, how much the filled texture overlap the empty texture is relative to the amount of energy inside the energy component.

Default :

"texture_filled": "custommachinery:textures/gui/base_energy_storage_filled"

Example :

"texture_filled": "namespace:textures/energy_element_texture_filled.png"

The element will search for a texture located in assets/namespace/textures/energy_element_texture_filled.png

The .png extension is mandatory.

Highlight

Name : highlight

Description :

A boolean property, if true the element will highlight (become slightly brighter) when the player mouse hover it. If false the element will not highlight on mouse hover.

Default : true

Example :

The element will not highlight on mouse hover :

"highlight": false
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 !"
Min

Name : min

Description :

An integer value that define the minimal amount needed for the bar to start filling.

Default : 0

Example :

The bar will start filling if the displayed number is higher than 100.

"min": 100
Max

Name : max

Description :

An integer value that define the maximal amount displayed by the bar. (From this amount the bar will show full.

Default : 1000

Example :

The bar will be full if the displayed number is equals or higher than 100.

"max": 100
Orientation

Name : orientation

Description :

The direction the bar will be filled to.

Valid values are : top, right, bottom and left.

Default : top

Example :

The bar will fill towards the right for the machine gui.

"orientation": "right"

Example

A bar with default texture, which show a number stored in the machine data with id "amount", which is between 0 and 10000 :

{
    "type": "custommachinery:bar",
    "x": 20,
    "y": 20,
    "id": "amount",
    "max": 10000
}