Interface IWorldChunk
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
public interface IWorldChunk
- Extension Methods
Properties
BlockEntities
An array holding block Entities currently residing in this chunk. This array may be larger than the amount of block entities in the chunk.
Dictionary<BlockPos, BlockEntity> BlockEntities { get; set; }
Property Value
Blocks
Use Data instead
[Obsolete("Use Data field")]
IChunkBlocks Blocks { get; }
Property Value
Data
Holds all the blockids for each coordinate, access via index: (y * chunksize + z) * chunksize + x
IChunkBlocks Data { get; }
Property Value
Disposed
Whether this chunk got unloaded
bool Disposed { get; }
Property Value
Empty
bool Empty { get; set; }
Property Value
Entities
An array holding all Entities currently residing in this chunk. This array may be larger than the amount of entities in the chunk.
Entity[] Entities { get; }
Property Value
- Entity[]
EntitiesCount
Actual count of entities in this chunk
int EntitiesCount { get; }
Property Value
LightPositions
Returns a list of a in-chunk indexed positions of all light sources in this chunk
HashSet<int> LightPositions { get; set; }
Property Value
Lighting
Holds all the lighting data for each coordinate, access via index: (y * chunksize + z) * chunksize + x
IChunkLight Lighting { get; }
Property Value
LiveModData
Can be used to store non-serialized mod data that is only serialized into the standard moddata dictionary on unload. This prevents the need for constant serializing/deserializing. Useful when storing large amounts of data. Is not populated on chunk load, you need to populate it with stored data yourself using GetModData()
Dictionary<string, object> LiveModData { get; set; }
Property Value
MapChunk
Holds a reference to the current map data of this chunk column
IMapChunk MapChunk { get; }
Property Value
MaybeBlocks
Faster (non-blocking) access to blocks at the cost of sometimes returning 0 instead of the real block. Use Data if you need reliable block access. Also should only be used for reading. Currently used for the particle system.
IChunkBlocks MaybeBlocks { get; }
Property Value
Methods
AcquireBlockReadLock()
For bulk chunk GetBlock operations, allows the chunkDataLayers to be pre-locked for reading, instead of entering and releasing one lock per read
Best used mainly on the server side unless you know what you are doing. The client-side Chunk Tesselator can need read-access to a chunk at any time so making heavy use of this would cause rendering delays on the client
Make sure always to call ReleaseBulkReadLock() when finished. Use a try/finally block if necessary, and complete all read operations within 8 seconds
void AcquireBlockReadLock()
AddEntity(Entity)
Adds an entity to the chunk.
void AddEntity(Entity entity)
Parameters
entity
EntityThe entity to add.
AdjustSelectionBoxForDecor(IBlockAccessor, BlockPos, Cuboidf[])
Adds extra selection boxes in case a decor block is attached at given position
Cuboidf[] AdjustSelectionBoxForDecor(IBlockAccessor blockAccessor, BlockPos pos, Cuboidf[] orig)
Parameters
blockAccessor
IBlockAccessorpos
BlockPosorig
Cuboidf[]
Returns
- Cuboidf[]
BreakAllDecorFast(IWorldAccessor, BlockPos, int, bool)
Removes a decor block from given position, saves a few cpu cycles by not calculating index3d
void BreakAllDecorFast(IWorldAccessor world, BlockPos pos, int index3d, bool callOnBrokenAsDecor = true)
Parameters
world
IWorldAccessorpos
BlockPosindex3d
intcallOnBrokenAsDecor
boolWhen set to true it will call block.OnBrokenAsDecor(...) which is used to drop the decors of that block
BreakDecor(IWorldAccessor, BlockPos, BlockFacing, int?)
If allowed by a player action, removes all decors at given position and calls OnBrokenAsDecor() on all selected decors and drops the items that are returned from Block.GetDrops()
bool BreakDecor(IWorldAccessor world, BlockPos pos, BlockFacing side = null, int? decorIndex = null)
Parameters
world
IWorldAccessorpos
BlockPosside
BlockFacingIf null, all the decor blocks on all sides are removed
decorIndex
int?If not null breaks only this part of the decor for give face. Requires side to be set.
Returns
FinishLightDoubleBuffering()
Only to be implemented client side
void FinishLightDoubleBuffering()
GetDecor(IBlockAccessor, BlockPos, int)
Block GetDecor(IBlockAccessor blockAccessor, BlockPos pos, int decorIndex)
Parameters
blockAccessor
IBlockAccessorpos
BlockPosdecorIndex
int
Returns
GetDecors(IBlockAccessor, BlockPos)
Block[] GetDecors(IBlockAccessor blockAccessor, BlockPos pos)
Parameters
blockAccessor
IBlockAccessorpos
BlockPos
Returns
- Block[]
GetLightAbsorptionAt(int, BlockPos, IList<Block>)
Returns the higher light absorption between solids and fluids block layers
int GetLightAbsorptionAt(int index3d, BlockPos blockPos, IList<Block> blockTypes)
Parameters
Returns
GetLocalBlockAtBlockPos(IWorldAccessor, int, int, int, int)
Block GetLocalBlockAtBlockPos(IWorldAccessor world, int posX, int posY, int posZ, int layer)
Parameters
world
IWorldAccessorposX
intposY
intposZ
intlayer
int
Returns
GetLocalBlockAtBlockPos(IWorldAccessor, BlockPos)
Retrieve a block from this chunk ignoring ice/water layer, performs Unpack() and a modulo operation on the position arg to get a local position in the 0..chunksize range (it's your job to pick out the right chunk before calling this method)
Block GetLocalBlockAtBlockPos(IWorldAccessor world, BlockPos position)
Parameters
world
IWorldAccessorposition
BlockPos
Returns
GetLocalBlockAtBlockPos_LockFree(IWorldAccessor, BlockPos, int)
As GetLocalBlockAtBlockPos except lock-free, use it inside paired LockForReading(true/false) calls
Block GetLocalBlockAtBlockPos_LockFree(IWorldAccessor world, BlockPos position, int layer = 0)
Parameters
world
IWorldAccessorposition
BlockPoslayer
int
Returns
GetLocalBlockEntityAtBlockPos(BlockPos)
Retrieve a block entity from this chunk
BlockEntity GetLocalBlockEntityAtBlockPos(BlockPos pos)
Parameters
pos
BlockPos
Returns
GetModdata(string)
Retrieve arbitrary, permantly stored mod data
byte[] GetModdata(string key)
Parameters
key
string
Returns
- byte[]
GetModdata<T>(string, T)
Retrieve arbitrary, permantly stored mod data
T GetModdata<T>(string key, T defaultValue = default)
Parameters
key
stringdefaultValue
T
Returns
- T
Type Parameters
T
GetSubDecors(IBlockAccessor, BlockPos)
Dictionary<int, Block> GetSubDecors(IBlockAccessor blockAccessor, BlockPos position)
Parameters
blockAccessor
IBlockAccessorposition
BlockPos
Returns
MarkFresh()
Marks this chunk as recently accessed. This will prevent the chunk from getting compressed by the in-memory chunk compression algorithm
void MarkFresh()
MarkModified()
Marks this chunk as modified. If called on server side it will be stored to disk on the next autosave or during shutdown, if called on client not much happens (but it will be preserved from packing for next ~8 seconds)
void MarkModified()
ReleaseBlockReadLock()
For bulk chunk GetBlock operations, allows the chunkDataLayers to be pre-locked for reading, instead of entering and releasing one lock per read
Make sure always to call ReleaseBulkReadLock() when finished. Use a try/finally block if necessary, and complete all read operations within 8 seconds
void ReleaseBlockReadLock()
RemoveEntity(long)
Removes an entity from the chunk.
bool RemoveEntity(long entityId)
Parameters
entityId
longthe ID for the entity
Returns
- bool
Whether or not the entity was removed.
RemoveModdata(string)
Removes the permanently stored data.
void RemoveModdata(string key)
Parameters
key
string
SetDecor(Block, int, int)
Sets a decor block to a specific sub-position on the side of an existing block. Use air block (id 0) to remove a decor.
bool SetDecor(Block block, int index3d, int faceAndSubposition)
Parameters
Returns
- bool
False if there already exists a block in this position and facing
SetDecor(Block, int, BlockFacing)
Sets a decor block to the side of an existing block. Use air block (id 0) to remove a decor.
bool SetDecor(Block block, int index3d, BlockFacing onFace)
Parameters
block
Blockindex3d
intonFace
BlockFacing
Returns
- bool
False if there already exists a block in this position and facing
SetDecors(Dictionary<int, Block>)
Set entire Decors for a chunk - used in Server->Client updates
void SetDecors(Dictionary<int, Block> newDecors)
Parameters
newDecors
Dictionary<int, Block>
SetModdata(string, byte[])
Allows setting of arbitrary, permanantly stored moddata of this chunk. When set on the server before the chunk is sent to the client, the data will also be sent to the client. When set on the client the data is discarded once the chunk gets unloaded
void SetModdata(string key, byte[] data)
Parameters
SetModdata<T>(string, T)
Allows setting of arbitrary, permanantly stored moddata of this chunk. When set on the server before the chunk is sent to the client, the data will also be sent to the client. When set on the client the data is discarded once the chunk gets unloaded
void SetModdata<T>(string key, T data)
Parameters
key
stringdata
T
Type Parameters
T
Unpack()
Blockdata and Light might be compressed, always call this method if you want to access these
void Unpack()
UnpackAndReadBlock(int, int)
Like Unpack_ReadOnly(), except it actually reads and returns the block ID at index
(Returns 0 if the chunk was disposed)
int UnpackAndReadBlock(int index, int layer)
Parameters
Returns
Unpack_AndReadLight(int)
Like Unpack_ReadOnly(), except it actually reads and returns the Light at index
(Returns 0 if the chunk was disposed)
ushort Unpack_AndReadLight(int index)
Parameters
index
int
Returns
Unpack_AndReadLight(int, out int)
A version of Unpack_AndReadLight which also returns the lightSat
(Returns 0 if the chunk was disposed)
ushort Unpack_AndReadLight(int index, out int lightSat)
Parameters
Returns
Unpack_ReadOnly()
Like Unpack(), except it must be used readonly: the calling code promises not to write any changes to this chunk's blocks or lighting
bool Unpack_ReadOnly()