Posted July 1, 20223 yr 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?
July 1, 20223 yr Author 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.
July 1, 20223 yr 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.
July 1, 20223 yr 9 minutes ago, Syric said: I want to check if the tool used (if any) is a pickaxe ItemStack#canPerformAction with ToolActions.PICKAXE_DIG
July 1, 20223 yr 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.
July 1, 20223 yr 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 July 1, 20223 yr 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.
July 1, 20223 yr 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
July 1, 20223 yr Author 1 hour ago, Luis_ST said: ItemStack#canPerformAction with ToolActions.PICKAXE_DIG This seems to have worked, thanks!
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.