Class BlockPos
- Namespace
- Vintagestory.API.MathTools
- Assembly
- VintagestoryAPI.dll
A useful data structure when operating with block postions.
Valuable Hint: Make use of Copy() or the XXXCopy() variants where needed. A common pitfall is writing code like: BlockPos abovePos = pos.Up(); - with this code abovePos and pos will reference to the same object!
[ProtoContract]
public class BlockPos : IEquatable<BlockPos>, IVec3
- Inheritance
-
BlockPos
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
BlockPos()
[Obsolete("Not dimension-aware. Use new BlockPos(dimensionId) where possible")]
public BlockPos()
BlockPos(int)
public BlockPos(int dim)
Parameters
dim
int
BlockPos(int, int, int)
[Obsolete("Not dimension-aware. Use overload with a dimension parameter instead")]
public BlockPos(int x, int y, int z)
Parameters
BlockPos(int, int, int, int)
public BlockPos(int x, int y, int z, int dim)
Parameters
BlockPos(Vec3i)
[Obsolete("Not dimension-aware. Use overload with a dimension parameter instead")]
public BlockPos(Vec3i vec)
Parameters
vec
Vec3i
BlockPos(Vec3i, int)
public BlockPos(Vec3i vec, int dim)
Parameters
BlockPos(Vec4i)
Note - for backwards compatibility, this is not dimension-aware; explicitly set the dimension in the resulting BlockPos if you need to
public BlockPos(Vec4i vec)
Parameters
vec
Vec4i
Fields
DimensionBoundary
public const int DimensionBoundary = 32768
Field Value
X
[ProtoMember(1)]
public int X
Field Value
Y
public int Y
Field Value
Z
[ProtoMember(3)]
public int Z
Field Value
dimension
public int dimension
Field Value
Properties
AsVec3i
[JsonIgnore]
public Vec3i AsVec3i { get; }
Property Value
InternalY
[ProtoMember(2)]
public int InternalY { get; set; }
Property Value
this[int]
0 = x, 1 = y, 2 = z
public int this[int i] { get; set; }
Parameters
i
int
Property Value
Methods
Add(int, int, int)
Offsets the position by given xyz
public BlockPos Add(int dx, int dy, int dz)
Parameters
Returns
Add(float, float, float)
Offsets the position by given xyz
public BlockPos Add(float dx, float dy, float dz)
Parameters
Returns
Add(BlockFacing, int)
Offsets the position into the direction of given block face
public BlockPos Add(BlockFacing facing, int length = 1)
Parameters
facing
BlockFacinglength
int
Returns
Add(BlockPos)
Offsets the position by given xyz vector
public BlockPos Add(BlockPos pos)
Parameters
pos
BlockPos
Returns
Add(FastVec3i)
Offsets the position by given xyz vector
public BlockPos Add(FastVec3i vector)
Parameters
vector
FastVec3i
Returns
Add(Vec3i)
Offsets the position by given xyz vector
public BlockPos Add(Vec3i vector)
Parameters
vector
Vec3i
Returns
AddCopy(int)
Creates a copy of this blocks position and offsets it by given xyz
public BlockPos AddCopy(int xyz)
Parameters
xyz
int
Returns
AddCopy(int, int, int)
Creates a copy of this blocks position and offsets it by given xyz
public BlockPos AddCopy(int dx, int dy, int dz)
Parameters
Returns
AddCopy(float, float, float)
Creates a copy of this blocks position and offsets it by given xyz
public BlockPos AddCopy(float dx, float dy, float dz)
Parameters
Returns
AddCopy(BlockFacing)
Creates a copy of this blocks position and offsets it in the direction of given block face
public BlockPos AddCopy(BlockFacing facing)
Parameters
facing
BlockFacing
Returns
AddCopy(BlockFacing, int)
Creates a copy of this blocks position and offsets it in the direction of given block face
public BlockPos AddCopy(BlockFacing facing, int length)
Parameters
facing
BlockFacinglength
int
Returns
AddCopy(Vec3i)
Creates a copy of this blocks position and offsets it by given xyz
public BlockPos AddCopy(Vec3i vector)
Parameters
vector
Vec3i
Returns
Copy()
Creates a copy of this blocks position
public virtual BlockPos Copy()
Returns
CopyAndCorrectDimension()
Creates a copy of this blocks position, obtaining the correct dimension value from the Y value
public virtual BlockPos CopyAndCorrectDimension()
Returns
CreateFromBytes(BinaryReader)
public static BlockPos CreateFromBytes(BinaryReader reader)
Parameters
reader
BinaryReader
Returns
DistanceSqTo(double, double, double)
Returns the squared Euclidean distance to between this and given position. Dimension aware
public float DistanceSqTo(double x, double y, double z)
Parameters
Returns
DistanceSqToNearerEdge(double, double, double)
Returns the squared Euclidean distance between the nearer edge of this blockpos (assumed 1 x 0.75 x 1 cube) and given position The 0.75 offset is because the "heat source" is likely to be above the base position of this block: it's approximate Note this is dimension unaware
public double DistanceSqToNearerEdge(double x, double y, double z)
Parameters
Returns
DistanceTo(double, double, double)
Returns the Euclidean distance to between this and given position. Note this is dimension unaware
public float DistanceTo(double x, double y, double z)
Parameters
Returns
DistanceTo(BlockPos)
Returns the Euclidean distance to between this and given position. Note if dimensions are different returns maximum value (i.e. infinite)
public float DistanceTo(BlockPos pos)
Parameters
pos
BlockPos
Returns
DivCopy(int)
Creates a copy of this blocks position and divides it by given factor
public BlockPos DivCopy(int factor)
Parameters
factor
int
Returns
Down(int)
Move the position vertically down
public BlockPos Down(int dy = 1)
Parameters
dy
int
Returns
DownCopy(int)
Creates a copy of this blocks position with the y-position adjusted by -length
public BlockPos DownCopy(int length = 1)
Parameters
length
int
Returns
East()
public BlockPos East()
Returns
EastCopy(int)
Creates a copy of this blocks position with the x-position adjusted by +length
public BlockPos EastCopy(int length = 1)
Parameters
length
int
Returns
Equals(int, int, int)
public bool Equals(int x, int y, int z)
Parameters
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
Equals(BlockPos)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(BlockPos other)
Parameters
other
BlockPosAn object to compare with this object.
Returns
FacingFrom(BlockPos)
Returns the direction moved from the other blockPos, to get to this BlockPos
public BlockFacing FacingFrom(BlockPos other)
Parameters
other
BlockPos
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
HorDistanceSqTo(double, double)
Returns the squared Euclidean horizontal distance to between this and given position Note this is dimension unaware
public float HorDistanceSqTo(double x, double z)
Parameters
Returns
HorizontalManhattenDistance(BlockPos)
Returns the manhatten distance to given position
public int HorizontalManhattenDistance(BlockPos pos)
Parameters
pos
BlockPos
Returns
InRangeHorizontally(int, int, int)
Returns true if the specified x,z is within a box the specified range around this position Note this is dimension unaware
public bool InRangeHorizontally(int x, int z, int range)
Parameters
Returns
ManhattenDistance(int, int, int)
Returns the manhatten distance to given position Note this is dimension unaware
public int ManhattenDistance(int x, int y, int z)
Parameters
Returns
ManhattenDistance(BlockPos)
Returns the manhatten distance to given position
public int ManhattenDistance(BlockPos pos)
Parameters
pos
BlockPos
Returns
North()
public BlockPos North()
Returns
NorthCopy(int)
Creates a copy of this blocks position with the z-position adjusted by -length
public BlockPos NorthCopy(int length = 1)
Parameters
length
int
Returns
Offset(BlockFacing)
Offsets the position into the direction of given block face
public BlockPos Offset(BlockFacing facing)
Parameters
facing
BlockFacing
Returns
Set(int, int, int)
Sets XYZ to new values - not dimension aware (but existing dimension will be preserved) - use SetAndCorrectDimension() for dimension awareness
public BlockPos Set(int x, int y, int z)
Parameters
Returns
Set(float, float, float)
public BlockPos Set(float x, float y, float z)
Parameters
Returns
Set(BlockPos)
public BlockPos Set(BlockPos blockPos)
Parameters
blockPos
BlockPos
Returns
Set(FastVec3i)
public BlockPos Set(FastVec3i pos)
Parameters
pos
FastVec3i
Returns
Set(Vec3d)
Not dimension aware (but existing dimension in this BlockPos will be preserved) - use SetAndCorrectDimension() for dimension awareness
public BlockPos Set(Vec3d origin)
Parameters
origin
Vec3d
Returns
Set(Vec3i)
public BlockPos Set(Vec3i pos)
Parameters
pos
Vec3i
Returns
SetAndCorrectDimension(int, int, int)
Dimension aware version of Set() - use this if there is a dimension embedded in the y coordinate (e.g. y == 65536+ for dimension 2)
public BlockPos SetAndCorrectDimension(int x, int y, int z)
Parameters
Returns
SetAndCorrectDimension(Vec3d)
Dimension aware version of Set() - use this if the Vec3d has the dimension embedded in the Y coordinate (e.g. Y == 65536+ for dimension 2)
public BlockPos SetAndCorrectDimension(Vec3d origin)
Parameters
origin
Vec3d
Returns
SetAndEquals(int, int, int)
Sets this BlockPos to the x,y,z values given, and returns a boolean stating if the existing values were already equal to x,y,z
public bool SetAndEquals(int x, int y, int z)
Parameters
Returns
- bool
Returns true if the BlockPos already held these exact x, y, z values (the .Set operation has not changed anything)
Returns false if the .Set operation caused a change to the BlockPos
SetDimension(int)
public BlockPos SetDimension(int dim)
Parameters
dim
int
Returns
South()
public BlockPos South()
Returns
SouthCopy(int)
Creates a copy of this blocks position with the z-position adjusted by +length
public BlockPos SouthCopy(int length = 1)
Parameters
length
int
Returns
Sub(int, int, int)
Substract a position => you'll have the manhatten distance
public BlockPos Sub(int x, int y, int z)
Parameters
Returns
Sub(BlockPos)
Substract a position => you'll have the manhatten distance
public BlockPos Sub(BlockPos pos)
Parameters
pos
BlockPos
Returns
SubCopy(int, int, int)
public BlockPos SubCopy(int x, int y, int z)
Parameters
Returns
SubCopy(BlockPos)
Substract a position => you'll have the manhatten distance
public BlockPos SubCopy(BlockPos pos)
Parameters
pos
BlockPos
Returns
ToBytes(BinaryWriter)
public void ToBytes(BinaryWriter writer)
Parameters
writer
BinaryWriter
ToLocalPosition(ICoreAPI)
Convert a block position to coordinates relative to the world spawn position. Note this is dimension unaware
public Vec3i ToLocalPosition(ICoreAPI api)
Parameters
api
ICoreAPI
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
ToVec3d()
Creates a new instance of a Vec3d initialized with this position Note this is dimension unaware
public Vec3d ToVec3d()
Returns
ToVec3f()
public Vec3f ToVec3f()
Returns
ToVec3i()
Creates a new instance of a Vec3i initialized with this position Note this is dimension unaware
public Vec3i ToVec3i()
Returns
Up(int)
Move the position vertically up
public BlockPos Up(int dy = 1)
Parameters
dy
int
Returns
UpCopy(int)
Creates a copy of this blocks position with the y-position adjusted by +length
public BlockPos UpCopy(int length = 1)
Parameters
length
int
Returns
Walk(BlockPos, BlockPos, Vec3i, Action<int, int, int>)
public static void Walk(BlockPos startPos, BlockPos untilPos, Vec3i mapSizeForClamp, Action<int, int, int> onpos)
Parameters
West()
public BlockPos West()
Returns
WestCopy(int)
Creates a copy of this blocks position with the x-position adjusted by -length
public BlockPos WestCopy(int length = 1)
Parameters
length
int
Returns
Operators
operator +(BlockPos, int)
public static BlockPos operator +(BlockPos left, int right)
Parameters
Returns
operator +(BlockPos, BlockPos)
public static BlockPos operator +(BlockPos left, BlockPos right)
Parameters
Returns
operator /(BlockPos, int)
public static BlockPos operator /(BlockPos left, int right)
Parameters
Returns
operator ==(BlockPos, BlockPos)
public static bool operator ==(BlockPos left, BlockPos right)
Parameters
Returns
operator !=(BlockPos, BlockPos)
public static bool operator !=(BlockPos left, BlockPos right)
Parameters
Returns
operator *(int, BlockPos)
public static BlockPos operator *(int left, BlockPos right)
Parameters
Returns
operator *(BlockPos, int)
public static BlockPos operator *(BlockPos left, int right)
Parameters
Returns
operator -(BlockPos, int)
public static BlockPos operator -(BlockPos left, int right)
Parameters
Returns
operator -(BlockPos, BlockPos)
public static BlockPos operator -(BlockPos left, BlockPos right)