Class DynamicChunk

java.lang.Object
net.minestom.server.instance.Chunk
net.minestom.server.instance.DynamicChunk
All Implemented Interfaces:
DataContainer, Viewable

public class DynamicChunk
extends Chunk
Represents a Chunk which store each individual block in memory.
  • Field Details

  • Constructor Details

  • 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 and BlockBatch) The thread-safe version is InstanceContainer.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 class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      blockStateId - the block state id
      customBlockId - the custom block id, 0 if not
      data - the Data of the block, can be null
      updatable - 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 associated CustomBlock object
    • tick

      public void tick​(long time, @NotNull Instance instance)
      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.

      Specified by:
      tick in class Chunk
      Parameters:
      time - the time of the update in milliseconds
      instance - the Instance linked to this chunk
    • 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 class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - 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 class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - 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 class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      blockStateId - the new block state id
      customBlockId - 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 class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      blockStateId - the new block state id
    • getBlockData

      public Data getBlockData​(int index)
      Description copied from class: Chunk
      Gets the Data at a block index.
      Specified by:
      getBlockData in class Chunk
      Parameters:
      index - the block index
      Returns:
      the Data at the block index, null if none
    • setBlockData

      public void setBlockData​(int x, int y, int z, Data data)
      Description copied from class: Chunk
      Sets the Data at a position.
      Specified by:
      setBlockData in class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      data - 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 class Chunk
      Returns:
      the block entities in this chunk
    • getSerializedData

      public byte[] getSerializedData()
      Serialize this Chunk based on readChunk(BinaryReader, ChunkCallback)

      It is also used by the default IChunkLoader which is MinestomBasicChunkLoader

      Specified by:
      getSerializedData in class Chunk
      Returns:
      the serialized chunk data
      See Also:
      which should be able to read what is written in this method
    • readChunk

      public void readChunk​(@NotNull BinaryReader reader, ChunkCallback callback)
      Description copied from class: Chunk
      Reads the chunk from binary.

      Used if the chunk is loaded from file.

      Specified by:
      readChunk in class Chunk
      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

      @NotNull protected ChunkDataPacket createFreshPacket()
      Description copied from class: Chunk
      Creates a ChunkDataPacket with this chunk data ready to be written.
      Specified by:
      createFreshPacket in class Chunk
      Returns:
      a new chunk data packet
    • copy

      @NotNull public Chunk copy​(int chunkX, int chunkZ)
      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.

      Specified by:
      copy in class Chunk
      Parameters:
      chunkX - the new chunk X
      chunkZ - the new chunk Z
      Returns:
      a copy of this chunk with a potentially new instance and position