Skip to content

Gui Modifiers

MehVahdJukaar edited this page Sep 25, 2024 · 46 revisions

Gui Modifiers (Slotify)

Gui Modifiers allow you to tweak many aspects of a GUI.

These include:

  • Moving slots
  • Adding images
  • Changing slots highlight color
  • Move some specific GUI elements

Modifiers were a feature from 'Slotify'. It has since been merged into Polytone, you can also refer to its' old wiki page here.

Getting started

You can start by adding a simple .json files in your resource pack in the path assets/[any namespace]/polytone/gui_modifiers/[modifier name].json

You can name them whatever you want but you'll need to create ONE PER GUI you want to target.

Here is an example of a simple gui modifier. Following will be a more in depth explanation

{  
  "target_type": "menu_id",  
  "target": "generic_9x3",  
  "slot_modifiers": [  
    {  
      "slots": "27->62",  
      "x_offset": 0,  
      "y_offset": 7  
    }  
  ],  
  "sprites": [  
    {  
      "x": -8,  
      "y": -8,  
      "z": -500,  
      "width": 16,  
      "height": 16,  
      "texture": "minecraft:icon/accessibility"
    }  
  ]  
}

This is a simple gui modifier for the normal chest. It places a 16x16 sprite of the minecraft accessibility icon texture in the middle of the screen, as well as offsetting the entire player inventory by 7 pixels to the bottom.

JSON Structure

Each modifier can contain these fields:

Field Function
target_type GUI targeting strategy
target Information on GUI to target
slot_modifiers Slot modification logic
widget_modifiers Button modification logic
special_offsets Some special offset parameters for some specific GUI
title_x_offset Screen title x offset
title_y_offset Screen title y offset
label_x_offset Screen label x offset
label_y_offset Screen label y offset
title_color Title color
label_color Label color
sprites Extra images to render on the Screen
texts Extra text strings to render

Target Type

The target_type is used to determine which GUI to target.

When it comes to GUI, game uses two types of concepts:

  • Screens: represent what a player actually sees.
  • Menu: a server side abstraction that handles Slots and communicates them to its own Screen.

Different targeting strategies are thus requires as not all Screens have a Menu and only Menu have a unique Registry ID associated with them. Both of them can have unique classes.

Here is what each of the target types are:

target_type value Required target Content Can modify slots?
menu_class Obfuscated full class path of target Menu class yes
menu_id Registry name of the Menu you are targeting yes
screen_title Sceen title's translation key no
screen_class Obfuscated full class path of target Screen class no

Note that all the _class types can also work with non obfuscated / non fully qualified class paths in some circumstances.

Below is an example for each:

The target field defines which GUI is being targeted, when menu_class is the target type, you will need the obfuscated class path like shown below.

    "target_type": "menu_class",  
    "target": "net.minecraft.class_1723"

If the target_type is set to menu_id, you will need to use one of the predefined GUI names as the target, the full list can be found further down.

    "target_type": "menu_id",  
    "target": "generic_9x6"

When using "screen_title" as your "target_type" you can either use translation strings or the screen name shown ingame as the "target".

    "target_type": "screen_title",  
    "target": "container.enderchest"

The target_type screen_class refers to specific screen classes and needs the screen class name as the target.

    "target_type": "screen_class",  
    "target": "net.minecraft.client.gui.screen.inventory.SignEditScreen"

Do note that screen_title takes priority when layered with menu_id

Slot Modifiers

Slot modifiers can be used to tweak the position of the specified GUI's slots on screen.

Note the square brackets denote a list meaning you can define multiple modifiers in the same slots_modifier field.

Here is a list of all the parameters and their use

Parameter Content
slots Slots (ids) to target
x_offset Screen X pixel offset
y_offset Screen Y pixel offset
color Slot Highlight primary color
color2 Slot Highlight secondary color

Each slot has a unique number assigned to it, for figuring out which slot has which number, you can use this website.

They can be defined either as an integer,

    "slot_modifiers": [  
      {  
        "slots": 0,  
        "x_offset": -20,  
        "y_offset": 22  
      }
    ]

as an array of integers

      "slot_modifiers": [  
        {  
          "slots": [1,2,3,4],  
          "x_offset": 27,  
           "y_offset": -11  
        }
      ]

or as a string formatted as "[from slot]->[to slot]".

    "slot_modifiers": [  
        {
          "slots": "5->8",  
          "x_offset": 36,  
          "y_offset": -1,  
          "color": "#696969",  
          "color2": "#tf67hj"  
        }
      ]

The specified slots' locations on the screen can be modified using x_offset and y_offset with an integer representing the offset in screen pixels.

Their hover color can be changed using color, color2 and the #hexcode as a string. This is also needed if your modified slots are outside of the normal GUI boundary and sit on other sprites.

The special_offsets currently only includes player (the survival inventory player model), which can be modified in the same way as slots (excluding color).

    "special_offsets": {  
      "player": {  
        "x_offset": 35,  
        "y_offset": 0  
       }  
    }

Sprites

Sprites are useful for appending further textures in inventories, they use "x", "y" and "z" to determine the position on screen.

    "sprites": [  
      {  
        "x": -102,  
        "y": -95,  
        "z": -200,  
        "width": 204,  
        "height": 190,  
         "texture": "minecraft:icon/accessibility" 
      }  
    ]

z determines the layer on which the texture is placed, ranging from -200 to 200. use -200 if items should appear on top of the custom sprite.
width and height determine the size of your sprite, it is recommended to use the actual size of your texture to get accurate pixel sizes.

The texture path is the same as in vanilla, pointing to a .png in your assets/textures/gui/sprites folder. NOTE: It MUST be in that folder or one of its subfolder.

Widget Modifiers

Widget modifiers let you customize buttons such as the 'sign' button in the book and quill screen, they are split into target parameters and modifiers, the former being used to find the button that you want to modify and the latter to modify the button.

These are used to target the buttons upper left corner, the coordinates are measured in pixels, originating from the center of the screen.

    "widget_modifiers": [  
      {
        "target_x": 2,  
        "target_y": 2,  
        "target_message": "done",  
        "target_width": 4,  
        "target_class_name": "Button",   
      }  
    ]

target_message is used to select the specific Button with this label.
target_width is used to specify the size of the targeted button.
target_class_name specifies the targeted button via class names.

x_offset and y_offset are used to offset the targeted button like slots.
width_increment modifies the width of the targeted button.

    [  
      {  
        "x_offset": 5,  
        "y_offset": 4  
        "width_increment": 4
      }   
    ]

Text Strings

Very similar to sprites. They have the following fields:

  • text: a Component of text. AS such can contain stuff as styles, bold, and formatting
  • x, y, z: position on screen
  • centered: if it shoul be rendered centered on the gievn coords
  • color: text color

Title Offset

title_x_offset and title_y_offset move the title text of the GUI/screen.

      "title_x_offset": -14,  
      "title_y_offset": 20  

Label Offset

label_x_offset and label_y_offset move the label text of the GUI/screen.

      "label_x_offset": -14,  
      "label_y_offset": 20  

Vanilla Menu Registry ID target list

  • generic_9x1
  • generic_9x2
  • generic_9x3
  • generic_9x4
  • generic_9x5
  • generic_9x6
  • generic_3x3
  • anvil
  • beacon
  • blast_furnace
  • brewing_stand
  • crafting
  • enchantment
  • furnace
  • grindstone
  • hopper
  • lectern
  • loom
  • merchant
  • shulker_box
  • smithing
  • smoker
  • cartography_table
  • stonecutter

Cheatsheet

A list of the most commonly used GUI targets.

GUI Name Target Type Target
Survival Inventory menu_class net.minecraft.class_1723 or InventoryMenu (newer versions)
Creative Inventory menu_class net.minecraft.class_481 or ItemPickerMenu (newer versions)
Chest menu_id generic_9x3
Double Chest menu_id generic_9x6
Horse Menu menu_class net.minecraft.class_1724 or HorseInventoryMenu
Ender Chest (uses slot modifiers from generic_9x3) screen_title container.enderchest

Tip: some screens use as title the name of the entity. You can use that as a target to have stuf like per entity aware screen textures

Also for some class targets you might need to use their obfuscaed fully qualified name. Get it here

https://linkie.shedaniel.dev/mappings?namespace=mojang_srg&version=1.19.2&search=HorseInventoryMenu&allowClasses=false&allowFields=false&translateMode=none