Class BlockUtil

java.lang.Object
com.binaris.wizardry.api.content.util.BlockUtil

public final class BlockUtil extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A SurfaceCriteria object is used to define a 'surface', a boundary between two blocks which differ in some way, for use in getNearestSurface(Level, BlockPos, Direction, int, boolean, SurfaceCriteria).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canBlockBeReplaced(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Checks whether a block at the given position in the given level can be replaced.
    static boolean
    canBlockBeReplaced(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, boolean excludeLiquids)
    Checks whether a block at the given position in the given level can be replaced.
    static boolean
    canBreak(net.minecraft.world.entity.Mob mob, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Checks whether the given mob can break the block at the given position in the given level following these rules: If the block break event is cancelled (called on each loader implementation), the block cannot be broken. If the block is outside the build height, it cannot be broken. If the block is unbreakable (destroy speed is less than 0 like bedrock), it cannot be broken. If the block's destroy speed is greater than 3.0f, it cannot be broken.
    static boolean
    canBreak(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, boolean powerful)
    Checks whether the given player can break the block at the given position in the given level following these rules: If the block break event is cancelled (called on each loader implementation), the block cannot be broken. If the player is in creative mode, they can break the block. If the player does not have build permissions, they cannot break the block. If the block is outside the build height, it cannot be broken. If the block is unbreakable (destroy speed is less than 0 like bedrock), it cannot be broken. If the player is in spectator mode, they cannot break the block. If the block's destroy speed is greater than 3.0f and the 'powerful' flag is false, it cannot be broken. Finally, if none of the above prevent it, the player's ability to interact with the block is checked.
    static boolean
    canPlaceBlock(net.minecraft.world.entity.LivingEntity placer, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Checks whether the given entity can place a block at the given position in the given level following these rules: If the entity cannot damage blocks, it cannot place the block. If the block is outside the build height, it cannot be placed. Finally, if the entity is a player, their ability to interact with the block is checked.
    static @Nullable net.minecraft.core.BlockPos
    findNearbyFloorSpace(net.minecraft.world.entity.Entity entity, int horizontalRange, int verticalRange)
    Finds a random nearby floor space within the given horizontal and vertical range of the given entity's position.
    static @Nullable net.minecraft.core.BlockPos
    findNearbyFloorSpace(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight)
    Finds a random nearby floor space within the given horizontal and vertical range of the given origin position.
    static @Nullable net.minecraft.core.BlockPos
    findNearbyFloorSpace(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight, net.minecraft.world.entity.Entity entity)
    Finds a random nearby floor space within the given horizontal and vertical range of the given origin position.
    static boolean
    freeze(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, boolean freezeLava)
    Freezes water and lava source blocks, converts flowing lava to cobblestone, and adds a layer of snow on top of blocks that can support it.
    static List<net.minecraft.core.BlockPos>
    getBlockSphere(net.minecraft.core.BlockPos centre, double radius)
    Returns a list of BlockPos in a sphere around a centre position.
    static net.minecraft.core.Direction[]
    Used because Direction#BY_2D_DATA is private access only.
    static Integer
    getNearestFloor(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, int range)
    Finds the nearest floor level (a surface that can be stood on) from a given position within a given range.
    static @Nullable Integer
    getNearestSurface(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int range, boolean doubleSided, BlockUtil.SurfaceCriteria criteria)
    Finds the nearest surface from a given position in a given direction within a given range that meets the given criteria.
    static boolean
    isBlockPassable(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos checkPos)
    Checks whether a block at the given position in the given level is passable (i.e.
    static boolean
    isBlockUnbreakable(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
    Checks whether the block at the given position in the given level is unbreakable (i.e.

    Methods inherited from class java.lang.Object

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

    • BlockUtil

      public BlockUtil()
  • Method Details

    • canBlockBeReplaced

      public static boolean canBlockBeReplaced(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Checks whether a block at the given position in the given level can be replaced.
      Parameters:
      world - The level
      pos - The position to check
      Returns:
      True if the block can be replaced, false otherwise
    • getNearestFloor

      public static Integer getNearestFloor(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, int range)
      Finds the nearest floor level (a surface that can be stood on) from a given position within a given range.
      Parameters:
      world - The level
      pos - The position
      range - The maximum range to search
      Returns:
      The Y coordinate of the nearest floor level, or null if none was found
    • canBlockBeReplaced

      public static boolean canBlockBeReplaced(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, boolean excludeLiquids)
      Checks whether a block at the given position in the given level can be replaced.
      Parameters:
      world - The level
      pos - The position to check
      excludeLiquids - Whether to exclude liquids from being considered replaceable
      Returns:
      True if the block can be replaced, false otherwise
    • canBreak

      public static boolean canBreak(net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, boolean powerful)
      Checks whether the given player can break the block at the given position in the given level following these rules:
      • If the block break event is cancelled (called on each loader implementation), the block cannot be broken.
      • If the player is in creative mode, they can break the block.
      • If the player does not have build permissions, they cannot break the block.
      • If the block is outside the build height, it cannot be broken.
      • If the block is unbreakable (destroy speed is less than 0 like bedrock), it cannot be broken.
      • If the player is in spectator mode, they cannot break the block.
      • If the block's destroy speed is greater than 3.0f and the 'powerful' flag is false, it cannot be broken.
      • Finally, if none of the above prevent it, the player's ability to interact with the block is checked.
      Parameters:
      player - The player attempting to break the block
      level - The level the block is in
      pos - The position of the block to be broken
      powerful - Whether to ignore block hardness (e.g. for powerful spells)
      Returns:
      True if the player can break the block, false otherwise
    • canBreak

      public static boolean canBreak(net.minecraft.world.entity.Mob mob, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Checks whether the given mob can break the block at the given position in the given level following these rules:
      • If the block break event is cancelled (called on each loader implementation), the block cannot be broken.
      • If the block is outside the build height, it cannot be broken.
      • If the block is unbreakable (destroy speed is less than 0 like bedrock), it cannot be broken.
      • If the block's destroy speed is greater than 3.0f, it cannot be broken.
      Parameters:
      mob - The mob attempting to break the block
      level - The level the block is in
      pos - The position of the block to be broken
      Returns:
      True if the mob can break the block, false otherwise
    • getHorizontals

      public static net.minecraft.core.Direction[] getHorizontals()
      Used because Direction#BY_2D_DATA is private access only.
    • canPlaceBlock

      public static boolean canPlaceBlock(net.minecraft.world.entity.LivingEntity placer, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Checks whether the given entity can place a block at the given position in the given level following these rules:
      • If the entity cannot damage blocks, it cannot place the block.
      • If the block is outside the build height, it cannot be placed.
      • Finally, if the entity is a player, their ability to interact with the block is checked.
      Parameters:
      placer - The entity attempting to place the block
      world - The level the block is in
      pos - The position of the block to be placed
      Returns:
      True if the entity can place the block, false otherwise
    • findNearbyFloorSpace

      @Nullable public static @Nullable net.minecraft.core.BlockPos findNearbyFloorSpace(net.minecraft.world.entity.Entity entity, int horizontalRange, int verticalRange)
      Finds a random nearby floor space within the given horizontal and vertical range of the given entity's position. A floor space is defined as a position where there is a solid block below and two air blocks above.
      Parameters:
      entity - The entity
      horizontalRange - The horizontal range to search
      verticalRange - The vertical range to search
      Returns:
      A random nearby floor space, or null if none was found
    • findNearbyFloorSpace

      @Nullable public static @Nullable net.minecraft.core.BlockPos findNearbyFloorSpace(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight, net.minecraft.world.entity.Entity entity)
      Finds a random nearby floor space within the given horizontal and vertical range of the given origin position. A floor space is defined as a position where there is a solid block below and two air blocks above.
      Parameters:
      world - The level
      origin - The origin position
      horizontalRange - The horizontal range to search
      verticalRange - The vertical range to search
      lineOfSight - Whether to require line of sight from the origin to the found position
      entity - The entity for line of sight calculations
      Returns:
      A random nearby floor space, or null if none was found
    • findNearbyFloorSpace

      @Nullable public static @Nullable net.minecraft.core.BlockPos findNearbyFloorSpace(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos origin, int horizontalRange, int verticalRange, boolean lineOfSight)
      Finds a random nearby floor space within the given horizontal and vertical range of the given origin position. A floor space is defined as a position where there is a solid block below and two air blocks above.
      Parameters:
      world - The level
      origin - The origin position
      horizontalRange - The horizontal range to search
      verticalRange - The vertical range to search
      lineOfSight - Whether to require line of sight from the origin to the found position
      Returns:
      A random nearby floor space, or null if none was found
    • isBlockUnbreakable

      public static boolean isBlockUnbreakable(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos)
      Checks whether the block at the given position in the given level is unbreakable (i.e. bedrock or air).
      Parameters:
      world - The level
      pos - The position to check
      Returns:
      True if the block is unbreakable, false otherwise
    • getBlockSphere

      public static List<net.minecraft.core.BlockPos> getBlockSphere(net.minecraft.core.BlockPos centre, double radius)
      Returns a list of BlockPos in a sphere around a centre position.
      Parameters:
      centre - The centre position
      radius - The radius of the sphere
      Returns:
      A list of BlockPos in a sphere around the centre position
    • getNearestSurface

      @Nullable public static @Nullable Integer getNearestSurface(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int range, boolean doubleSided, BlockUtil.SurfaceCriteria criteria)
      Finds the nearest surface from a given position in a given direction within a given range that meets the given criteria.
      Parameters:
      world - The world
      pos - The starting position
      direction - The direction to search in
      range - The maximum range to search
      doubleSided - Whether to search in both directions along the given axis
      criteria - The criteria that defines a surface
      Returns:
      The coordinate of the nearest surface along the given axis, or null if none was found
    • freeze

      public static boolean freeze(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, boolean freezeLava)
      Freezes water and lava source blocks, converts flowing lava to cobblestone, and adds a layer of snow on top of blocks that can support it.
      Parameters:
      world - The world
      pos - The position to freeze
      freezeLava - Whether to freeze lava as well as water
      Returns:
      True if a block was changed, false otherwise
    • isBlockPassable

      public static boolean isBlockPassable(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos checkPos)
      Checks whether a block at the given position in the given level is passable (i.e. can be moved through).
      Parameters:
      world - The level
      checkPos - The position to check
      Returns:
      True if the block is passable, false otherwise