# Setup

Before we start,  you need to add a marker to your custom block spawn function if your custom block doesn't already use an Item display. It also needs a special tag in this guide, I will use "gui\_block" as the tag. If you have multiple GUI blocks, make sure to give them different tags.  This will be the anchor point for the commands for the barrel GUI. \
You also have to rename the placed barrel a bit.

### Load

The first thing we have to do now is, add some new scoreboards. We will use the [Template](/custom-barrel-gui-1.20.5+/misc-information/filling-the-gui-with-items.md) method to fill the GUIs, so we will also need to create the templates either in the load function or in an external function that we call in the load function. Because it's only one, I will do it in the load function.

{% code title="load.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
scoreboard objectives add temp dummy
scoreboard objectives add tempLinkId dummy

data merge storage <namespace>:guis {\
    GuideGuiBlock:[\
        {Slot:0b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:0b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:1b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:2b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:3b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:4b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'"What\'s your answer?"',"minecraft:custom_model_data":1000,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:5b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:6b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:7b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:8b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:9b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:10b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'"Yes"',"minecraft:custom_model_data":1001,"minecraft:custom_data":{GuiItem:1b,Button:"yes"}}},\
        {Slot:11b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:12b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:13b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'"Maybe"',"minecraft:custom_model_data":1002,"minecraft:custom_data":{GuiItem:1b,Button:"maybe"}}},\
        {Slot:14b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:15b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'"No"',"minecraft:custom_model_data":1003,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:16b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"no"}}},\
        {Slot:17b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:18b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:19b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:20b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:21b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:22b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:23b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:24b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:25b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":999,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}},\
        {Slot:26b,id:"minecraft:structure_void",Count:1b,components:{"minecraft:item_name":'""',"minecraft:custom_model_data":2000,"minecraft:custom_data":{GuiItem:1b,Button:"static"}}}\
    ]\
}
```

{% endcode %}

This gigantic block of text might look intimidating at first but if you understand, what it does, it isn't that bad. The whole chest gets filled with structure-void items that have the `GuiItem:1b` NBT tag. This tag shows that those are not "real items" but only for GUIs. Most of them also have the `static` Button NBT. This shows that they cannot be clicked and just refresh the GUI. The interesting ones are those that have different Button NBT and CustomModelData.

The different Button NBT is for determining which function to execute later.

### Resource Pack

You might wonder why in the previous step we made every item in the list a structure void, this is because it is not often used as an item for the player. That means it is safer to use and has a low risk of breaking your and other people's packs. One drawback though, is that you have to assign every texture/model of the items you want in the GUI to a structure void custom model data.

Those are the model files we will use in this guide:

{% code title="structure\_void.json" lineNumbers="true" fullWidth="true" %}

```json
{
  "parent": "minecraft:item/generated",
  "textures": {
    "layer0": "minecraft:item/structure_void"
  },
  "overrides": [
    {
      "predicate": {"custom_model_data": 999}, "model": "<namespace>/gui/empty_slot"
    },
    {
      "predicate": {"custom_model_data": 1000}, "model": "minecraft/item/oak_sign"
    },
    {
      "predicate": {"custom_model_data": 1001}, "model": "minecraft/item/green_concrete"
    },
    {
      "predicate": {"custom_model_data": 1002}, "model": "minecraft/item/yellow_concrete"
    },
    {
      "predicate": {"custom_model_data": 1003}, "model": "minecraft/item/red_concrete"
    }
  ]
}
```

{% endcode %}

{% code title="empty\_slot.json" lineNumbers="true" fullWidth="true" %}

```json
{}
```

{% endcode %}

The GUI background gets added differently. For that, we'll use custom fonts.\
\
First, put your GUI texture in folder called `custom_gui` and put that one either in  `minecraft/textures` or `<namespace>/textures`.

The Texture should have the same dimensions as the default vanilla texture: 256x256px.

<figure><img src="/files/DcurFYg6AovDaDfIpKk4" alt=""><figcaption><p>Custom Background Texture</p></figcaption></figure>

Add the font directory to your own namespace and create a new file called `gui.json`.\
This is how the file should look like:

{% code title="gui.json" lineNumbers="true" fullWidth="true" %}

```json
{
    "providers": [
        {
            "type": "space",
            "advances": {
                " ": 4,
                "\uFFF1": -8
            }
        },
        {
            "type": "space",
            "advances": {
                " ": 4,
                "\uFFF2": -169
            }
        },
        {
            "type": "bitmap",
            "file": "<namespace>:custom_gui/<gui texture name>.png",
            "ascent": 13,
            "height": 256,
            "chars": [
                "\u0001"
            ]
        }
    ]
}
```

{% endcode %}

&#x20;The GUI font adds 3 new characters. 2 negative spaces with different widths and 1 GUI texture character (you can add as many new GUI textures as you want). We need the 2 negative spaces for aligning the background and the barrel name. Almost no values need to be changed. The only things you should change are the `file` field, pointing to your texture and the `chars` field for additional background textures.\
\
To apply the background, you have to go a bit back and add one thing to the code that places the custom block. It has to replace the `CustomName` of the barrel. This is best done like this (assuming this command is executed by the "command anchor" that sits inside the block):

{% code fullWidth="true" %}

```haskell
data merge block ~ ~ ~ {CustomName:'[{"text":"\\uFFF1","font":"<namspace>:gui"},{"text":"\\uFFF2"},{"text":"\\u0001","color":"white"},{"text":"<custom block name>","font":"minecraft:default"}]'}
```

{% endcode %}

### Advancement

Next, create an advancement that triggers when we interact with the barrel. For this, we use the `item_used_on_block` trigger and a function call as a reward. We'll also add a location `check_condition` to see if we interacted with a barrel or something else, to reduce the times this advancement is called unnecessary.

{% code title="open\_gui.json" lineNumbers="true" fullWidth="true" %}

```json
{
    "criteria": {
        "requirement": {
            "trigger": "minecraft:item_used_on_block",
            "conditions": {
                "location": [
                    {
                        "condition": "minecraft:location_check",
                        "predicate": {
                            "block": {
                                "blocks": [
                                    "minecraft:barrel"
                                ]
                            }
                        }
                    }
                ]
            }
        }
    },
    "rewards": {
        "function": "<namespace>:<block name>/gui/revoke"
    }
}
```

{% endcode %}

### Revoke

Now, let's make the revoke function. To better organize the files we create the directories shown in the advancement.

Because an advancement only works once and then gets disabled, you have to enable it again. In the same function, we add 1 to the Servers tempLinkId score and assign that score to the player. This ensures, that the player gets a new unique ID. This will be used later. We also move the context of the command over to the barrels command anchor.

{% code title="revoke.mcfunction" lineNumbers="true" fullWidth="true" %}

```haskell
scoreboard players add Server tempLinkId 1
scoreboard players operation @s tempLinkId = Server tempLinkId

execute as @e[type=item_display,tag=gui_block,tag=!already_open] at @s if block ~ ~ ~ barrel[open=true] run function <namespace>:<block name>/gui/init

advancement revoke @s only <namespace>:open_gui
```

{% endcode %}

This is the basic setup of the GUI, the next step is to make it react when we open the barrel.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://datapackhub.gitbook.io/custom-barrel-gui-1.20.5+/advanced-gui-with-font-bg/setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
