Class DynamicChunk

java.lang.Object
net.minestom.server.instance.Chunk
net.minestom.server.instance.DynamicChunk
All Implemented Interfaces:
Block.Getter, Block.Setter, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Viewable, Biome.Getter, Biome.Setter

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

WARNING: not thread-safe.

  • Field Details

    • entries

      protected final it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<Block> entries
    • tickableMap

      protected final it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<Block> tickableMap
  • Constructor Details

    • DynamicChunk

      public DynamicChunk(@NotNull @NotNull Instance instance, int chunkX, int chunkZ)
  • Method Details

    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull Block block)
      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 batches) The thread-safe version is Block.Setter.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:
      setBlock in interface Block.Setter
      Specified by:
      setBlock in class Chunk
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      block - the block to place
    • setBiome

      public void setBiome(int x, int y, int z, @NotNull @NotNull Biome biome)
    • getSections

      @NotNull public @NotNull List<Section> getSections()
      Specified by:
      getSections in class Chunk
    • getSection

      @NotNull public @NotNull Section getSection(int section)
      Specified by:
      getSection in class Chunk
    • tick

      public void tick(long time)
      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 interface Tickable
      Specified by:
      tick in class Chunk
      Parameters:
      time - the time of the update in milliseconds
    • getBlock

      @Nullable public @Nullable Block getBlock(int x, int y, int z, @NotNull @NotNull Block.Getter.Condition condition)
    • getBiome

      @NotNull public @NotNull Biome getBiome(int x, int y, int z)
    • getLastChangeTime

      public long getLastChangeTime()
      Description copied from class: Chunk
      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.

      Specified by:
      getLastChangeTime in class Chunk
      Returns:
      the last change time in milliseconds
    • sendChunk

      public void sendChunk(@NotNull @NotNull Player player)
      Description copied from class: Chunk
      Sends the chunk data to player.
      Specified by:
      sendChunk in class Chunk
      Parameters:
      player - the player
    • sendChunk

      public void sendChunk()
      Specified by:
      sendChunk in class Chunk
    • copy

      @NotNull public @NotNull Chunk copy(@NotNull @NotNull Instance instance, 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 chunk position (X/Z) can be modified using the given arguments.

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

      public void reset()
      Description copied from class: Chunk
      Resets the chunk, this means clearing all the data making it empty.
      Specified by:
      reset in class Chunk
    • updateSnapshot

      @NotNull public @NotNull ChunkSnapshot updateSnapshot(@NotNull @NotNull SnapshotUpdater updater)
      Description copied from interface: Snapshotable
      Updates the currently cached snapshot if required. The updater can be used to retrieve references to other snapshots while avoiding circular dependency. Be careful to do not store updater anywhere as its data will change when building requested references.

      This method is not thread-safe, and targeted at internal use since its execution rely on safe-points (e.g. end of ticks)

      Parameters:
      updater - the snapshot updater/context
      Returns:
      the updated snapshot