Jump to content

[1.19.2] Check if player can mine the block


Adil Yilan

Recommended Posts

I am implementing some custom logic in LeftClickBlock event handler and I need to determine whether player can destroy block by simple mining with tool in hand.

For example, if player starts to mine the Obsidian with Stone Pickaxe, it would be convenient to have some method that would return false for ability to destroy it, based on tool/material requirements for mining of Obsidian.

Is there such a method already?

I have tried getDestroySpeed on ItemStack and getDigSpeed on Player, but both return a value of 4.00 so I can't make any further logic based on that...

Thanks in advance :)

 

Link to comment
Share on other sites

Player.hasCorrectToolForDrops()

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

@warjort That one is for drops, but I would like to check whether it can be destroyed through mining, regardless if it will drop or not.

For example, hasCorrectToolForDrops method returns false when you mine Diamond Ore Block with Stone Pickaxe - but I really want to know if player can mine it, not if it will drop diamond, so preferred result would be true.

Is there a different method that just checks for ability to destroy it?

Link to comment
Share on other sites

You can pretty much always mine a block. You just don't get any items/drops.

Try punching obsidian for long enough.

 

There are exceptions like

* Command Blocks which is hardcoded,

* Bedrock which has a destroy speed of -1

* or if somebody uses one of the forge events to cancel() the block break.

But I don't think there is any generic way to test for this? They are "ad hoc" logic.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

@warjort Thanks for useful info. :)

I've just found this also:

"The base time in seconds is the block's hardness multiplied by 1.5 if the player can harvest the block with the current tool, or 5 if the player cannot."

So I will most likely go and calculate for duration of time required to break the block by using hardness and player.hasCorrectToolForDrops(), and place threshold instead - e.g. if it is longer than 30 seconds skip action or something like that.

Thanks again :)

 

Link to comment
Share on other sites

There are other considerations, it depends what you are actually trying to achieve?

e.g. if the player has haste or mining fatigue.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I am creating enchant that will allow player to cause quake when mining which will result in several cracks in the ground.

So player hits one block, and with Quake enchantment, stones, stone replaceables and ores in specific directions will also be destroyed and possibly drop loot.

I don't want to allow players to mine blocks with this enchant that would otherwise be very hard to mine with enchanted tool.

So if stone tool takes too much time to mine some block in the path, I might leave that block intact and find another route for crack to happen.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.