tutorial:stats
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorial:stats [2024/11/18 16:45] – identifier constructor is private, Registries class bemoty | 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 = Identifier.of("modid", " | + | 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(Registries.CUSTOM_STAT, | + | Registry.register(BuiltInRegistries.CUSTOM_STAT, |
| </ | </ | ||
| Line 17: | Line 17: | ||
| <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.txt · Last modified: 2026/01/08 21:31 by cassiancc