Class DynamicChunk
- All Implemented Interfaces:
DataContainer
,Viewable
public class DynamicChunk extends Chunk
Chunk
which store each individual block in memory.-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<java.lang.Integer>
blockEntities
protected PaletteStorage
blockPalette
protected it.unimi.dsi.fastutil.ints.Int2ObjectMap<Data>
blocksData
protected PaletteStorage
customBlockPalette
protected it.unimi.dsi.fastutil.ints.IntSet
updatableBlocks
protected it.unimi.dsi.fastutil.ints.Int2LongMap
updatableBlocksLastUpdate
Fields inherited from class net.minestom.server.instance.Chunk
BIOME_COUNT, BIOME_MANAGER, biomes, BLOCK_MANAGER, CHUNK_SECTION_COUNT, CHUNK_SECTION_SIZE, CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z, chunkX, chunkZ, columnarSpace, data, loaded, viewers
-
Constructor Summary
Constructors Constructor Description DynamicChunk(Biome[] biomes, int chunkX, int chunkZ)
DynamicChunk(Biome[] biomes, int chunkX, int chunkZ, PaletteStorage blockPalette, PaletteStorage customBlockPalette)
-
Method Summary
Modifier and Type Method Description Chunk
copy(int chunkX, int chunkZ)
Creates a copy of this chunk, including blocks state id, custom block id, biomes, update data.protected ChunkDataPacket
createFreshPacket()
Creates aChunkDataPacket
with this chunk data ready to be written.Data
getBlockData(int index)
Gets theData
at a block index.java.util.Set<java.lang.Integer>
getBlockEntities()
Gets all the block entities in this chunk.short
getBlockStateId(int x, int y, int z)
Gets the block state id at a position.short
getCustomBlockId(int x, int y, int z)
Gets the custom block id at a position.byte[]
getSerializedData()
Serialize thisChunk
based onreadChunk(BinaryReader, ChunkCallback)
void
readChunk(BinaryReader reader, ChunkCallback callback)
Reads the chunk from binary.protected void
refreshBlockStateId(int x, int y, int z, short blockStateId)
Changes the block state id at a position (the custom block id stays the same).protected void
refreshBlockValue(int x, int y, int z, short blockStateId, short customBlockId)
Changes the block state id and the custom block id at a position.void
setBlockData(int x, int y, int z, Data data)
Sets theData
at a position.void
tick(long time, Instance instance)
Executes a chunk tick.void
UNSAFE_setBlock(int x, int y, int z, short blockStateId, short customBlockId, Data data, boolean updatable)
Sets a block at a position.Methods inherited from class net.minestom.server.instance.Chunk
addViewer, createChunkSectionUpdatePacket, getBiomes, getBlockIndex, getChunkX, getChunkZ, getCustomBlock, getCustomBlock, getData, getFreshFullDataPacket, getFreshPartialDataPacket, getViewers, isBlockEntity, isLoaded, isReadOnly, removeViewer, sendChunk, sendChunkSectionUpdate, sendChunkUpdate, sendChunkUpdate, setColumnarSpace, setData, setReadOnly, shouldGenerate, toPosition, toString, unload
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.minestom.server.Viewable
isViewer, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Field Details
-
blockPalette
-
customBlockPalette
-
blocksData
-
updatableBlocks
protected final it.unimi.dsi.fastutil.ints.IntSet updatableBlocks -
updatableBlocksLastUpdate
protected final it.unimi.dsi.fastutil.ints.Int2LongMap updatableBlocksLastUpdate -
blockEntities
protected final java.util.Set<java.lang.Integer> blockEntities
-
-
Constructor Details
-
DynamicChunk
public DynamicChunk(@Nullable Biome[] biomes, int chunkX, int chunkZ, @NotNull PaletteStorage blockPalette, @NotNull PaletteStorage customBlockPalette) -
DynamicChunk
-
-
Method Details
-
UNSAFE_setBlock
public void UNSAFE_setBlock(int x, int y, int z, short blockStateId, short customBlockId, Data data, boolean updatable)Description copied from class:Chunk
Sets a block at a position.This is used when the previous block has to be destroyed/replaced, meaning that it clears the previous data and update method.
WARNING: this method is not thread-safe (in order to bring performance improvement with
ChunkBatch
andBlockBatch
) The thread-safe version isInstanceContainer.setSeparateBlocks(int, int, int, short, short, Data)
(or any similar instance methods) Otherwise, you can simply do not forget to have this chunk synchronized when this is called.- Specified by:
UNSAFE_setBlock
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block ZblockStateId
- the block state idcustomBlockId
- the custom block id, 0 if notdata
- theData
of the block, can be nullupdatable
- true if the block has an update method Warning:customBlockId
cannot be 0 in this case and needs to be valid since the update delay and method will be retrieved from the associatedCustomBlock
object
-
tick
Description copied from class:Chunk
Executes a chunk tick.Should be used to update all the blocks in the chunk.
WARNING: this method doesn't necessary have to be thread-safe, proceed with caution.
-
getBlockStateId
public short getBlockStateId(int x, int y, int z)Description copied from class:Chunk
Gets the block state id at a position.- Specified by:
getBlockStateId
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block Z- Returns:
- the block state id at the position
-
getCustomBlockId
public short getCustomBlockId(int x, int y, int z)Description copied from class:Chunk
Gets the custom block id at a position.- Specified by:
getCustomBlockId
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block Z- Returns:
- the custom block id at the position
-
refreshBlockValue
protected void refreshBlockValue(int x, int y, int z, short blockStateId, short customBlockId)Description copied from class:Chunk
Changes the block state id and the custom block id at a position.- Specified by:
refreshBlockValue
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block ZblockStateId
- the new block state idcustomBlockId
- the new custom block id
-
refreshBlockStateId
protected void refreshBlockStateId(int x, int y, int z, short blockStateId)Description copied from class:Chunk
Changes the block state id at a position (the custom block id stays the same).- Specified by:
refreshBlockStateId
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block ZblockStateId
- the new block state id
-
getBlockData
Description copied from class:Chunk
Gets theData
at a block index.- Specified by:
getBlockData
in classChunk
- Parameters:
index
- the block index- Returns:
- the
Data
at the block index, null if none
-
setBlockData
Description copied from class:Chunk
Sets theData
at a position.- Specified by:
setBlockData
in classChunk
- Parameters:
x
- the block Xy
- the block Yz
- the block Zdata
- the new data, can be null
-
getBlockEntities
@NotNull public java.util.Set<java.lang.Integer> getBlockEntities()Description copied from class:Chunk
Gets all the block entities in this chunk.- Specified by:
getBlockEntities
in classChunk
- Returns:
- the block entities in this chunk
-
getSerializedData
public byte[] getSerializedData()Serialize thisChunk
based onreadChunk(BinaryReader, ChunkCallback)
It is also used by the default
IChunkLoader
which isMinestomBasicChunkLoader
- Specified by:
getSerializedData
in classChunk
- Returns:
- the serialized chunk data
- See Also:
which should be able to read what is written in this method
-
readChunk
Description copied from class:Chunk
Reads the chunk from binary.Used if the chunk is loaded from file.
- Specified by:
readChunk
in classChunk
- Parameters:
reader
- the data reader WARNING: the data will not necessary be read directly in the same thread, be sure that the data is only used for this reading.callback
- the optional callback to execute once the chunk is done reading WARNING: this need to be called to notify the instance.- See Also:
which is responsible for the serialized data given
-
createFreshPacket
Description copied from class:Chunk
Creates aChunkDataPacket
with this chunk data ready to be written.- Specified by:
createFreshPacket
in classChunk
- Returns:
- a new chunk data packet
-
copy
Description copied from class:Chunk
Creates a copy of this chunk, including blocks state id, custom block id, biomes, update data.The instance and chunk position (X/Z) can be modified using the given arguments.
-