Struct DecorBits
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
An actual instance of this struct is the 'faceAndSubposition' data.
The struct also provides various static methods to convert elements to and from a PackedIndex used in WorldChunk storage
public struct DecorBits
- Inherited Members
- Extension Methods
Constructors
DecorBits(int)
public DecorBits(int value)
Parameters
value
int
DecorBits(BlockFacing)
Simplest case, we supply just a face (no subposition for cave-art, and no rotation)
public DecorBits(BlockFacing face)
Parameters
face
BlockFacing
DecorBits(BlockFacing, int, int, int)
Turn both face and local voxel position to a decor faceAndSubposition index
public DecorBits(BlockFacing face, int vx, int vy, int vz)
Parameters
face
BlockFacingvx
int0..15
vy
int0..15
vz
int0..15
Fields
maskRotationData
A bit mask to select the three rotation data bits; this is also the maxvalue of the rotationData
public const int maskRotationData = 7
Field Value
Properties
Face
public int Face { get; }
Property Value
Rotation
public int Rotation { get; set; }
Property Value
SubPosition
public int SubPosition { get; }
Property Value
Methods
FaceAndSubpositionFromIndex(int)
public static int FaceAndSubpositionFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
FaceAndSubpositionToIndex(int)
The packedIndex works like this: [radfast 7 Dec 2024, 1.20-rc.2]
The packedIndex has four components:
index3d for the block's local x,y,z value within the chunk, each in the range 0-31, for 15 bits in total
faceindex for the face of the block this decor is on (corresponding to BlockFacing.Index), range 0-5
optionally, a subposition in the range 0-256, where 0 means no subposition, and values 1-256 give a subposition in the 16x16 subgrid, used for ArtPigment or similar
optionally, 3 bits of rotation data
These are packed into bits in the following way, it has to be this way for backwards compatibility reasons (assuming we do not want to add a new chunk dataversion)
31 - 24 (the five Least Significant Bits of the subposition) * 6 + faceindex
23 - 21 (the three Most Significant Bits of the subposition)
20 - 19 (unused)
18 - 16 rotation data
15 (unused)
14 - 0 index3d
(Exceptionally, the value in bits 31-24 has the magic value of (0x20 * 6 + faceindex), and the value in bits 23-16 is 0xE0, if a subposition value of 256 is intended: this works within the existing algorithms because 0xE0 + 0x20 == 0x100 i.e. 256. If necessary we can have values up to 0x2A there, so the range of possible subpositions is up to 266)
0000 0000 0000 0000 0000 0000 0000 0000
public static int FaceAndSubpositionToIndex(int faceAndSubposition)
Parameters
faceAndSubposition
int
Returns
FaceFromIndex(int)
public static int FaceFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
FaceToIndex(BlockFacing)
public static int FaceToIndex(BlockFacing face)
Parameters
face
BlockFacing
Returns
FacingFromIndex(int)
public static BlockFacing FacingFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
Index3dFromIndex(int)
public static int Index3dFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
RotationFromIndex(int)
public static int RotationFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
SubpositionFromIndex(int)
public static int SubpositionFromIndex(int packedIndex)
Parameters
packedIndex
int
Returns
Operators
implicit operator int(DecorBits)
public static implicit operator int(DecorBits a)