Stat bars

Banner showing a set of stat bars

Stat bars are used to display different stats on an item, like effects, attributes or durability. They can either be registered programmatically during initialization of an addon mod, or defined in a resourcepack.

Programmatically defined stat bars can be registered during the FMLClientSetupEvent event by calling WorkbenchStatsGui.addBar(statBar) to make the stat bar show up in the workbench, and HoloStatsGui.addBar(statBar) to make it show up in the holosphere.

Short example:

static final ItemEffect ignitingEffect = ItemEffect.get("igniting");
/* ... */
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void clientSetup(FMLClientSetupEvent event) {
    var statGetter = new StatGetterEffectLevel(ignitingEffect, 1);
    GuiStatBar statBar = new GuiStatBar(0, 0, StatsHelper.barLength,
        "tetra.stats.igniting", 0, 10, false, false, false,
        statGetter, LabelGetterBasic.integerLabel,
        new TooltipGetterInteger("tetra.stats.igniting.tooltip", statGetter)
    );

    WorkbenchStatsGui.addBar(statBar);
    HoloStatsGui.addBar(statBar);
}

Remember to register the event handler!

Data driven stat bars

Stat bars can be defined in JSON files within resources/tetra/stat_bars/ in a resourcepack (not a datapack!).

Stat Bar

Defines how a statbar displays, including labels, formatting, tooltip and possibly bar indicators.

Format:
typeoptionalstring

There's only one type registered in vanilla tetra, but this can be set if some other mod has registered other statbar types.

keyResource location

The localization key for the stat bar, the localized value will be displayed next to the numerical label above the stat bar. Probably something along the lines of 'mymod.stats.attack_damage'.

statStat getter

The stat to display in the stat bar, this value backs how the bar is displayed and the label.

minnumber

The minimum value for the stat bar, sets the lower bound for the actual bar.

maxnumber

The maximum value for the stat bar, sets the upper bound for the actual bar.

labelLabel Getter

Defines how the actual value of the stat is displayed above the bar.

tooltipTooltip getter

Defines the tooltip for the stat bar, this is displayed when hovering over the stat bar.

indicatorsoptional
array[
Resource location
]

An array of resource locations referencing directories (relative stat_indicators/) of indicators which should be displayed for this stat bar.

contexts
array[
string
Example values:
tetra:workbench
tetra:holosphere
]

Defines which UIs to show this stat bar in.

generateSorteroptionalboolean

If set to true, registers a stat sorter with the same label, stat and format as this stat bar.

Example:
{
  "type": "tetra:default",
  "key": "tetra.stats.attack_damage",
  "contexts": [
    "tetra:workbench"
  ],
  "min": 0,
  "max": 40,
  "stat": {
    "type": "tetra:sum",
    "stats": [
      {
        "type": "tetra:attribute",
        "attribute": "generic.attack_damage"
      },
      {
        "type": "tetra:sum",
        "stats": [
          {
            "type": "tetra:multiply",
            "stats": [
              {
                "type": "tetra:enchantment",
                "enchantment": "minecraft:sharpness"
              }
            ],
            "factor": 0.5
          }
        ],
        "offset": 0.5
      }
    ]
  },
  "label": {
    "type": "tetra:basic",
    "format": "double_decimal",
    "diff_format": "double_decimal"
  },
  "tooltip": {
    "type": "tetra:default",
    "key": "tetra.stats.attack_damage.tooltip",
    "stats": [
      {
        "type": "tetra:sum",
        "stats": [
          {
            "type": "tetra:attribute",
            "attribute": "generic.attack_damage"
          },
          {
            "type": "tetra:sum",
            "stats": [
              {
                "type": "tetra:multiply",
                "stats": [
                  {
                    "type": "tetra:enchantment",
                    "enchantment": "minecraft:sharpness"
                  }
                ],
                "factor": 0.5
              }
            ],
            "offset": 0.5
          }
        ],
        "attribute": "generic.attack_damage"
      }
    ],
    "formatters": [
      {
        "type": "tetra:basic",
        "format": "double_decimal"
      }
    ]
  },
  "indicators": [
    "tetra:attack_damage/shared",
    "tetra:attack_damage/normalized"
  ]
}