Package com.ldtteam.structurize.api
Class BlockPosUtil
java.lang.Object
com.ldtteam.structurize.api.BlockPosUtil
Utility methods for BlockPos.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable net.minecraft.core.BlockPosfindSafeTeleportPos(@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 Stringformat(net.minecraft.core.BlockPos pos) Format aBlockPosto a string suitable for commandsstatic longgetDistanceSquared(net.minecraft.core.BlockPos block1, net.minecraft.core.BlockPos block2) Squared distance between two BlockPos.static net.minecraft.core.BlockPosgetNextPosInCircleFrom(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 booleanisInbetween(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 matterstatic net.minecraft.core.BlockPosreadFromNBT(net.minecraft.nbt.CompoundTag compound, String name) Reads Chunk Coordinates from an NBT Compound with a specific tag name.static voidwriteToNBT(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 voidwriteToNBTTagList(net.minecraft.nbt.ListTag tagList, net.minecraft.core.BlockPos pos) Write a compound with chunk coordinate to a tag list.
-
Method Details
-
format
Format aBlockPosto 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.
-
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 checkcorner1- first cornercorner2- 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 positionscorner1- rectangle top left cornercorner2- rectangle bottom right cornerringHeight- 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 searchtarget- the original target locationfalling- 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
-