Class BlockUtil
java.lang.Object
com.binaris.wizardry.api.content.util.BlockUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceASurfaceCriteriaobject is used to define a 'surface', a boundary between two blocks which differ in some way, for use ingetNearestSurface(Level, BlockPos, Direction, int, boolean, SurfaceCriteria). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanBlockBeReplaced(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 booleancanBlockBeReplaced(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 booleancanBreak(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 booleancanBreak(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 booleancanPlaceBlock(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.BlockPosfindNearbyFloorSpace(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.BlockPosfindNearbyFloorSpace(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.BlockPosfindNearbyFloorSpace(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 booleanfreeze(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 becauseDirection#BY_2D_DATAis private access only.static IntegergetNearestFloor(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 IntegergetNearestSurface(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 booleanisBlockPassable(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 booleanisBlockUnbreakable(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.
-
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 levelpos- 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 levelpos- The positionrange- 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 levelpos- The position to checkexcludeLiquids- 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 blocklevel- The level the block is inpos- The position of the block to be brokenpowerful- 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 blocklevel- The level the block is inpos- 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 becauseDirection#BY_2D_DATAis 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 blockworld- The level the block is inpos- 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 entityhorizontalRange- The horizontal range to searchverticalRange- 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 levelorigin- The origin positionhorizontalRange- The horizontal range to searchverticalRange- The vertical range to searchlineOfSight- Whether to require line of sight from the origin to the found positionentity- 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 levelorigin- The origin positionhorizontalRange- The horizontal range to searchverticalRange- The vertical range to searchlineOfSight- 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 levelpos- 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 positionradius- 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 worldpos- The starting positiondirection- The direction to search inrange- The maximum range to searchdoubleSided- Whether to search in both directions along the given axiscriteria- 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 worldpos- The position to freezefreezeLava- 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 levelcheckPos- The position to check- Returns:
- True if the block is passable, false otherwise
-