Resource Right/Fastest/Optimal Tool Types

Discussion in 'Spigot Plugin Development' started by Trigary, Jun 2, 2017.

  1. The following is a list of blocks, sorted based on their optimal tool (the tool with which you can break it the fastest).

    GRAVEL, MYCEL, SOIL, SNOW, SAND, SOUL_SAND, DIRT, SNOW_BLOCK, GRASS, GRASS_PATH, CLAY

    Material.GRAVEL, Material.MYCEL, Material.SOIL, Material.SNOW, Material.SAND, Material.SOUL_SAND, Material.DIRT, Material.SNOW_BLOCK, Material.GRASS, Material.GRASS_PATH, Material.CLAY

    TRAPPED_CHEST, LOG_2, BIRCH_DOOR, DARK_OAK_FENCE, WORKBENCH, WOOD_DOUBLE_STEP, DARK_OAK_FENCE_GATE, SPRUCE_DOOR, WALL_SIGN, HUGE_MUSHROOM_1, WOOD_STAIRS, JUNGLE_FENCE, LADDER, MELON_BLOCK, NOTE_BLOCK, CHEST, WOOD, WALL_BANNER, BIRCH_FENCE_GATE, WOOD_BUTTON, ACACIA_FENCE, JUNGLE_FENCE_GATE, VINE, JACK_O_LANTERN, LOG, FENCE_GATE, BIRCH_WOOD_STAIRS, SPRUCE_FENCE, BIRCH_FENCE, WOOD_PLATE, SIGN_POST, DARK_OAK_STAIRS, SPRUCE_FENCE_GATE, WOOD_STEP, PUMPKIN, JUNGLE_DOOR, JUKEBOX, SPRUCE_WOOD_STAIRS, CHORUS_FLOWER, ACACIA_DOOR, FENCE, STANDING_BANNER, BOOKSHELF, TRAP_DOOR, DAYLIGHT_DETECTOR, DARK_OAK_DOOR, HUGE_MUSHROOM_2, DAYLIGHT_DETECTOR_INVERTED, ACACIA_STAIRS, CHORUS_PLANT, ACACIA_FENCE_GATE, COCOA, WOODEN_DOOR, JUNGLE_WOOD_STAIRS

    Material.TRAPPED_CHEST, Material.LOG_2, Material.BIRCH_DOOR, Material.DARK_OAK_FENCE, Material.WORKBENCH, Material.WOOD_DOUBLE_STEP, Material.DARK_OAK_FENCE_GATE, Material.SPRUCE_DOOR, Material.WALL_SIGN, Material.HUGE_MUSHROOM_1, Material.WOOD_STAIRS, Material.JUNGLE_FENCE, Material.LADDER, Material.MELON_BLOCK, Material.NOTE_BLOCK, Material.CHEST, Material.WOOD, Material.WALL_BANNER, Material.BIRCH_FENCE_GATE, Material.WOOD_BUTTON, Material.ACACIA_FENCE, Material.JUNGLE_FENCE_GATE, Material.VINE, Material.JACK_O_LANTERN, Material.LOG, Material.FENCE_GATE, Material.BIRCH_WOOD_STAIRS, Material.SPRUCE_FENCE, Material.BIRCH_FENCE, Material.WOOD_PLATE, Material.SIGN_POST, Material.DARK_OAK_STAIRS, Material.SPRUCE_FENCE_GATE, Material.WOOD_STEP, Material.PUMPKIN, Material.JUNGLE_DOOR, Material.JUKEBOX, Material.SPRUCE_WOOD_STAIRS, Material.CHORUS_FLOWER, Material.ACACIA_DOOR, Material.FENCE, Material.STANDING_BANNER, Material.BOOKSHELF, Material.TRAP_DOOR, Material.DAYLIGHT_DETECTOR, Material.DARK_OAK_DOOR, Material.HUGE_MUSHROOM_2, Material.DAYLIGHT_DETECTOR_INVERTED, Material.ACACIA_STAIRS, Material.CHORUS_PLANT, Material.ACACIA_FENCE_GATE, Material.COCOA, Material.WOODEN_DOOR, Material.JUNGLE_WOOD_STAIRS

    NETHER_BRICK, IRON_PLATE, GOLD_ORE, QUARTZ_STAIRS, RAILS, DISPENSER, GOLD_BLOCK, PURPUR_SLAB, BRICK_STAIRS, NETHER_FENCE, NETHER_BRICK_STAIRS, QUARTZ_BLOCK, COAL_ORE, MAGENTA_SHULKER_BOX, MOSSY_COBBLESTONE, ANVIL, DROPPER, DOUBLE_STEP, LIME_SHULKER_BOX, STONE_BUTTON, DOUBLE_STONE_SLAB2, BRICK, BREWING_STAND, STONE, SMOOTH_BRICK, MOB_SPAWNER, PURPUR_DOUBLE_SLAB, RED_SANDSTONE, REDSTONE_BLOCK, RED_NETHER_BRICK, DIAMOND_BLOCK, PINK_SHULKER_BOX, BLUE_SHULKER_BOX, POWERED_RAIL, IRON_DOOR_BLOCK, OBSIDIAN, ICE, SANDSTONE, QUARTZ_ORE, GRAY_SHULKER_BOX, ENCHANTMENT_TABLE, COAL_BLOCK, HARD_CLAY, ACTIVATOR_RAIL, FROSTED_ICE, RED_SHULKER_BOX, EMERALD_ORE, CAULDRON, SMOOTH_STAIRS, NETHERRACK, COBBLESTONE_STAIRS, PACKED_ICE, STONE_SLAB2, SILVER_SHULKER_BOX, HOPPER, COBBLE_WALL, LAPIS_ORE, NETHER_WART_BLOCK, IRON_TRAPDOOR, BLACK_SHULKER_BOX, PURPUR_BLOCK, GLOWSTONE, REDSTONE_ORE, GLOWING_REDSTONE_ORE, IRON_ORE, LAPIS_BLOCK, BONE_BLOCK, END_BRICKS, MAGMA, PURPUR_STAIRS, PRISMARINE, STAINED_CLAY, GOLD_PLATE, RED_SANDSTONE_STAIRS, IRON_FENCE, SANDSTONE_STAIRS, YELLOW_SHULKER_BOX, NETHER_WARTS, ORANGE_SHULKER_BOX, DIAMOND_ORE, IRON_BLOCK, EMERALD_BLOCK, OBSERVER, ENDER_STONE, BROWN_SHULKER_BOX, BURNING_FURNACE, LIGHT_BLUE_SHULKER_BOX, FURNACE, ENDER_CHEST, STONE_PLATE, PURPLE_SHULKER_BOX, DETECTOR_RAIL, PURPUR_PILLAR, GREEN_SHULKER_BOX, COBBLESTONE, WHITE_SHULKER_BOX, CYAN_SHULKER_BOX, STEP

    Material.NETHER_BRICK, Material.IRON_PLATE, Material.GOLD_ORE, Material.QUARTZ_STAIRS, Material.RAILS, Material.DISPENSER, Material.GOLD_BLOCK, Material.PURPUR_SLAB, Material.BRICK_STAIRS, Material.NETHER_FENCE, Material.NETHER_BRICK_STAIRS, Material.QUARTZ_BLOCK, Material.COAL_ORE, Material.MAGENTA_SHULKER_BOX, Material.MOSSY_COBBLESTONE, Material.ANVIL, Material.DROPPER, Material.DOUBLE_STEP, Material.LIME_SHULKER_BOX, Material.STONE_BUTTON, Material.DOUBLE_STONE_SLAB2, Material.BRICK, Material.BREWING_STAND, Material.STONE, Material.SMOOTH_BRICK, Material.MOB_SPAWNER, Material.PURPUR_DOUBLE_SLAB, Material.RED_SANDSTONE, Material.REDSTONE_BLOCK, Material.RED_NETHER_BRICK, Material.DIAMOND_BLOCK, Material.PINK_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.POWERED_RAIL, Material.IRON_DOOR_BLOCK, Material.OBSIDIAN, Material.ICE, Material.SANDSTONE, Material.QUARTZ_ORE, Material.GRAY_SHULKER_BOX, Material.ENCHANTMENT_TABLE, Material.COAL_BLOCK, Material.HARD_CLAY, Material.ACTIVATOR_RAIL, Material.FROSTED_ICE, Material.RED_SHULKER_BOX, Material.EMERALD_ORE, Material.CAULDRON, Material.SMOOTH_STAIRS, Material.NETHERRACK, Material.COBBLESTONE_STAIRS, Material.PACKED_ICE, Material.STONE_SLAB2, Material.SILVER_SHULKER_BOX, Material.HOPPER, Material.COBBLE_WALL, Material.LAPIS_ORE, Material.NETHER_WART_BLOCK, Material.IRON_TRAPDOOR, Material.BLACK_SHULKER_BOX, Material.PURPUR_BLOCK, Material.GLOWSTONE, Material.REDSTONE_ORE, Material.GLOWING_REDSTONE_ORE, Material.IRON_ORE, Material.LAPIS_BLOCK, Material.BONE_BLOCK, Material.END_BRICKS, Material.MAGMA, Material.PURPUR_STAIRS, Material.PRISMARINE, Material.STAINED_CLAY, Material.GOLD_PLATE, Material.RED_SANDSTONE_STAIRS, Material.IRON_FENCE, Material.SANDSTONE_STAIRS, Material.YELLOW_SHULKER_BOX, Material.NETHER_WARTS, Material.ORANGE_SHULKER_BOX, Material.DIAMOND_ORE, Material.IRON_BLOCK, Material.EMERALD_BLOCK, Material.OBSERVER, Material.ENDER_STONE, Material.BROWN_SHULKER_BOX, Material.BURNING_FURNACE, Material.LIGHT_BLUE_SHULKER_BOX, Material.FURNACE, Material.ENDER_CHEST, Material.STONE_PLATE, Material.PURPLE_SHULKER_BOX, Material.DETECTOR_RAIL, Material.PURPUR_PILLAR, Material.GREEN_SHULKER_BOX, Material.COBBLESTONE, Material.WHITE_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.STEP

    How to use these?
    Check out EnumSets (EnumSet#of).

    It's not fancy, it only exists to get the job done :)
    Code (Java):

    public class Main {
       private static Set<Material> shovel;
       private static Set<Material> axe;
       private static Set<Material> pickaxe;
       private static Set<Material> leftover;
     
       // https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
       // http://minecraft.gamepedia.com/Breaking#Best_tools
     
       public static void main (String[] args) {
          shovel = new HashSet<> ();
          axe = new HashSet<> ();
          pickaxe = new HashSet<> ();
          leftover = new HashSet<> ();
       
          for (Material material : Material.values ()) {
             if (!material.isBlock ()) {
                continue;
             }
           
             List<String> name = Arrays.asList (material.name ().toLowerCase ().split ("_"));
           
             if (name.contains ("diode") || name.contains ("glass") || name.contains ("water") || name.contains ("lava") || name.contains ("torch")
                   || name.contains ("lamp") || name.contains ("piston") || name.contains ("command") || name.contains ("stem") || name.contains ("leaves") ||
                   name.contains ("comparator")) {
                continue;
             } else if (name.contains ("stone") || name.contains ("ore") || name.contains ("iron") || name.contains ("rail") || name.contains ("nether") ||
                   name.contains ("shulker") || name.contains ("quartz") || name.contains ("cobblestone") || name.contains ("sandstone") ||
                   name.contains ("brick") || name.contains ("ice")) {
                pickaxe.add (material);
             } else if (name.contains ("wood") || name.contains ("wooden") || name.contains ("spruce") || name.contains ("oak") || name.contains ("birch") || name.contains ("jungle") ||
                   name.contains ("acacia") || name.contains ("log") || name.contains ("daylight") || name.contains ("sign")) {
                axe.add (material);
             } else if (name.contains ("sand") || name.contains ("grass") || name.contains ("dirt") || name.contains ("snow")) {
                shovel.add (material);
             } else {
                leftover.add (material);
             }
          }
       
          add (shovel, Material.MYCEL, Material.CLAY, Material.SOIL, Material.GRAVEL);
          add (axe, Material.FENCE, Material.FENCE_GATE, Material.LADDER, Material.MELON_BLOCK, Material.PUMPKIN, Material.JACK_O_LANTERN, Material.VINE, Material.COCOA,
               Material.BOOKSHELF, Material.CHEST, Material.WORKBENCH, Material.TRAP_DOOR, Material.TRAPPED_CHEST, Material.JUKEBOX, Material.NOTE_BLOCK, Material.MELON_BLOCK,
               Material.STANDING_BANNER, Material.WALL_BANNER, Material.CHORUS_PLANT, Material.CHORUS_FLOWER, Material.HUGE_MUSHROOM_1, Material.HUGE_MUSHROOM_2);
          add (pickaxe, Material.EMERALD_BLOCK, Material.COAL_BLOCK, Material.DIAMOND_BLOCK, Material.GOLD_BLOCK, Material.LAPIS_BLOCK, Material.COBBLE_WALL, Material.PRISMARINE,
               Material.RAILS, Material.GLOWSTONE, Material.STAINED_CLAY, Material.HOPPER, Material.ANVIL, Material.REDSTONE_BLOCK,
               Material.BREWING_STAND, Material.CAULDRON, Material.GOLD_PLATE, Material.DISPENSER, Material.ENDER_CHEST, Material.MAGMA, Material.DROPPER, Material.FURNACE,
               Material.MOB_SPAWNER, Material.OBSIDIAN, Material.ENCHANTMENT_TABLE, Material.BONE_BLOCK, Material.OBSERVER, Material.BURNING_FURNACE, Material.PURPUR_BLOCK,
               Material.PURPUR_DOUBLE_SLAB, Material.PURPUR_PILLAR, Material.PURPUR_SLAB, Material.PURPUR_STAIRS, Material.STEP, Material.END_BRICKS, Material.NETHERRACK,
               Material.HARD_CLAY, Material.SMOOTH_BRICK, Material.SMOOTH_STAIRS, Material.DOUBLE_STEP);
       
          remove (shovel, Material.LONG_GRASS);
          remove (axe);
          remove (pickaxe);
          remove (leftover, Material.REDSTONE_WIRE, Material.MONSTER_EGGS, Material.POTATO, Material.TRIPWIRE_HOOK, Material.DOUBLE_PLANT, Material.FLOWER_POT, Material.RED_ROSE,
                  Material.CACTUS, Material.DRAGON_EGG, Material.CAKE_BLOCK, Material.CROPS, Material.LEVER, Material.SAPLING, Material.AIR, Material.FIRE, Material.BARRIER,
                  Material.DEAD_BUSH, Material.SUGAR_CANE_BLOCK, Material.YELLOW_FLOWER, Material.BEACON, Material.TNT, Material.TRIPWIRE, Material.CARROT, Material.STRUCTURE_VOID,
                  Material.BEDROCK, Material.PORTAL, Material.SKULL, Material.SPONGE, Material.RED_MUSHROOM, Material.BROWN_MUSHROOM, Material.STRUCTURE_BLOCK, Material.END_GATEWAY,
                  Material.ENDER_PORTAL_FRAME, Material.CARPET, Material.ENDER_PORTAL, Material.END_ROD, Material.WEB, Material.BED_BLOCK, Material.WOOL, Material.SLIME_BLOCK,
                  Material.HAY_BLOCK, Material.BEETROOT_BLOCK, Material.SEA_LANTERN);
       
          printSet ("shovel", shovel);
          printSet ("axe", axe);
          printSet ("pickaxe", pickaxe);
          printSet ("leftover", leftover);
       }
     
     
     
       private static void remove (Set<Material> set, Material... materials) {
          for (Material material : materials) {
             set.remove (material);
          }
       }
     
       private static void add (Set<Material> set, Material... materials) {
          for (Material material : materials) {
             set.add (material);
             leftover.remove (material);
          }
       }
     
       private static void printSet (String name, Set<Material> set) {
          System.out.println (name);
          StringBuilder builder = new StringBuilder ();
          for (Material material : set) {
             builder.append (material.name ()).append (", ");
          }
          System.out.println (builder.toString ());
          builder = new StringBuilder ();
          for (Material material : set) {
             builder.append ("Material.").append (material.name ()).append (", ");
          }
          System.out.println (builder.toString ());
          System.out.println ();
       }
    }
     

    Hello!
    I want to check whether the player who breaks the block (sand) uses the right tool for it (shovel).

    I have made a list containing all of the Materials which's tool is a shovel:
    Code (Text):
    EnumSet.of (Material.CLAY, Material.SOIL, Material.GRASS, Material.GRASS_PATH, Material.GRAVEL, Material.MYCEL, Material.DIRT, Material.SAND, Material.SOUL_SAND, Material.SNOW_BLOCK, Material.SNOW);
    But doing for axes and pickaxes will be much harder (especially for the axes, because of the wood variants: BIRCH_DOOR, SPRUCE_DOOR, etc).

    I can either take my time and create these EnumSets or I can check whether the Material's name contains "birch", "spruce", etc.
    Does a better method than these exist? Has someone else done these before?
     
    #1 Trigary, Jun 2, 2017
    Last edited: Jun 3, 2017
  2. block#getDrops(ItemStack) will return an empty collection if the itemstack isn't the correct tool.

    Not sure how things like doors are handled since they technically dont have a "correct tool" needed to break. You can break a lot of things with anything, including your hand.

    Code (Text):

    public void onBlockBreak(BlockBreakEvent event) {
        if (event.getBlock().getDrops(event.getPlayer().getInventory().getItemInMainHand()).isEmpty()) {
            // collection is empty, broke with wrong tool.
        }
    }
     
     
  3. Thank you for your suggestion, but I am trying to find the "optimal" tool, meaning the tool with which you break the block the fastest.
     
  4. Mas

    Mas

    There isn't a built-in way to find the best tool for breaking a block unfortunately. Unless someone else has made one you might have to do it the long way. If you do, sharing it would be good :p
     
  5. Pls share if you do make it
     
  6. Okay, the first version is done. Please let me know in this thread if there are any mistakes!