Solved Get blocks pickaxe can destroy

Discussion in 'Spigot Plugin Development' started by Bredo, Jul 1, 2021.

  1. Hello, so basically, I wanted to know if there were a way (or list) to get all the blocks a pickaxe can destroy. Now, of course, I could go in-game a get 'every' block and see if the pickaxe could break it (easily) and then note it down, but it gonna take forever; plus, I am curious to see if there is code or a list anywhere for it.
     
  2. Maybe with some reflections? The easier way would be to do your own list imo
     
  3. yeah, I thought so, but it's not the only pickaxe; I pretty much need to find a list for pickaxe, shovel, ax, sword & hoe. so pretty much every block ingame. hmm, but there should be a way using reflections to loop each block and see what tool has the biggest strength on it.
     
  4. Found something
    Code (Java):
    public static boolean isUsableTool(ItemStack tool, Material block) {
            net.minecraft.world.level.block.Block nmsBlock = org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers.getBlock(block);
            if (nmsBlock == null) { return false; }
            IBlockData data = nmsBlock.getBlockData();
            return tool != null && tool.getType() != Material.AIR && org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers.getItem(tool.getType()).canDestroySpecialBlock(data);
        }
    Credit:
    - https://www.spigotmc.org/threads/get-best-tool-to-break-block.452848/
     
    • Like Like x 1
    • Winner Winner x 1
  5. I didn't know that method; it also does not use NMS, so that's probably what I'm going with.
    thx.
     
    • Like Like x 1
  6. Didn't work tho, it just picked a tool that can break that block
     
  7. I reckon you could probably make an enumeration for yourself, making "PICKAXE" and then deriving which type of PICKAXE is the correct one for the job, taking into account haste, efficiency.

    You could probably also make use of the Block#isPreferredTool(ItemStack) function you found to accomplish this, if you... for example, give it an Axe and it says false, then move on. If you then get to Pickaxe and it says true, then refine which type of pickaxe is the best in the inventory of the player using basic comparisons, such as efficiency level, type etc. etc.
     
  8. the
    Code (Java):
    block#isPreferredTool(ItemStack)
    is not ideal, cause it flags true if the tool can break it, so if I have a shovel and a axe and try to break dirt, it can say the axe is the preferred tool but using
    and there is also a method for getting the block break speed, even with enchantment, maybe combine these to get all the tools and then get the fastest one.
     
    • Like Like x 1