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
Direct Known Subclasses:
LightingChunk

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

WARNING: not thread-safe.

  • Field Details

    • sections

      protected List<Section> sections
    • motionBlocking

      protected Heightmap motionBlocking
    • worldSurface

      protected Heightmap worldSurface
    • 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, @Nullable BlockHandler.Placement placement, @Nullable BlockHandler.Destroy destroy)
      Specified by:
      setBlock in class Chunk
    • 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
    • motionBlockingHeightmap

      @NotNull public @NotNull Heightmap motionBlockingHeightmap()
      Specified by:
      motionBlockingHeightmap in class Chunk
    • worldSurfaceHeightmap

      @NotNull public @NotNull Heightmap worldSurfaceHeightmap()
      Specified by:
      worldSurfaceHeightmap in class Chunk
    • loadHeightmapsFromNBT

      public void loadHeightmapsFromNBT(org.jglrxavpok.hephaistos.nbt.NBTCompound heightmapsNBT)
      Specified by:
      loadHeightmapsFromNBT 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
    • getFullDataPacket

      @NotNull public @NotNull SendablePacket getFullDataPacket()
      Specified by:
      getFullDataPacket 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
    • invalidate

      public void invalidate()
      Description copied from class: Chunk
      Invalidate the chunk caches
      Specified by:
      invalidate in class Chunk
    • createLightData

      protected LightData createLightData()
    • 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