Class BlockPosUtil

java.lang.Object
com.ldtteam.structurize.api.util.BlockPosUtil

public final class BlockPosUtil extends Object
Utility methods for BlockPos.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable net.minecraft.core.BlockPos
    findSafeTeleportPos(@NotNull net.minecraft.world.level.Level level, @NotNull net.minecraft.core.BlockPos target, boolean falling)
    Given a target position, try to find a nearby location where a player can stand without suffocating.
    static String
    format(net.minecraft.core.BlockPos pos)
    Format a BlockPos to a string suitable for commands
    static long
    getDistanceSquared(net.minecraft.core.BlockPos block1, net.minecraft.core.BlockPos block2)
    Squared distance between two BlockPos.
    static net.minecraft.core.BlockPos
    getNextPosInCircleFrom(net.minecraft.core.BlockPos start, net.minecraft.core.BlockPos corner1, net.minecraft.core.BlockPos corner2, int ringHeight)
    Gets the next position to use in a circular-creeping inward snake manner.
    static net.minecraft.world.level.block.Rotation
    getRotationFromRotations(int rotations)
    Get the rotation enum value from the amount of rotations.
    static boolean
    isInbetween(net.minecraft.core.BlockPos inside, net.minecraft.core.BlockPos corner1, net.minecraft.core.BlockPos corner2)
    Check if the given position is inside the given corners, corner order does not matter
    static net.minecraft.core.BlockPos
    readFromNBT(net.minecraft.nbt.CompoundTag compound, String name)
    Reads Chunk Coordinates from an NBT Compound with a specific tag name.
    static void
    writeToNBT(net.minecraft.nbt.CompoundTag compound, String name, net.minecraft.core.BlockPos pos)
    Writes a Chunk Coordinate to an NBT compound, with a specific tag name.
    static void
    writeToNBTTagList(net.minecraft.nbt.ListTag tagList, net.minecraft.core.BlockPos pos)
    Write a compound with chunk coordinate to a tag list.

    Methods inherited from class java.lang.Object

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

    • format

      public static String format(net.minecraft.core.BlockPos pos)
      Format a BlockPos to a string suitable for commands
      Parameters:
      pos - the pos
      Returns:
      a space-separated set of coord values
    • writeToNBT

      public static void writeToNBT(net.minecraft.nbt.CompoundTag compound, String name, net.minecraft.core.BlockPos pos)
      Writes a Chunk Coordinate to an NBT compound, with a specific tag name.
      Parameters:
      compound - Compound to write to.
      name - Name of the tag.
      pos - Coordinates to write to NBT.
    • readFromNBT

      public static net.minecraft.core.BlockPos readFromNBT(net.minecraft.nbt.CompoundTag compound, String name)
      Reads Chunk Coordinates from an NBT Compound with a specific tag name.
      Parameters:
      compound - Compound to read data from.
      name - Tag name to read data from.
      Returns:
      Chunk coordinates read from the compound.
    • writeToNBTTagList

      public static void writeToNBTTagList(net.minecraft.nbt.ListTag tagList, net.minecraft.core.BlockPos pos)
      Write a compound with chunk coordinate to a tag list.
      Parameters:
      tagList - Tag list to write compound with chunk coordinates to.
      pos - Coordinate to write to the tag list.
    • getDistanceSquared

      public static long getDistanceSquared(net.minecraft.core.BlockPos block1, net.minecraft.core.BlockPos block2)
      Squared distance between two BlockPos.
      Parameters:
      block1 - position one.
      block2 - position two.
      Returns:
      squared distance.
    • getRotationFromRotations

      public static net.minecraft.world.level.block.Rotation getRotationFromRotations(int rotations)
      Get the rotation enum value from the amount of rotations.
      Parameters:
      rotations - the amount of rotations.
      Returns:
      the enum Rotation.
    • isInbetween

      public static boolean isInbetween(net.minecraft.core.BlockPos inside, net.minecraft.core.BlockPos corner1, net.minecraft.core.BlockPos corner2)
      Check if the given position is inside the given corners, corner order does not matter
      Parameters:
      inside - inside position to check
      corner1 - first corner
      corner2 - second corner
      Returns:
    • getNextPosInCircleFrom

      public static net.minecraft.core.BlockPos getNextPosInCircleFrom(net.minecraft.core.BlockPos start, net.minecraft.core.BlockPos corner1, net.minecraft.core.BlockPos corner2, int ringHeight)
      Gets the next position to use in a circular-creeping inward snake manner. Its iterating the rectangle of corners in clockwise rotation
      Parameters:
      start - current positions
      corner1 - rectangle top left corner
      corner2 - rectangle bottom right corner
      ringHeight - the y height we iterate before advancing inwards
      Returns:
      next position
    • findSafeTeleportPos

      @Nullable public static @Nullable net.minecraft.core.BlockPos findSafeTeleportPos(@NotNull @NotNull net.minecraft.world.level.Level level, @NotNull @NotNull net.minecraft.core.BlockPos target, boolean falling)
      Given a target position, try to find a nearby location where a player can stand without suffocating. Searches for a 1x2x1 space of air, first at the same y level and then trying more y levels.
      Parameters:
      level - the level to search
      target - the original target location
      falling - if true, checks for something to land on as well; if false, assumes you don't care about fall dmg
      Returns:
      the safe target location, or null if none could be found