tutorial:stats
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:stats [2021/02/08 18:51] – increment stats on both server and client jummit | tutorial:stats [2026/01/08 21:31] (current) – Mojang mappings and fixes for incorrect identifier cassiancc | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| To add a custom statistic, create an identifier which will be used to register and increase the stat: | To add a custom statistic, create an identifier which will be used to register and increase the stat: | ||
| <code java> | <code java> | ||
| - | public static final Identifier INTERACT_WITH_COOL_BLOCK = new Identifier(" | + | public static final Identifier INTERACT_WITH_COOL_BLOCK = Identifier.fromNamespaceAndPath("example-mod", " |
| </ | </ | ||
| Line 11: | Line 11: | ||
| Then register the stat using the identifier: | Then register the stat using the identifier: | ||
| <code java> | <code java> | ||
| - | Registry.register(Registry.CUSTOM_STAT, | + | Registry.register(BuiltInRegistries.CUSTOM_STAT, |
| </ | </ | ||
| - | Then specify the stat formatter. It determines how the number is shown in the Statistics screen. You can use DEFAULT, DIVIDE_BY_TEN, | + | Then add the stat to the statistic screen, where you can also specify the stat formatter. It determines how the number is shown in the stat list. You can use DEFAULT, DIVIDE_BY_TEN, |
| <code java> | <code java> | ||
| - | Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_COOL_BLOCK, | + | Stats.CUSTOM.get(INTERACT_WITH_COOL_BLOCK, |
| </ | </ | ||
| ===== Using The Statistic ===== | ===== Using The Statistic ===== | ||
| - | To increment the statistic, for example when a player interacts with a block, you can use '' | + | To increment the statistic, for example when a player interacts with a block, you can use '' |
| <code java> | <code java> | ||
| @Override | @Override | ||
| - | public ActionResult onUse(BlockState state, | + | public ActionResult onUse(BlockState state, |
| - | player.incrementStat(ModClass.INTERACT_WITH_COOL_BLOCK); | + | player.awardStat(ModClass.INTERACT_WITH_COOL_BLOCK); |
| - | return | + | return |
| } | } | ||
| </ | </ | ||
| - | You can also use '' | + | You can also use '' |
| ===== Translation ===== | ===== Translation ===== | ||
| - | To translate the name, add an entry for '' | + | To translate the name, add an entry for '' |
| <code json> | <code json> | ||
| { | { | ||
| - | "stat.modid.interact_with_cool_block": | + | "stat.example-mod.interact_with_cool_block": |
| } | } | ||
| </ | </ | ||
tutorial/stats.1612810277.txt.gz · Last modified: 2021/02/08 18:51 by jummit