Class SixSidedUtils

java.lang.Object
etithespirit.orimod.info.coordinate.SixSidedUtils

public final class SixSidedUtils extends Object
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 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 Type
    Method
    Description
    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.
    static net.minecraft.world.level.block.state.properties.BooleanProperty
     
    static net.minecraft.world.level.block.state.properties.BooleanProperty
    getBlockStateFromDirection(net.minecraft.core.Direction direction)
    Given a Direction, this will return the associated cardinal blockstate (for instance, Direction.DOWN returns BlockStateProperties.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 the Direction of from -> to.
    static net.minecraft.core.Direction
    getDirectionBetweenBlocks(net.minecraft.core.BlockPos blockPos, net.minecraft.world.phys.Vec3 preciseClickPos)
    Returns a Direction representative of where the given Vec3 sits relative to the given BlockPos
    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 given BlockPos.
    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 given BlockPos.
    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)
    Calls getNumberFromSurfaces(boolean, boolean, boolean, boolean, boolean, boolean) from the given BlockState'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 given BlockPos.
    static boolean
    isAdjacent(net.minecraft.core.Vec3i difference)
    Returns whether or not the given Vec3i value represents an offset that would put it adjacent to any given Vec3i if the two were added.
    static boolean
    isAdjacent(net.minecraft.core.Vec3i from, net.minecraft.core.Vec3i to)
    Returns whether or not the given Vec3i 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 from at -> 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 returns BlockStateProperties.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 in flags 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 like getNumberFromSurfaces(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 given Vec3i 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 given Vec3i value represents an offset that would put it adjacent to any given Vec3i if the two were added.
      Parameters:
      difference - The difference between two Vec3is.
      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 given Function
      Parameters:
      getShapeFor - A Function 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 appropriate VoxelShape 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)
      Calls getNumberFromSurfaces(boolean, boolean, boolean, boolean, boolean, boolean) from the given BlockState'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 from at -> 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 given BlockPos.
      Parameters:
      worldIn - The LevelReader 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 given BlockPos.
      Parameters:
      worldIn - The LevelReader 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 - The LevelReader for the world that this block exists in.
      at - The location of this block in the world.
      filter - A Predicate that determines whether a given neighbor's BlockState 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 given BlockPos.
      Parameters:
      worldIn - The LevelReader 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 a Direction, this will return the associated cardinal blockstate (for instance, Direction.DOWN returns BlockStateProperties.DOWN).
      Parameters:
      direction - The direction to convert.
      Returns:
      A BooleanProperty representing a direction equivalent to the given Direction.
      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 returns BlockStateProperties.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 the Direction 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 use BlockHitResult.getDirection() and pass it into getBlockStateFromDirection(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 a Direction representative of where the given Vec3 sits relative to the given BlockPos
      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 like getNumberFromSurfaces(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 original BlockState to base this off of. It will be used to acquire the default state for its Block.
      flags - The flags representing which directions should be true and false.
      Returns:
      A new BlockState associated with the given Block 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 in flags 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 place
      origin - The origin of the placement, which the neighbors are situated around.
      flags - Surface flags acquired by this class.