Class BlockUtils

java.lang.Object
me.hackware.api.util.BlockUtils

public final class BlockUtils extends Object
Block breaking utilities — breaking speed, break delta, tool search, etc.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canBreak(net.minecraft.core.BlockPos pos)
     
    static boolean
    canBreak(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
     
    findFastestTool(net.minecraft.world.level.block.state.BlockState state)
    Finds the fastest tool in the entire inventory (hotbar + main) for the given block state.
    findFastestToolHotbar(net.minecraft.world.level.block.state.BlockState state)
    Finds the fastest tool in the hotbar only.
    static float
    getBlockBreakingSpeed(int slot, net.minecraft.world.level.block.state.BlockState state, boolean onGround)
    Calculates the block-breaking speed for a given inventory slot against a block state.
    static float
    getBlockBreakingSpeedFor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.block.state.BlockState state)
    Same calculation as getBlockBreakingSpeed(int, BlockState, boolean) but for an arbitrary player using whatever they're holding in their main hand.
    static float
    getBreakDelta(float speed, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.world.item.ItemStack toolStack)
    Returns the break progress per tick for a given speed, state, and tool.
    static float
    getBreakDelta(int slot, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos)
    Convenience overload using a specific slot index and the player's on-ground state.
    static boolean
    isAirLike(net.minecraft.core.BlockPos pos)
    Whether this block counts as air for combat checks: genuinely air/replaceable, a liquid, has no collision shape, or is a whitelisted soft block an explosion destroys anyway.
    static boolean
    isAirLike(net.minecraft.world.level.block.state.BlockState st, net.minecraft.core.BlockPos pos)
    State-based variant of isAirLike(BlockPos) when the caller already has the state.
    static boolean
    isInstaMineable(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos)
    True if this block can be broken in a single tick (insta-mine) right now, accounting for the fastest tool currently in the hotbar plus Haste, Efficiency, on-ground and water modifiers.
    static Iterable<net.minecraft.core.BlockPos>
    iterate(net.minecraft.world.phys.AABB box)
    Iterates all block positions within the given axis-aligned bounding box.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isAirLike

      public static boolean isAirLike(net.minecraft.core.BlockPos pos)
      Whether this block counts as air for combat checks: genuinely air/replaceable, a liquid, has no collision shape, or is a whitelisted soft block an explosion destroys anyway. Placement legality must NOT use this — the server still rejects placing into most of these blocks.
    • isAirLike

      public static boolean isAirLike(net.minecraft.world.level.block.state.BlockState st, net.minecraft.core.BlockPos pos)
      State-based variant of isAirLike(BlockPos) when the caller already has the state.
    • canBreak

      public static boolean canBreak(net.minecraft.core.BlockPos pos)
    • canBreak

      public static boolean canBreak(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
    • getBlockBreakingSpeed

      public static float getBlockBreakingSpeed(int slot, net.minecraft.world.level.block.state.BlockState state, boolean onGround)
      Calculates the block-breaking speed for a given inventory slot against a block state. Replicates vanilla Player.getDestroySpeed(BlockState) but for an arbitrary slot.
      Parameters:
      slot - Inventory slot index (0–8 hotbar, 9–35 main, or -1 for current main hand)
      state - The block state to mine
      onGround - Whether the player is (or will be) on the ground
      Returns:
      Mining speed multiplier (≥ 1.0 for bare hand)
    • getBlockBreakingSpeedFor

      public static float getBlockBreakingSpeedFor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.block.state.BlockState state)
      Same calculation as getBlockBreakingSpeed(int, BlockState, boolean) but for an arbitrary player using whatever they're holding in their main hand. Used to predict mining time for remote players (e.g. BreakIndicators) so the prediction reflects THEIR tool/effects, not the local player's.
    • getBreakDelta

      public static float getBreakDelta(float speed, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos, net.minecraft.world.item.ItemStack toolStack)
      Returns the break progress per tick for a given speed, state, and tool.
      Parameters:
      speed - Mining speed (from getBlockBreakingSpeed(int, net.minecraft.world.level.block.state.BlockState, boolean))
      state - Block state being mined
      pos - Block position (for hardness lookup)
      toolStack - The tool being used (for harvest check)
      Returns:
      Progress per tick (0.0–1.0; ≥ 1.0 means instant mine)
    • getBreakDelta

      public static float getBreakDelta(int slot, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos)
      Convenience overload using a specific slot index and the player's on-ground state.
    • isInstaMineable

      public static boolean isInstaMineable(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos)
      True if this block can be broken in a single tick (insta-mine) right now, accounting for the fastest tool currently in the hotbar plus Haste, Efficiency, on-ground and water modifiers. Hardness-0 blocks (torches, tnt, …) are always instant; harder blocks qualify only when the tool is fast enough — e.g. a Haste II + Efficiency V diamond pickaxe one-shots stone.

      Only hotbar tools are considered, since that is what a caller can select instantly (a single carried-slot packet) before sending the break.

    • findFastestTool

      public static InventoryUtil.FindItemResult findFastestTool(net.minecraft.world.level.block.state.BlockState state)
      Finds the fastest tool in the entire inventory (hotbar + main) for the given block state.
    • findFastestToolHotbar

      public static InventoryUtil.FindItemResult findFastestToolHotbar(net.minecraft.world.level.block.state.BlockState state)
      Finds the fastest tool in the hotbar only.
    • iterate

      public static Iterable<net.minecraft.core.BlockPos> iterate(net.minecraft.world.phys.AABB box)
      Iterates all block positions within the given axis-aligned bounding box.