Package me.hackware.api.util
Class BlockUtils
java.lang.Object
me.hackware.api.util.BlockUtils
Block breaking utilities — breaking speed, break delta, tool search, etc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanBreak(net.minecraft.core.BlockPos pos) static booleancanBreak(net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) static InventoryUtil.FindItemResultfindFastestTool(net.minecraft.world.level.block.state.BlockState state) Finds the fastest tool in the entire inventory (hotbar + main) for the given block state.static InventoryUtil.FindItemResultfindFastestToolHotbar(net.minecraft.world.level.block.state.BlockState state) Finds the fastest tool in the hotbar only.static floatgetBlockBreakingSpeed(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 floatgetBlockBreakingSpeedFor(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.block.state.BlockState state) Same calculation asgetBlockBreakingSpeed(int, BlockState, boolean)but for an arbitrary player using whatever they're holding in their main hand.static floatgetBreakDelta(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 floatgetBreakDelta(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 booleanisAirLike(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 booleanisAirLike(net.minecraft.world.level.block.state.BlockState st, net.minecraft.core.BlockPos pos) State-based variant ofisAirLike(BlockPos)when the caller already has the state.static booleanisInstaMineable(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.
-
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 ofisAirLike(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 vanillaPlayer.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 mineonGround- 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 asgetBlockBreakingSpeed(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 (fromgetBlockBreakingSpeed(int, net.minecraft.world.level.block.state.BlockState, boolean))state- Block state being minedpos- 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
Iterates all block positions within the given axis-aligned bounding box.
-