Class ChunkHolder<T extends Future<T>>

java.lang.Object
com.fastasyncworldedit.core.queue.implementation.chunk.ChunkHolder<T>
All Implemented Interfaces:
IBlocks, IChunk, IChunkGet, IChunkSet, IQueueChunk<T>, ITileInput, Trimable, InputExtent, OutputExtent, Callable<T>

public class ChunkHolder<T extends Future<T>> extends Object implements IQueueChunk<T>
An abstract IChunk class that implements basic get/set blocks.
  • Method Details

    • newInstance

      public static ChunkHolder newInstance()
    • init

      public void init(ChunkHolder.IBlockDelegate delegate)
    • recycle

      public void recycle()
      Specified by:
      recycle in interface Trimable
    • initAge

      public long initAge()
    • getDelegate

      public ChunkHolder.IBlockDelegate getDelegate()
    • entity

      public void entity(FaweCompoundTag tag)
      Specified by:
      entity in interface IChunkSet
    • removeEntity

      public void removeEntity(UUID uuid)
      Specified by:
      removeEntity in interface IChunkSet
    • getEntityRemoves

      public Set<UUID> getEntityRemoves()
      Specified by:
      getEntityRemoves in interface IChunkSet
    • getBiomes

      public BiomeType[][] getBiomes()
      Description copied from interface: IChunkSet
      This will return only biomes SET to the EXTENT or QUEUE. This will NOT return the current biomes in the world. This is used for history purposes.
      Specified by:
      getBiomes in interface IChunkSet
      Returns:
      Array of biomes set
    • getLight

      public char[][] getLight()
      Specified by:
      getLight in interface IChunkSet
    • getSkyLight

      public char[][] getSkyLight()
      Specified by:
      getSkyLight in interface IChunkSet
    • setBlocks

      public void setBlocks(int layer, char[] data)
      Specified by:
      setBlocks in interface IChunkSet
    • load

      public char[] load(int layer)
      Description copied from interface: IBlocks
      Obtain the specified chunk section stored as an array of ordinals. Uses normal minecraft chunk-section position indices (length 4096). Operations synchronises on the section and will load the section into memory if not present. For chunk GET operations, this will load the data from the world. For chunk SET, this will create a new empty array.
      Specified by:
      load in interface IBlocks
      Parameters:
      layer - chunk section layer (may be negative)
      Returns:
      char array of ordinals of the chunk section
    • loadIfPresent

      @Nullable public char[] loadIfPresent(int layer)
      Description copied from interface: IBlocks
      Obtain the specified chunk section stored as an array of ordinals if present or null. Uses normal minecraft chunk-section position indices (length 4096). Does not synchronise to the section layer as it will not attempt to load into memory.
      Specified by:
      loadIfPresent in interface IBlocks
      Parameters:
      layer - chunk section layer (may be negative)
      Returns:
      char array of ordinals of the chunk section if present
    • isFastMode

      public boolean isFastMode()
      Specified by:
      isFastMode in interface IChunkSet
    • setFastMode

      public void setFastMode(boolean fastmode)
      Specified by:
      setFastMode in interface IChunkSet
    • setBitMask

      public void setBitMask(int bitMask)
      Specified by:
      setBitMask in interface IChunkSet
    • getBitMask

      public int getBitMask()
      Specified by:
      getBitMask in interface IBlocks
      Specified by:
      getBitMask in interface IChunkSet
    • hasBiomes

      public boolean hasBiomes(int layer)
      Description copied from interface: IChunkSet
      If the given layer has biomes stored to be set to the world. Can be negative
      Specified by:
      hasBiomes in interface IChunkSet
      Parameters:
      layer - layer to check
      Returns:
      if the layer has biomes stored to be set to the world
    • setSideEffectSet

      public void setSideEffectSet(SideEffectSet sideEffectSet)
      Description copied from interface: IChunkSet
      Set the side effects to be used when settings these blocks
      Specified by:
      setSideEffectSet in interface IChunkSet
    • getSideEffectSet

      public SideEffectSet getSideEffectSet()
      Description copied from interface: IChunkSet
      Get the side effects to be used when settings these blocks
      Specified by:
      getSideEffectSet in interface IChunkSet
    • isInit

      public boolean isInit()
    • setCreateCopy

      public int setCreateCopy(boolean createCopy)
      Description copied from interface: IChunkGet
      Not for external API use. Internal use only.
      Specified by:
      setCreateCopy in interface IChunkGet
    • isCreateCopy

      public boolean isCreateCopy()
      Specified by:
      isCreateCopy in interface IChunkGet
    • setLightingToGet

      public void setLightingToGet(char[][] lighting, int minSectionPosition, int maxSectionPosition)
      Description copied from interface: IChunkGet
      Flush the block lighting array (section*blocks) to the chunk GET between the given section indices. Negative allowed.
      Specified by:
      setLightingToGet in interface IChunkGet
      Parameters:
      lighting - lighting array
      minSectionPosition - lowest section index
      maxSectionPosition - highest section index
    • setSkyLightingToGet

      public void setSkyLightingToGet(char[][] lighting, int minSectionPosition, int maxSectionPosition)
      Description copied from interface: IChunkGet
      Flush the sky lighting array (section*blocks) to the chunk GET between the given section indices. Negative allowed.
      Specified by:
      setSkyLightingToGet in interface IChunkGet
      Parameters:
      lighting - sky lighting array
      minSectionPosition - lowest section index
      maxSectionPosition - highest section index
    • setHeightmapToGet

      public void setHeightmapToGet(HeightMapType type, int[] data)
      Specified by:
      setHeightmapToGet in interface IChunkGet
    • getMaxY

      public int getMaxY()
      Description copied from interface: IChunkGet
      Max y value for the chunk's world (inclusive)
      Specified by:
      getMaxY in interface IChunkGet
    • getMinY

      public int getMinY()
      Description copied from interface: IChunkGet
      Min y value for the chunk's world (inclusive)
      Specified by:
      getMinY in interface IChunkGet
    • getMaxSectionPosition

      public int getMaxSectionPosition()
      Description copied from interface: IBlocks
      Get the highest layer position stored in the internal chunk. For 1.16 and below, always returns 15. For 1.17 and above, may not return a value correct to the world if this is a IChunkSet instance, which defaults to 15. For extended height worlds, this will only return over 15 if blocks are stored outside the default range.
      Specified by:
      getMaxSectionPosition in interface IBlocks
    • getMinSectionPosition

      public int getMinSectionPosition()
      Description copied from interface: IBlocks
      Get the lowest layer position stored in the internal chunk. For 1.16 and below, always returns 0. For 1.17 and above, may not return a value correct to the world if this is a IChunkSet instance, which defaults to 0. For extended height worlds, this will only return under 0 if blocks are stored outside the default range.
      Specified by:
      getMinSectionPosition in interface IBlocks
    • flushLightToGet

      public void flushLightToGet()
    • hasSection

      public boolean hasSection(int layer)
      Description copied from interface: IBlocks
      Returns if the chunk has a BLOCKS section at the given layer. May not be indicative of presence of entities, tile entites, biomes, etc.
      Specified by:
      hasSection in interface IBlocks
      Parameters:
      layer - chunk section layer
      Returns:
      if blocks/a block section is present
    • hasNonEmptySection

      public boolean hasNonEmptySection(int layer)
      Description copied from interface: IBlocks
      Returns whether the chunk has a section that has any non-air/reserved blocks. This method might be conservative and return true even if the section is empty.
      Specified by:
      hasNonEmptySection in interface IBlocks
      Parameters:
      layer - the section's layer
      Returns:
      whether the chunk has a section that has any non-air/reserved blocks
    • filterBlocks

      public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region, boolean full)
      Description copied from interface: IChunk
      Filter through all the blocks in the chunk
      Specified by:
      filterBlocks in interface IChunk
      Parameters:
      filter - the filter
      block - The filter block
      region - The region allowed to filter (maybe null)
    • trim

      public boolean trim(boolean aggressive)
      Description copied from interface: Trimable
      Trims the object, reducing its memory footprint.
      Specified by:
      trim in interface Trimable
      Parameters:
      aggressive - if trimming should be aggressive e.g., Not returning early when the first element cannot be trimmed
      Returns:
      if this object is empty at the end of the trim, and can therefore be deleted
    • trim

      public boolean trim(boolean aggressive, int layer)
      Specified by:
      trim in interface IBlocks
    • getSectionCount

      public int getSectionCount()
      Description copied from interface: IBlocks
      Get the number of stored sections
      Specified by:
      getSectionCount in interface IBlocks
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface IChunkSet
    • tile

      public boolean tile(int x, int y, int z, FaweCompoundTag tag)
      Description copied from interface: OutputExtent
      Sets a tile/block entity at the given location.
      Specified by:
      tile in interface IChunkSet
      Specified by:
      tile in interface OutputExtent
      Parameters:
      x - the x position
      y - the y position
      z - the z position
      tag - the tile/block entity to set
      Returns:
      true if the tile/block entity was placed
    • getOrCreateGet

      public final IChunkGet getOrCreateGet()
      Get or create the existing part of this chunk.
    • getOrCreateSet

      public final IChunkSet getOrCreateSet()
      Get or create the settable part of this chunk.
    • getChunkSet

      public final IChunkSet getChunkSet()
    • init

      public <V extends IChunk> void init(IQueueExtent<V> extent, int chunkX, int chunkZ)
      Description copied from interface: IChunk
      Initialize at the location (allows for reuse) - It's expected initialization will clear any set fields
      Specified by:
      init in interface IChunk
    • call

      public T call()
      Description copied from interface: IQueueChunk
      Apply the queued changes to the world containing this chunk.

      The future returned may return another future. To ensure completion keep calling Future.get() on each result.

      Specified by:
      call in interface Callable<T extends Future<T>>
      Specified by:
      call in interface IQueueChunk<T extends Future<T>>
      Returns:
      Future
    • call

      public <U extends Future<U>> U call(IQueueExtent<? extends IChunk> owner, IChunkSet set, Runnable finalize)
      This method should never be called from outside ChunkHolder
      Specified by:
      call in interface IChunkGet
    • getExtent

      public IQueueExtent<? extends IChunk> getExtent()
      Get the extent this chunk is in.
    • getX

      public int getX()
      Description copied from interface: IChunk
      Get chunkX
      Specified by:
      getX in interface IBlocks
      Specified by:
      getX in interface IChunk
      Returns:
      the x coordinate of the chunk
    • getZ

      public int getZ()
      Description copied from interface: IChunk
      Get chunkZ
      Specified by:
      getZ in interface IBlocks
      Specified by:
      getZ in interface IChunk
      Returns:
      the z coordinate of the chunk
    • setBiome

      public boolean setBiome(int x, int y, int z, BiomeType biome)
      Specified by:
      setBiome in interface IChunkSet
      Specified by:
      setBiome in interface OutputExtent
    • setBlock

      public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
      Specified by:
      setBlock in interface IChunkSet
      Specified by:
      setBlock in interface OutputExtent
    • getBiomeType

      public BiomeType getBiomeType(int x, int y, int z)
      Specified by:
      getBiomeType in interface IBlocks
      Specified by:
      getBiomeType in interface IChunkGet
      Specified by:
      getBiomeType in interface InputExtent
    • getBlock

      public BlockState getBlock(int x, int y, int z)
      Specified by:
      getBlock in interface IBlocks
      Specified by:
      getBlock in interface IChunkGet
      Specified by:
      getBlock in interface InputExtent
    • tiles

      public Map<BlockVector3,FaweCompoundTag> tiles()
      Specified by:
      tiles in interface IBlocks
    • tile

      @Nullable public FaweCompoundTag tile(int x, int y, int z)
      Specified by:
      tile in interface IBlocks
    • entities

      public Collection<FaweCompoundTag> entities()
      Specified by:
      entities in interface IBlocks
    • getFullEntities

      public Set<Entity> getFullEntities()
      Description copied from interface: IChunkGet
      Get the entities in the chunk as "full" entities.
      Specified by:
      getFullEntities in interface IChunkGet
    • getFullBlock

      public BaseBlock getFullBlock(int x, int y, int z)
      Specified by:
      getFullBlock in interface IChunkGet
      Specified by:
      getFullBlock in interface InputExtent
    • setSkyLight

      public void setSkyLight(int x, int y, int z, int value)
      Specified by:
      setSkyLight in interface IChunkSet
      Specified by:
      setSkyLight in interface OutputExtent
    • setHeightMap

      public void setHeightMap(HeightMapType type, int[] heightMap)
      Specified by:
      setHeightMap in interface IChunkSet
      Specified by:
      setHeightMap in interface OutputExtent
    • removeSectionLighting

      public void removeSectionLighting(int layer, boolean sky)
      Specified by:
      removeSectionLighting in interface IBlocks
    • setFullBright

      public void setFullBright(int layer)
      Specified by:
      setFullBright in interface IChunkSet
    • setBlockLight

      public void setBlockLight(int x, int y, int z, int value)
      Specified by:
      setBlockLight in interface IChunkSet
      Specified by:
      setBlockLight in interface OutputExtent
    • setLightLayer

      public void setLightLayer(int layer, char[] toSet)
      Specified by:
      setLightLayer in interface IChunkSet
    • setSkyLightLayer

      public void setSkyLightLayer(int layer, char[] toSet)
      Specified by:
      setSkyLightLayer in interface IChunkSet
    • getSkyLight

      public int getSkyLight(int x, int y, int z)
      Specified by:
      getSkyLight in interface IChunkGet
      Specified by:
      getSkyLight in interface InputExtent
    • getEmittedLight

      public int getEmittedLight(int x, int y, int z)
      Specified by:
      getEmittedLight in interface IChunkGet
      Specified by:
      getEmittedLight in interface InputExtent
    • getBrightness

      public int getBrightness(int x, int y, int z)
      Specified by:
      getBrightness in interface InputExtent
    • getOpacity

      public int getOpacity(int x, int y, int z)
      Specified by:
      getOpacity in interface InputExtent
    • getHeightMap

      public int[] getHeightMap(HeightMapType type)
      Specified by:
      getHeightMap in interface IChunkGet
      Specified by:
      getHeightMap in interface InputExtent
    • entity

      @Nullable public FaweCompoundTag entity(UUID uuid)
      Description copied from interface: IChunkGet
      Returns the compound tag describing the entity with the given UUID, if any.
      Specified by:
      entity in interface IChunkGet
      Parameters:
      uuid - the uuid of the entity
      Returns:
      the compound tag describing the entity with the given UUID, if any