Notes on new Tool system in 1.17.1+
Aug. 13th, 2021 07:03 pmGanked from changelog:
Build: 1.17.1-37.0.31 - Tue Aug 10 22:45:23 GMT 2021
gigaherz:
Redesign the tool system to rely on the new vanilla tags. (#7970)
Changed:
- ToolType is replaced with ToolAction, which can selectively represent which actions are supported by an item.
- Added a canPerformAction method to query ToolActions.
- Renamed canHarvestBlock to isCorrectToolForDrops to match vanilla.
- Added TierSortingRegistry, which can be used to add custom tiers and supports sorting between vanilla or with other mods.
How to use:
For the breaking system there's 2 methods:
- getDestroySpeed decides if an item *can* mine the block fast. Override if you have multiple tags or your item isn't a DiggerItem.
- isCorrectToolForDrops decides if an item will get drops. Returning false will also slow down mining, regardless of getDestroySpeed. Override if you have type-dependant tiers or your item isn't a DiggerItem.
For the tier system mods can just call `TierSortingRegistry.registerTier(tier, "name", List.of(lesser tiers), List.of(better tiers));` to register their tiers.
There's helper methods to query tiers such as TierSortingRegsitry.isCorrectTierForDrops.
The ToolActions solve 2 problems:
1. distinguishing which kind of digger an item can be
2. querying if the item can perform specific secondary actions.
Any item can override `canPerformAction` to customize which actions it performs.
Additional notes from Gigahertz on updating tools:
Remove the harvestTool and harvestLevel calls from the blocks
and instead, add the block to the relevant tags
ToolType.AXE -> minecraft:mineable/axe
ToolType.PICKAXE -> minecraft:mineable/pickaxe
ToolType.SHOVEL -> minecraft:mineable/shovel
and so on
if you define a custom tool type, define a custom tool type tag, can be optional if you don't have any default blocks
if you define a custom tier, register it into the TierSortingRegistry
if your tier is supposed to be equivalent to a vanilla tier, specify the tier you want to be equivalent to in the "after" list, the tier right after that in the "before" list, and have an empty optional tag in your tier.
you can use ForgeTier as a convenience
Build: 1.17.1-37.0.31 - Tue Aug 10 22:45:23 GMT 2021
gigaherz:
Redesign the tool system to rely on the new vanilla tags. (#7970)
Changed:
- ToolType is replaced with ToolAction, which can selectively represent which actions are supported by an item.
- Added a canPerformAction method to query ToolActions.
- Renamed canHarvestBlock to isCorrectToolForDrops to match vanilla.
- Added TierSortingRegistry, which can be used to add custom tiers and supports sorting between vanilla or with other mods.
How to use:
For the breaking system there's 2 methods:
- getDestroySpeed decides if an item *can* mine the block fast. Override if you have multiple tags or your item isn't a DiggerItem.
- isCorrectToolForDrops decides if an item will get drops. Returning false will also slow down mining, regardless of getDestroySpeed. Override if you have type-dependant tiers or your item isn't a DiggerItem.
For the tier system mods can just call `TierSortingRegistry.registerTier(tier, "name", List.of(lesser tiers), List.of(better tiers));` to register their tiers.
There's helper methods to query tiers such as TierSortingRegsitry.isCorrectTierForDrops.
The ToolActions solve 2 problems:
1. distinguishing which kind of digger an item can be
2. querying if the item can perform specific secondary actions.
Any item can override `canPerformAction` to customize which actions it performs.
Additional notes from Gigahertz on updating tools:
Remove the harvestTool and harvestLevel calls from the blocks
and instead, add the block to the relevant tags
ToolType.AXE -> minecraft:mineable/axe
ToolType.PICKAXE -> minecraft:mineable/pickaxe
ToolType.SHOVEL -> minecraft:mineable/shovel
and so on
- harvest level 0 -> forge:needs_wood_tool
- was harvest level 0 but you want only GOLD tools to mine, not wood -> forge:needs_gold_tool
- harvest level 1 -> minecraft:needs_stone_tool
- harvest level 2 -> minecraft:needs_iron_tool
- harvest level 3 -> minecraft:needs_diamond_tool
- harvest level 4 -> forge:needs_netherite_tool
if you define a custom tool type, define a custom tool type tag, can be optional if you don't have any default blocks
if you define a custom tier, register it into the TierSortingRegistry
if your tier is supposed to be equivalent to a vanilla tier, specify the tier you want to be equivalent to in the "after" list, the tier right after that in the "before" list, and have an empty optional tag in your tier.
you can use ForgeTier as a convenience