Class SixSidedUtils
java.lang.Object
etithespirit.orimod.info.coordinate.SixSidedUtils
A static master-class used for all operations pertaining to bitwise flags for blocks that do things with their neighbors.
This contains a wide array of features designed to handle cardinal
Its most important attribute is that it can condense the enabled/disabled status of a given cardinal
Finally, due to its extensive use, this provides the ability to convert between
BooleanProperties
(UP/DOWN/NORTH/SOUTH/EAST/WEST),
Directions
, and more.Its most important attribute is that it can condense the enabled/disabled status of a given cardinal
BooleanProperty
into
an integer value that uses its first six bits. The index of these bits (from LSB to MSB) corresponds directly to the order of
directions in Cardinals
, so for instance, bit0 represents Cardinals.ADJACENTS_IN_ORDER
[0].Finally, due to its extensive use, this provides the ability to convert between
Direction
and cardinal BooleanProperty
instances.
It also provides a means of getting the opposite cardinal BooleanProperty
relative to another cardinal BooleanProperty
(for example, BlockStateProperties.EAST
will return BlockStateProperties.WEST
)- Author:
- Eti
-
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.world.phys.shapes.VoxelShape[]
getBitwiseColliderArrayFor
(Function<Integer, net.minecraft.world.phys.shapes.VoxelShape> getShapeFor) Given a method that takes in an integer value ranging from 0b000000 to 0b111111 and returns a corresponding voxel shape, this will return a 64-VoxelShape array for every possible combination of bits.static net.minecraft.world.level.block.state.properties.BooleanProperty
getBlockStateForSingleFlagValue
(int flag) static net.minecraft.world.level.block.state.properties.BooleanProperty
getBlockStateFromDirection
(net.minecraft.core.Direction direction) Given aDirection
, this will return the associated cardinal blockstate (for instance,Direction.DOWN
returnsBlockStateProperties.DOWN
).static net.minecraft.world.level.block.state.properties.BooleanProperty
getBlockStateFromEvidentFace
(net.minecraft.core.BlockPos blockPos, net.minecraft.world.phys.Vec3 preciseClickPos) Given a block raytrace, this returns the closest face direction when comparing the ray's precise 3D location to the center of the block.
This is strictly useful if the block is NOT a cube.static net.minecraft.core.Direction
getDirectionBetweenBlocks
(net.minecraft.core.BlockPos from, net.minecraft.core.BlockPos to) Returns theDirection
of from -> to.static net.minecraft.core.Direction
getDirectionBetweenBlocks
(net.minecraft.core.BlockPos blockPos, net.minecraft.world.phys.Vec3 preciseClickPos) Returns aDirection
representative of where the givenVec3
sits relative to the givenBlockPos
static int
getFlagsForNeighborsWhere
(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at, com.mojang.datafixers.util.Function3<net.minecraft.world.level.block.state.BlockState, net.minecraft.core.BlockPos, net.minecraft.core.BlockPos, Boolean> filter) Returns all neighbors to the block at the given position that satisfy the given predicate.static int
getNonAirNonFluidFullNeighbors
(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at) Returns directional flags representing which blocks around the given location are not air, not a fluid or waterlogged, and have a full face facing the block at the givenBlockPos
.static int
getNonAirNonFluidFullNeighbors
(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos... forcedNeighbors) Returns directional flags representing which blocks around the given location are not air, not a fluid or waterlogged, and have a full face facing the block at the givenBlockPos
.static int
getNumberFromSurfaces
(boolean east, boolean west, boolean up, boolean down, boolean north, boolean south) Given six boolean values, each representing a face's occupied state, this returns a numeric value with the appropriate bit flags set.static int
getNumberFromSurfaces
(net.minecraft.world.level.block.state.BlockState state) CallsgetNumberFromSurfaces(boolean, boolean, boolean, boolean, boolean, boolean)
from the givenBlockState
's data, which should contain six booleans representing each face's occupied state.static boolean
hasNonAirNonFluidFullNeighbor
(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at) This returns true if at least one adjacent block is not air, not occupied by a fluid or waterlogged, and has a funn face facing the block at the givenBlockPos
.static boolean
isAdjacent
(net.minecraft.core.Vec3i difference) Returns whether or not the givenVec3i
value represents an offset that would put it adjacent to any givenVec3i
if the two were added.static boolean
isAdjacent
(net.minecraft.core.Vec3i from, net.minecraft.core.Vec3i to) Returns whether or not the givenVec3i
values are directly adjacent to one another.static int
neighborFlagForBlockDirection
(net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos otherAt) Given two given block positions, this will return a value with a single flag set that represents the direction fromat
->otherAt
.static net.minecraft.world.level.block.state.properties.BooleanProperty
oppositeState
(net.minecraft.world.level.block.state.properties.BooleanProperty cardinalBlockstateProp) Given a "cardinal blockstate" (UP/DOWN/NORTH/SOUTH/EAST/WEST), this will return the BooleanProperty in the opposite direction (for instance,BlockStateProperties.DOWN
returnsBlockStateProperties.UP
).static void
setAllBlocksForFlags
(net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos origin, int flags) For each flag inflags
that is set, the neighbor to this block will be changed to the given blockstate.static net.minecraft.world.level.block.state.BlockState
whereSurfaceFlagsAre
(net.minecraft.world.level.block.state.BlockState original, int flags) Assuming the input BlockState has the six cardinal flags (UP/DOWN/NORTH/SOUTH/EAST/WEST), and assuming that the input flags value is a six-bit value acquired from something likegetNumberFromSurfaces(BlockState)
this will return the BlockState with a given property set to true or false depending on if a given bit is 1 or 0.
-
Method Details
-
getBlockStateForSingleFlagValue
public static net.minecraft.world.level.block.state.properties.BooleanProperty getBlockStateForSingleFlagValue(int flag) -
isAdjacent
public static boolean isAdjacent(net.minecraft.core.Vec3i from, net.minecraft.core.Vec3i to) Returns whether or not the givenVec3i
values are directly adjacent to one another.- Parameters:
from
- The origin position.to
- The target position.- Returns:
- True if the two positions are next to eachother in the 3D grid.
-
isAdjacent
public static boolean isAdjacent(net.minecraft.core.Vec3i difference) Returns whether or not the givenVec3i
value represents an offset that would put it adjacent to any givenVec3i
if the two were added.- Parameters:
difference
- The difference between twoVec3i
s.- Returns:
- True if the two positions are next to eachother in the 3D grid.
-
getBitwiseColliderArrayFor
public static net.minecraft.world.phys.shapes.VoxelShape[] getBitwiseColliderArrayFor(Function<Integer, net.minecraft.world.phys.shapes.VoxelShape> getShapeFor) Given a method that takes in an integer value ranging from 0b000000 to 0b111111 and returns a corresponding voxel shape, this will return a 64-VoxelShape array for every possible combination of bits. The specific shape returned should be determined with the givenFunction
- Parameters:
getShapeFor
- AFunction
that will construct a shape for a given set of flags.- Returns:
- An array of 64
VoxelShape
instances representing every possible combination for all six directions. These are ordered so that a given flag value as an index will return the appropriateVoxelShape
for that value.
-
getNumberFromSurfaces
public static int getNumberFromSurfaces(boolean east, boolean west, boolean up, boolean down, boolean north, boolean south) Given six boolean values, each representing a face's occupied state, this returns a numeric value with the appropriate bit flags set.- Parameters:
west
- Whether or not the west (X+) face is occupied. (Note that west is right because this is relative to Z-, where south is forward.)east
- Whether or not the east (X-) face is occupied. (Note that east is left because this is relative to Z-, where south is forward.)up
- Whether or not the top face (Y+) is occupied.down
- Whether or not the bottom (Y-) face is occupied.north
- Whether or not the back face (Z+) is occupied.south
- Whether or not the front face (Z-) is occupied.- Returns:
- A numeric value with the first six
-
getNumberFromSurfaces
public static int getNumberFromSurfaces(net.minecraft.world.level.block.state.BlockState state) CallsgetNumberFromSurfaces(boolean, boolean, boolean, boolean, boolean, boolean)
from the givenBlockState
's data, which should contain six booleans representing each face's occupied state.- Parameters:
state
- The state to use.- Returns:
- A numeric value representing which surfaces are enabled.
-
neighborFlagForBlockDirection
public static int neighborFlagForBlockDirection(net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos otherAt) Given two given block positions, this will return a value with a single flag set that represents the direction fromat
->otherAt
. Note that these blocks MUST be adjacent.- Parameters:
at
- The origin block; the "from" component of this direction.otherAt
- The destination block; the "to" component of this direction.- Returns:
- A numeric value representing the given direction.
-
getNonAirNonFluidFullNeighbors
public static int getNonAirNonFluidFullNeighbors(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at) Returns directional flags representing which blocks around the given location are not air, not a fluid or waterlogged, and have a full face facing the block at the givenBlockPos
.- Parameters:
worldIn
- TheLevelReader
for the world this block exists in.at
- The location of this block in the world.- Returns:
- Flags representing which surrounding neighbors have a full face facing this block, and that are not waterlogged or a fluid.
-
getNonAirNonFluidFullNeighbors
public static int getNonAirNonFluidFullNeighbors(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos... forcedNeighbors) Returns directional flags representing which blocks around the given location are not air, not a fluid or waterlogged, and have a full face facing the block at the givenBlockPos
.- Parameters:
worldIn
- TheLevelReader
for the world this block exists in.at
- The location of this block in the world.forcedNeighbors
- Any neighbors defined here will forcefully have their flag set to 1. This only works for normals. (magnitude of 1, only 1 axis set to 1).- Returns:
- Flags representing which surrounding neighbors have a full face facing this block, and that are not waterlogged or a fluid.
-
getFlagsForNeighborsWhere
public static int getFlagsForNeighborsWhere(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at, com.mojang.datafixers.util.Function3<net.minecraft.world.level.block.state.BlockState, net.minecraft.core.BlockPos, net.minecraft.core.BlockPos, Boolean> filter) Returns all neighbors to the block at the given position that satisfy the given predicate.- Parameters:
worldIn
- TheLevelReader
for the world that this block exists in.at
- The location of this block in the world.filter
- APredicate
that determines whether a given neighbor'sBlockState
is valid.- Returns:
- A numeric value with all bits set for directions that satisfy the predicate.
-
hasNonAirNonFluidFullNeighbor
public static boolean hasNonAirNonFluidFullNeighbor(net.minecraft.world.level.BlockGetter worldIn, net.minecraft.core.BlockPos at) This returns true if at least one adjacent block is not air, not occupied by a fluid or waterlogged, and has a funn face facing the block at the givenBlockPos
.- Parameters:
worldIn
- TheLevelReader
for the world the given block exists in.at
- The position of the block to check in the world.- Returns:
- Whether or not at least one neighbor is sturdy and is not a fluid.
-
getBlockStateFromDirection
public static net.minecraft.world.level.block.state.properties.BooleanProperty getBlockStateFromDirection(net.minecraft.core.Direction direction) throws IllegalArgumentException Given aDirection
, this will return the associated cardinal blockstate (for instance,Direction.DOWN
returnsBlockStateProperties.DOWN
).- Parameters:
direction
- The direction to convert.- Returns:
- A
BooleanProperty
representing a direction equivalent to the givenDirection
. - Throws:
IllegalArgumentException
- If the input value is not valid.
-
oppositeState
public static net.minecraft.world.level.block.state.properties.BooleanProperty oppositeState(net.minecraft.world.level.block.state.properties.BooleanProperty cardinalBlockstateProp) throws IllegalArgumentException Given a "cardinal blockstate" (UP/DOWN/NORTH/SOUTH/EAST/WEST), this will return the BooleanProperty in the opposite direction (for instance,BlockStateProperties.DOWN
returnsBlockStateProperties.UP
).- Parameters:
cardinalBlockstateProp
- A cardinal state.- Returns:
- A state in the opposite direction.
- Throws:
IllegalArgumentException
- If the input value is not one of the six cardinal blockstates.
-
getDirectionBetweenBlocks
@Nullable public static net.minecraft.core.Direction getDirectionBetweenBlocks(net.minecraft.core.BlockPos from, net.minecraft.core.BlockPos to) Returns theDirection
of from -> to. The blocks must be adjacent, otherwise the method will return null.- Parameters:
from
- The start position.to
- The end position.- Returns:
- A direction from start to end, or null if the blocks are not adjacent.
-
getBlockStateFromEvidentFace
public static net.minecraft.world.level.block.state.properties.BooleanProperty getBlockStateFromEvidentFace(net.minecraft.core.BlockPos blockPos, net.minecraft.world.phys.Vec3 preciseClickPos) Given a block raytrace, this returns the closest face direction when comparing the ray's precise 3D location to the center of the block.
This is strictly useful if the block is NOT a cube. Otherwise just useBlockHitResult.getDirection()
and pass it intogetBlockStateFromDirection(Direction)
.- Parameters:
blockPos
- The position of the block to test.preciseClickPos
- A precise point somewhere around this block, usually acquired from a raycast result.- Returns:
- A
BooleanProperty
representing one of the six cardinal directions.
-
getDirectionBetweenBlocks
public static net.minecraft.core.Direction getDirectionBetweenBlocks(net.minecraft.core.BlockPos blockPos, net.minecraft.world.phys.Vec3 preciseClickPos) Returns aDirection
representative of where the givenVec3
sits relative to the givenBlockPos
- Parameters:
blockPos
- The position of the block to test.preciseClickPos
- A precise point somewhere around this block, usually acquired from a raycast result.- Returns:
- A
Direction
best representing the direction that the point is at relative to the block.
-
whereSurfaceFlagsAre
public static net.minecraft.world.level.block.state.BlockState whereSurfaceFlagsAre(net.minecraft.world.level.block.state.BlockState original, int flags) Assuming the input BlockState has the six cardinal flags (UP/DOWN/NORTH/SOUTH/EAST/WEST), and assuming that the input flags value is a six-bit value acquired from something likegetNumberFromSurfaces(BlockState)
this will return the BlockState with a given property set to true or false depending on if a given bit is 1 or 0.- Parameters:
original
- The originalBlockState
to base this off of. It will be used to acquire the default state for itsBlock
.flags
- The flags representing which directions should be true and false.- Returns:
- A new
BlockState
associated with the givenBlock
whose cardinal properties are representative of the given flags.
-
setAllBlocksForFlags
public static void setAllBlocksForFlags(net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos origin, int flags) For each flag inflags
that is set, the neighbor to this block will be changed to the given blockstate.- Parameters:
level
- The world to change.state
- The state to placeorigin
- The origin of the placement, which the neighbors are situated around.flags
- Surface flags acquired by this class.
-