# Getting Started (Tutorial)

**Step 1:** Add BlockHardness to your project

<pre class="language-xml"><code class="lang-xml"><strong>       // Maven
</strong><strong>       &#x3C;repository>
</strong>            &#x3C;id>jitpack.io&#x3C;/id>
            &#x3C;url>https://jitpack.io&#x3C;/url>
        &#x3C;/repository>       

        &#x3C;dependency>
            &#x3C;groupId>com.github.OwnerAli&#x3C;/groupId>
            &#x3C;artifactId>BlockHardness&#x3C;/artifactId>
            &#x3C;version>-SNAPSHOT&#x3C;/version>
            &#x3C;scope>provided&#x3C;/scope>
        &#x3C;/dependency>

<strong>        // Gradle
</strong><strong>        repositories {
</strong>            maven { url 'https://jitpack.io' }
        }

        dependencies {
            implementation 'com.github.OwnerAli:BlockHardness:master-SNAPSHOT'
        }
</code></pre>

***

**Step 2:** The player needs the miner fatigue potion effect for this plugin to work! Because of this, you'll need to give it to them when they join, or whenever you want them to have a custom block breaking speed. IT NEEDS TO BE MINER FATIGUE LEVEL -1!!

```java
Player#addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, Integer.MAX_VALUE,
                        -1, false, false, false)
```

***

{% hint style="info" %}
Keep in mind the BlockHardness library was designed for my CustomDrops plugin which handles custom drops which is why it doesn't support many regular dropping options like fortune, tools, etc. You're meant to handle that in your own plugin if you wish to do so.
{% endhint %}

**Step 3:** Now that your player has MinerFatigue LEVEL -1, you have to listen to the BlockHardnessBlockInteractEvent to start the mining process with your desired speed.\
\
Example of how I use it in my CustomDrops Plugin:

<pre class="language-java"><code class="lang-java"><strong>BlockHardnessPlugin blockHardness = (BlockHardnessPlugin) CustomDrops.getInstance()
</strong>                .getServer().getPluginManager().getPlugin("BlockHardness");
                
blockHardness.getBreakPlayerRegistry().getBreakPlayer(player)
                .ifPresent(breakPlayer -> breakPlayer.startMining(block,
                                finalBreakSpeed, false));
</code></pre>

Method BreakPlayer#startMining(Block block, double breakSpeedInSeconds, boolean dropVanillaBlock).

<mark style="color:green;">Param 1</mark>: The block you want to start mining

<mark style="color:green;">Param 2</mark>: The speed at which the block should be mined at

<mark style="color:green;">Param 3</mark>: If the block should drop itself when broken\
\
**For example**, my CustomDrops plugin uses it but has conditions to limit whether or not a player can mine with certain permissions, what speed the player will mine based on their tool, fortune multiplier if tool has fortune, etc.

***

**Optional Step 4:** You can also listen to the CustomHardnessBlockBreakEvent. This event is fired when a block is done being mined at a custom speed. I use this event to drop custom drops in my CustomDrops plugin. You can do whatever you want with it though. \
\
**For example**, OreRegenerator uses this event to add regeneration support to CustomHardness blocks because they don't fire a BlockBreakEvent.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.vanixmc.com/blockhardness-library/getting-started-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
