Class Physics.WorldGeneration

java.lang.Object
ActiverseUtils.Physics.WorldGeneration
Enclosing class:
Physics

public static class Physics.WorldGeneration extends Object
WorldGeneration provides advanced utilities for procedural world generation. It supports biomes, cave generation, tile metadata, Perlin noise terrain, structure placement, and world serialization.
Version:
1.4.0
Author:
Knivier
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Tile is a serializable record that stores the type of tile and any custom metadata.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WorldGeneration(int width, int height)
    Constructs a world with the given dimensions using current time as seed.
    WorldGeneration(int width, int height, long seed)
    Constructs a world with given dimensions and a specified random seed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the entire tile map by setting all tiles to null.
    void
    fillBelowSurface(int[] surface, int stoneLevel, String surfaceType, String dirtType, String stoneType)
    Fills terrain below the surface based on a heightmap using layered materials.
    void
    generateBiomes(int biomeWidth, String[] biomes)
    Assigns biomes to each tile based on horizontal position and biome width.
    void
    generateCaves(double fillProbability, int steps)
    Generates cave-like structures using a randomized cellular automata.
    int[]
    generatePerlinSurface(int baseLevel, double frequency, double amplitude)
    Generates a 1D heightmap using Perlin noise with default octaves and persistence.
    int[]
    generatePerlinSurface(int baseLevel, double frequency, double amplitude, int octaves, double persistence)
    Generates a customizable Perlin-based heightmap with multiple octaves.
    Returns the internal random instance (for procedural hooks).
    getTile(int x, int y)
    Returns the Tile object at the specified (x, y), or null if out of bounds.
    Returns the internal tile map.
    boolean
    inBounds(int x, int y)
    Returns true if (x, y) is within world boundaries.
    void
    Loads a previously saved tileMap from disk and replaces the current one.
    void
    placeStructure(int x, int y, String[][] structure)
    Places a rectangular structure into the world, starting at (x, y).
    void
    Serializes the tileMap to a file on disk.
    void
    setTile(int x, int y, String type)
    Sets the tile at (x, y) with a type and no metadata.
    void
    setTile(int x, int y, String type, Map<String,Object> metadata)
    Sets the tile at (x, y) with a specified type and metadata map.

    Methods inherited from class java.lang.Object

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

    • WorldGeneration

      public WorldGeneration(int width, int height)
      Constructs a world with the given dimensions using current time as seed.
    • WorldGeneration

      public WorldGeneration(int width, int height, long seed)
      Constructs a world with given dimensions and a specified random seed.
  • Method Details

    • getTile

      public Physics.WorldGeneration.Tile getTile(int x, int y)
      Returns the Tile object at the specified (x, y), or null if out of bounds.
      Returns:
      Tile at (x, y) or null if out of bounds.
    • setTile

      public void setTile(int x, int y, String type)
      Sets the tile at (x, y) with a type and no metadata.
    • setTile

      public void setTile(int x, int y, String type, Map<String,Object> metadata)
      Sets the tile at (x, y) with a specified type and metadata map.
    • inBounds

      public boolean inBounds(int x, int y)
      Returns true if (x, y) is within world boundaries.
      Returns:
      boolean indicating if coordinates are valid.
    • getTileMap

      public Physics.WorldGeneration.Tile[][] getTileMap()
      Returns the internal tile map.
    • getRandom

      public Random getRandom()
      Returns the internal random instance (for procedural hooks).
      Returns:
      Random instance used for procedural generation.
    • clear

      public void clear()
      Clears the entire tile map by setting all tiles to null.
    • generatePerlinSurface

      public int[] generatePerlinSurface(int baseLevel, double frequency, double amplitude)
      Generates a 1D heightmap using Perlin noise with default octaves and persistence.
      Parameters:
      baseLevel - The vertical base to center terrain around.
      frequency - Controls horizontal stretching (lower = wider features).
      amplitude - Controls vertical height variation.
      Returns:
      An array of Y-values representing the surface.
    • generatePerlinSurface

      public int[] generatePerlinSurface(int baseLevel, double frequency, double amplitude, int octaves, double persistence)
      Generates a customizable Perlin-based heightmap with multiple octaves.
      Parameters:
      baseLevel - The vertical base to center terrain around.
      frequency - Controls horizontal stretching (lower = wider features).
      amplitude - Controls vertical height variation.
      octaves - Number of octaves for detail (higher = more detail).
      persistence - Controls amplitude scaling between octaves (0.0-1.0).
      Returns:
      An array of Y-values representing the surface.
    • fillBelowSurface

      public void fillBelowSurface(int[] surface, int stoneLevel, String surfaceType, String dirtType, String stoneType)
      Fills terrain below the surface based on a heightmap using layered materials.
      Parameters:
      surface - The heightmap array.
      stoneLevel - Y-value below which stone is used.
      surfaceType - Tile type for surface layer.
      dirtType - Tile type for soil layer.
      stoneType - Tile type for deep underground.
    • generateBiomes

      public void generateBiomes(int biomeWidth, String[] biomes)
      Assigns biomes to each tile based on horizontal position and biome width. Each tile receives a "biome" key in its metadata.
    • placeStructure

      public void placeStructure(int x, int y, String[][] structure)
      Places a rectangular structure into the world, starting at (x, y). Each non-null string in the 2D array represents a tile type.
    • generateCaves

      public void generateCaves(double fillProbability, int steps)
      Generates cave-like structures using a randomized cellular automata.
      Parameters:
      fillProbability - Initial chance for a cell to be wall.
      steps - Number of smoothing iterations (higher = smoother caves).
    • saveToFile

      public void saveToFile(String path) throws IOException
      Serializes the tileMap to a file on disk.
      Throws:
      IOException
    • loadFromFile

      public void loadFromFile(String path) throws IOException, ClassNotFoundException
      Loads a previously saved tileMap from disk and replaces the current one.
      Throws:
      IOException
      ClassNotFoundException