User Tools

Site Tools


tutorial:mining_levels

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:mining_levels [2020/05/13 14:50] – parse it better shedanieltutorial:mining_levels [2022/09/29 05:07] (current) solidblock
Line 2: Line 2:
  
 ==== Introduction ==== ==== Introduction ====
-Vanilla has a terrible system for mining levels, values are hardcoded and there isn't support for mining levels except for pickaxes. +The way mining levels and preferred tools are assigned has changed significantly in 1.17. Making your tools and blocks interact properly now requires adding them to specific tags.
-==== Setting Mining Level of a Block ====+
  
-To start, use the ''breakByTool'' method in ''FabricBlockSettings'' to set the block mining levels, it requires an item tag, which is provided by fabric in ''FabricToolTags'': +==== Setting the preferred tool for your block ====
-<code java> +
-settings.breakByTool(FabricToolTags.PICKAXES, 2) +
-</code>+
  
-Here'the list of mining levels+To define what tool is used to harvest your block, you need to add the block'identifier to a tag inside of ''tags/blocks/mineable'' that corresponds to your tool ("''pickaxe.json''","''axe.json''", etc.)
-<code> +<code JavaScript /src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json
-0 -> Wooden / Golden Pickaxe +{ 
-1 -> Stone Pickaxe +  "replace": false, 
-2 -> Iron Pickaxe +  "values": [ 
-3 -> Diamond Pickaxe+    "tutorial:example_ore_block", 
 +    "tutorial:example_cobblestone_block" 
 +  ] 
 +}
 </code> </code>
  
-==== Dealing with Block Material Madness ==== +Fabric API also provides two additional tags ''fabric:mineable/sword'' and ''fabric:mineable/shears'' for blocks that can be harvested with a sword or shearsYou put these tags in ''resources/data/fabric/tags/blocks/mineable/''.
-Vanilla pickaxes are effective for ''STONE'', ''METAL'' and ''ANVIL''. +
-Vanilla axes are effective for ''WOOD'', ''NETHER_WOOD'', ''PLANT'', ''REPLACEABLE_PLANT'', ''BAMBOO'', ''PUMPKIN''.+
  
-If you use any of these materials, the tool will break your block even if it is under the required mining level+==== Setting the block'mining level ====
-To avoid this, you must create your own clone of the material. Let's say you want to create a clone for ''Material.STONE'', take a look at the code for ''Material.STONE'': +
-<code java> +
-new Material.Builder(MaterialColor.STONE).requiresTool().build() +
-</code>+
  
-Turn ''Material.Builder'' into ''FabricMaterialBuilder'' and you will get this+To add a mining level requirement to your block that is under netherite, you'll need to add it to one of these three tags inside tags/blocks
-<code java+<code> 
-new FabricMaterialBuilder(MaterialColor.STONE).requiresTool().build()+Stone or higher -> needs_stone_tool.json 
 +Iron or higher -> needs_iron_tool.json 
 +Diamond or higher -> needs_diamond_tool.json
 </code> </code>
  
-==== Disable drops when using the invalid tool ==== +Here we make our late-game ore variants require a diamond tool to harvest
-You will need to set ''requiresTool'' in the material of the block, therefore you will want to create a clone for your material. +<code JavaScript /src/main/resources/data/minecraft/tags/blocks/needs_diamond_tool.json
-Let's say you want to create a clone for ''Material.WOOD'' to make your wooden block drop only when using the correct tool, take a look at the code for ''Material.STONE''+
-<code java+  "replace": false, 
-new Material.Builder(MaterialColor.WOOD).burnable().build()+  "values":
 +    "tutorial:example_late_game_ore", 
 +    "tutorial:example_late_game_deepslate_ore" 
 +  ] 
 +}
 </code> </code>
  
-Turn ''Material.Builder'' into ''FabricMaterialBuilder'' and **add ''requiresTool()''**, you will get this+Fabric API provides dynamic tags for mining levels above diamond, as well as for wood (mining level 0)Dynamic mining level tags are in the format ''fabric:needs_tool_level_N'', where ''N'' is the wanted tool level as an integer. For example, a mining level tag for netherite (mining level 4would be ''fabric:needs_tool_level_4''. Dynamic tags are checked automatically. You put these tags in ''resources/fabric/tags/blocks/''. 
-<code java+<code JavaScript /src/main/resources/data/fabric/tags/blocks/needs_tool_level_4.json
-new FabricMaterialBuilder(MaterialColor.WOOD).burnable().requiresTool().build()+
 +  "replace": false, 
 +  "values":
 +    "tutorial:example_tough_block", 
 +    "tutorial:example_netherite_anvil_block" 
 +  ] 
 +}
 </code> </code>
  
-==== Making a custom tool ====+The default mining level of blocks not modified with mining level tags is -1 (the hand mining level). 
 + 
 +==== Tool Tags ====
 You will need to add your tool into the fabric tool tags to support modded blocks. You will need to add your tool into the fabric tool tags to support modded blocks.
  
 Example of adding a pickaxe to the ''pickaxes'' tag: Example of adding a pickaxe to the ''pickaxes'' tag:
-<code json> + 
-/src/main/resources/data/fabric/tags/items/pickaxes.json+<code javascript /src/main/resources/data/fabric/tags/items/pickaxes.json>
 { {
   "replace": false,   "replace": false,
   "values": [   "values": [
-    "examplemod:example_pickaxe"+    "tutorial:example_pickaxe"
   ]   ]
 } }
 </code> </code>
tutorial/mining_levels.1589381459.txt.gz · Last modified: 2020/05/13 14:50 by shedaniel