Class Chunk
- All Implemented Interfaces:
Block.Getter,Block.Setter,Snapshotable,Taggable,TagReadable,TagWritable,Tickable,Viewable,Biome.Getter,Biome.Setter
- Direct Known Subclasses:
DynamicChunk
Instance, limited by a size of 16x256x16 blocks and subdivided in 16 sections of 16 blocks height.
Should contain all the blocks located at those positions and manage their tick updates.
Be aware that implementations do not need to be thread-safe, all chunks are guarded by their own instance ('this').
You can create your own implementation of this class by extending it
and create the objects in InstanceContainer.setChunkSupplier(ChunkSupplier).
You generally want to avoid storing references of this object as this could lead to a huge memory leak, you should store the chunk coordinates instead.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minestom.server.instance.block.Block.Getter
Block.Getter.Condition -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intprotected final intprotected final intprotected PFColumnarSpaceprotected Instanceprotected booleanprotected final intprotected final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a viewer.abstract @NotNull ChunkCreates a copy of this chunk, including blocks state id, custom block id, biomes, update data.intGets the chunk X.intGets the chunk Z.abstract @NotNull SendablePacket@NotNull UUIDGets the unique identifier of this chunk.@NotNull InstanceGets the instance where this chunk is storedabstract longGets the last time that this chunk changed.intGets the highest (exclusive) section Y available in this chunkintGets the lowest (inclusive) section Y available in this chunkabstract @NotNull SectiongetSection(int section) @NotNull SectiongetSectionAt(int blockY) Gets all the viewers of this viewable element.abstract voidInvalidate the chunk cachesbooleanisLoaded()Used to verify if the chunk should still be kept in memory.booleanGets if this chunk is read-only.abstract voidloadHeightmapsFromNBT(org.jglrxavpok.hephaistos.nbt.NBTCompound heightmaps) abstract @NotNull HeightmapvoidCalled when the chunk generator has finished generating the chunk.protected voidonLoad()Called when the chunk has been successfully loaded.booleanremoveViewer(@NotNull Player player) Removes a viewer.abstract voidreset()Resets the chunk, this means clearing all the data making it empty.voidvoidSends the chunk data toplayer.voidSets a block at a position.protected abstract voidsetBlock(int x, int y, int z, @NotNull Block block, BlockHandler.Placement placement, BlockHandler.Destroy destroy) voidsetColumnarSpace(PFColumnarSpace columnarSpace) Changes this chunk columnar space.voidsetReadOnly(boolean readOnly) Changes the read state of the chunk.booleanGets if this chunk will or had been loaded with aChunkGenerator.@NotNull TagHandlerabstract voidtick(long time) Executes a chunk tick.@NotNull PointGets the world position of this chunk.toString()protected voidunload()Sets the chunk as "unloaded".abstract @NotNull HeightmapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minestom.server.world.biomes.Biome.Getter
getBiome, getBiomeMethods inherited from interface net.minestom.server.world.biomes.Biome.Setter
setBiome, setBiomeMethods inherited from interface net.minestom.server.instance.block.Block.Getter
getBlock, getBlock, getBlock, getBlockMethods inherited from interface net.minestom.server.instance.block.Block.Setter
setBlockMethods inherited from interface net.minestom.server.snapshot.Snapshotable
updateSnapshotMethods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Field Details
-
CHUNK_SIZE_X
public static final int CHUNK_SIZE_X- See Also:
-
CHUNK_SIZE_Z
public static final int CHUNK_SIZE_Z- See Also:
-
CHUNK_SECTION_SIZE
public static final int CHUNK_SECTION_SIZE- See Also:
-
instance
-
chunkX
protected final int chunkX -
chunkZ
protected final int chunkZ -
minSection
protected final int minSection -
maxSection
protected final int maxSection -
loaded
protected volatile boolean loaded -
columnarSpace
-
-
Constructor Details
-
Chunk
-
-
Method Details
-
setBlock
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
batches) The thread-safe version isInstance.setBlock(int, int, int, Block)(or any similar instance methods) Otherwise, you can simply do not forget to have this chunk synchronized when this is called.- Specified by:
setBlockin interfaceBlock.Setter- Parameters:
x- the block Xy- the block Yz- the block Zblock- the block to place
-
setBlock
protected abstract void setBlock(int x, int y, int z, @NotNull @NotNull Block block, @Nullable BlockHandler.Placement placement, @Nullable BlockHandler.Destroy destroy) -
getSections
-
getSection
-
motionBlockingHeightmap
-
worldSurfaceHeightmap
-
loadHeightmapsFromNBT
public abstract void loadHeightmapsFromNBT(org.jglrxavpok.hephaistos.nbt.NBTCompound heightmaps) -
getSectionAt
-
tick
public abstract void tick(long time) 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.
-
getLastChangeTime
public abstract long getLastChangeTime()Gets the last time that this chunk changed."Change" means here data used in
ChunkDataPacket. It is necessary to see if the cached version of this chunk can be used instead of re-writing and compressing everything.- Returns:
- the last change time in milliseconds
-
sendChunk
Sends the chunk data toplayer.- Parameters:
player- the player
-
sendChunk
public void sendChunk() -
getFullDataPacket
-
copy
@NotNull public abstract @NotNull Chunk copy(@NotNull @NotNull Instance instance, int chunkX, int chunkZ) Creates a copy of this chunk, including blocks state id, custom block id, biomes, update data.The chunk position (X/Z) can be modified using the given arguments.
- Parameters:
instance- the chunk ownerchunkX- the chunk X of the copychunkZ- the chunk Z of the copy- Returns:
- a copy of this chunk with a potentially new instance and position
-
reset
public abstract void reset()Resets the chunk, this means clearing all the data making it empty. -
getIdentifier
Gets the unique identifier of this chunk.WARNING: this UUID is not persistent but randomized once the object is instantiated.
- Returns:
- the chunk identifier
-
getInstance
Gets the instance where this chunk is stored- Returns:
- the linked instance
-
getChunkX
public int getChunkX()Gets the chunk X.- Returns:
- the chunk X
-
getChunkZ
public int getChunkZ()Gets the chunk Z.- Returns:
- the chunk Z
-
getMinSection
public int getMinSection()Gets the lowest (inclusive) section Y available in this chunk- Returns:
- the lowest (inclusive) section Y available in this chunk
-
getMaxSection
public int getMaxSection()Gets the highest (exclusive) section Y available in this chunk- Returns:
- the highest (exclusive) section Y available in this chunk
-
toPosition
Gets the world position of this chunk.- Returns:
- the position of this chunk
-
shouldGenerate
public boolean shouldGenerate()Gets if this chunk will or had been loaded with aChunkGenerator.If false, the chunk will be entirely empty when loaded.
- Returns:
- true if this chunk is affected by a
ChunkGenerator
-
isReadOnly
public boolean isReadOnly()Gets if this chunk is read-only.Being read-only should prevent block placing/breaking and setting block from an
Instance. It does not affectIChunkLoaderandChunkGenerator.- Returns:
- true if the chunk is read-only
-
setReadOnly
public void setReadOnly(boolean readOnly) Changes the read state of the chunk.Being read-only should prevent block placing/breaking and setting block from an
Instance. It does not affectIChunkLoaderandChunkGenerator.- Parameters:
readOnly- true to make the chunk read-only, false otherwise
-
setColumnarSpace
Changes this chunk columnar space.- Parameters:
columnarSpace- the new columnar space
-
isLoaded
public boolean isLoaded()Used to verify if the chunk should still be kept in memory.- Returns:
- true if the chunk is loaded
-
onLoad
protected void onLoad()Called when the chunk has been successfully loaded. -
onGenerate
public void onGenerate()Called when the chunk generator has finished generating the chunk. -
toString
-
addViewer
Description copied from interface:ViewableAdds a viewer. -
removeViewer
Description copied from interface:ViewableRemoves a viewer.- Specified by:
removeViewerin interfaceViewable- Parameters:
player- the viewer to remove- Returns:
- true if the player has been removed, false otherwise (could be because he was not a viewer)
-
getViewers
Description copied from interface:ViewableGets all the viewers of this viewable element.- Specified by:
getViewersin interfaceViewable- Returns:
- A Set containing all the element's viewers
-
tagHandler
- Specified by:
tagHandlerin interfaceTaggable
-
unload
protected void unload()Sets the chunk as "unloaded". -
invalidate
public abstract void invalidate()Invalidate the chunk caches
-