Class NMSWorldGenAccess

java.lang.Object
com.github.darksoulq.abyssallib.world.gen.NMSWorldGenAccess
All Implemented Interfaces:
WorldGenAccess

public class NMSWorldGenAccess extends Object implements WorldGenAccess
Implementation of WorldGenAccess backed by NMS (Native Minecraft Server).

This class provides high-performance world access during chunk generation by interacting directly with WorldGenLevel, while maintaining thread safety through the use of LimitedRegion.

It is designed specifically for use in terrain generation, structure placement, and other population phases where standard Bukkit API access is restricted.

  • Constructor Summary

    Constructors
    Constructor
    Description
    NMSWorldGenAccess(org.bukkit.generator.LimitedRegion region, org.bukkit.World world, Random random)
    Creates a new NMS-backed world generation access instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable org.bukkit.entity.Entity
    addEntity(double x, double y, double z, @NotNull SavedEntity entity)
    Spawns a SavedEntity.
    void
    addEntity(double x, double y, double z, @NotNull CustomEntity<?> entity)
    Spawns a CustomEntity at the given coordinates.
    @NotNull org.bukkit.entity.Entity
    addEntity(double x, double y, double z, @NotNull org.bukkit.entity.EntityType type)
    Spawns a vanilla entity safely within the generation region.
    @NotNull org.bukkit.block.Biome
    getBiome(int x, int y, int z)
    Gets the biome at a position.
    @NotNull org.bukkit.block.data.BlockData
    getBlockData(int x, int y, int z)
    Gets the BlockData at a position.
    @NotNull org.bukkit.block.BlockState
    getBlockState(int x, int y, int z)
    Retrieves the full BlockState using the safe LimitedRegion.
    int
    getHighestBlockY(int x, int z, org.bukkit.HeightMap heightMap)
    Gets the highest Y value at a position using a HeightMap.
    @NotNull Random
    Gets the random instance used for generation.
    @NotNull org.bukkit.Material
    getType(int x, int y, int z)
    Gets the material at a position.
    @NotNull org.bukkit.World
    Gets the Bukkit world.
    boolean
    isInRegion(int x, int y, int z)
    Checks if the given coordinate is within this generation region
    void
    setBlock(int x, int y, int z, @NotNull CustomBlock block)
    Places a CustomBlock using its default block data.
    void
    setBlock(int x, int y, int z, @NotNull CustomBlock block, @NotNull org.bukkit.block.data.BlockData data)
    Places a CustomBlock with explicit BlockData.
    void
    setBlock(int x, int y, int z, @NotNull org.bukkit.Material material)
    Sets a block using a Material.
    void
    setBlock(int x, int y, int z, @NotNull org.bukkit.block.data.BlockData data)
    Sets a block using BlockData.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NMSWorldGenAccess

      public NMSWorldGenAccess(org.bukkit.generator.LimitedRegion region, org.bukkit.World world, Random random)
      Creates a new NMS-backed world generation access instance.
      Parameters:
      region - The limited region for safe block/entity access
      world - The Bukkit world being generated
      random - The random instance for this generation pass
  • Method Details

    • isInRegion

      public boolean isInRegion(int x, int y, int z)
      Checks if the given coordinate is within this generation region
      Parameters:
      x - X coordinate
      y - Y Coordinate
      z - Z Coordinate
      Returns:
      Whether the coordinate is in region or not
    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull org.bukkit.Material material)
      Sets a block using a Material.
      Specified by:
      setBlock in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      material - Material to place
    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull org.bukkit.block.data.BlockData data)
      Sets a block using BlockData.
      Specified by:
      setBlock in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      data - Block data to apply
    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull CustomBlock block)
      Places a CustomBlock using its default block data.
      Specified by:
      setBlock in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      block - Custom block instance
    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull CustomBlock block, @NotNull @NotNull org.bukkit.block.data.BlockData data)
      Places a CustomBlock with explicit BlockData.

      The base block is placed first, then custom logic is applied via a virtual wrapper.

      Specified by:
      setBlock in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      block - Custom block instance
      data - Block data to apply
    • addEntity

      @NotNull public @NotNull org.bukkit.entity.Entity addEntity(double x, double y, double z, @NotNull @NotNull org.bukkit.entity.EntityType type)
      Spawns a vanilla entity safely within the generation region.
      Specified by:
      addEntity in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      type - Entity type
      Returns:
      Spawned entity
    • addEntity

      public void addEntity(double x, double y, double z, @NotNull @NotNull CustomEntity<?> entity)
      Spawns a CustomEntity at the given coordinates.
      Specified by:
      addEntity in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      entity - Custom entity instance
    • addEntity

      @Nullable public @Nullable org.bukkit.entity.Entity addEntity(double x, double y, double z, @NotNull @NotNull SavedEntity entity)
      Spawns a SavedEntity.
      Specified by:
      addEntity in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      entity - Saved entity definition
      Returns:
      Spawned entity or null if failed
    • getType

      @NotNull public @NotNull org.bukkit.Material getType(int x, int y, int z)
      Gets the material at a position.
      Specified by:
      getType in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Material at location
    • getBlockData

      @NotNull public @NotNull org.bukkit.block.data.BlockData getBlockData(int x, int y, int z)
      Gets the BlockData at a position.
      Specified by:
      getBlockData in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Block data
    • getBlockState

      @NotNull public @NotNull org.bukkit.block.BlockState getBlockState(int x, int y, int z)
      Retrieves the full BlockState using the safe LimitedRegion.
      Specified by:
      getBlockState in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Block state snapshot
    • getBiome

      @NotNull public @NotNull org.bukkit.block.Biome getBiome(int x, int y, int z)
      Gets the biome at a position.
      Specified by:
      getBiome in interface WorldGenAccess
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
      Returns:
      Biome
    • getHighestBlockY

      public int getHighestBlockY(int x, int z, org.bukkit.HeightMap heightMap)
      Gets the highest Y value at a position using a HeightMap.
      Specified by:
      getHighestBlockY in interface WorldGenAccess
      Parameters:
      x - X coordinate
      z - Z coordinate
      heightMap - Heightmap type
      Returns:
      Highest Y coordinate
    • getWorld

      @NotNull public @NotNull org.bukkit.World getWorld()
      Gets the Bukkit world.
      Specified by:
      getWorld in interface WorldGenAccess
      Returns:
      World instance
    • getRandom

      @NotNull public @NotNull Random getRandom()
      Gets the random instance used for generation.
      Specified by:
      getRandom in interface WorldGenAccess
      Returns:
      Random instance