User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:1.1x-1.17:mining_levels

Mining Levels (1.1x-1.17)

Introduction

Vanilla has a terrible system for mining levels, values are hardcoded and there isn't support for mining levels except for pickaxes.

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:

settings.breakByTool(FabricToolTags.PICKAXES, 2)

Here's the list of mining levels:

0 -> Wooden / Golden Pickaxe
1 -> Stone Pickaxe
2 -> Iron Pickaxe
3 -> Diamond Pickaxe
4 -> Netherite Pickaxe

Dealing with Block Material Madness

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.

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:

new Material.Builder(MaterialColor.STONE).requiresTool().build()

Turn Material.Builder into FabricMaterialBuilder and you will get this:

new FabricMaterialBuilder(MaterialColor.STONE).requiresTool().build()

Disable drops when using the invalid tool (For 1.15.x!)

You will need to set requiresTool in the material of the block, therefore you will want to create a clone for your material.

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:

new Material.Builder(MaterialColor.WOOD).burnable().build()

Turn Material.Builder into FabricMaterialBuilder and add requiresTool(), you will get this:

new FabricMaterialBuilder(MaterialColor.WOOD).burnable().requiresTool().build()

Disable drops when using the invalid tool (For 1.16.x!)

You will need to set requiresTool in the settings of the block.

Making a custom tool

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:

File Location: /src/main/resources/data/fabric/tags/items/pickaxes.json

{
  "replace": false,
  "values": [
    "examplemod:example_pickaxe"
  ]
}
tutorial/1.1x-1.17/mining_levels.txt · Last modified: 2022/03/26 00:31 (external edit)