Jump to content

Recommended Posts

Posted

How can I check if a block was destroyed with a pickaxe? I found this thread from 1.15, but the method it suggests:

Item::getToolTypes
// Which returns a Set<ToolType>
Set::contains

does not seem to work anymore. What has it been replaced with?

Posted

The context is that I'm calling onDestroyedByPlayer() to make some things happen - specifically, the block might explode. I want to check if the tool used (if any) is a pickaxe, so that if it is, the explosion chance can be decreased.

Posted

Older versions of minecraft used tool types, but this was all reworked.

The new logic uses:

Quote

Item.isCorrectToolForDrops(BlockState).

If you look at the PickaxeItem/DiggerItem this checks the tier of the tool then checks if the block is in BlockTags.MINEABLE_WITH_PICKAXE

So you could just use that method passing your block state.

 

Alternatively If the tool is vanilla, or a modded pick that reuses vanilla code, you could do

if (player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof PickaxeItem)

but not all modded picks are PickaxeItems. And other non-picks might use the BlockTags.MINEABLE_WITH_PICKAXE, e.g. drills or hammers.

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.

Posted

Another option would be to use an ItemTag that would contain the items that give reduced explosion chances. You would have the vanilla picks by default, but users could add other tools.

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.

Posted (edited)
8 minutes ago, Luis_ST said:

ItemStack#canPerformAction with ToolActions.PICKAXE_DIG

Doesn't that have the same problem as instanceof?

If the modded tool doesn't extend PickaxeItem and doesn't provide an implementation of the canPerformAction?

Edited by warjort

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.

Posted
4 minutes ago, warjort said:

If the modded tool doesn't extend PickaxeItem and doesn't provide an implementation of the canPerformAction?

the ToolAction system is design to fix this,
if Item#canPerformAction with ToolActions.PICKAXE_DIG returns true the item has the Pickaxe behaviour

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.

Announcements



×
×
  • Create New...

Important Information

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