Class Physics.WorldGeneration
java.lang.Object
ActiverseUtils.Physics.WorldGeneration
- Enclosing class:
Physics
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 ClassesModifier and TypeClassDescriptionstatic final record
Tile is a serializable record that stores the type of tile and any custom metadata. -
Constructor Summary
ConstructorsConstructorDescriptionWorldGeneration
(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 TypeMethodDescriptionvoid
clear()
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
loadFromFile
(String path) 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
saveToFile
(String path) Serializes the tileMap to a file on disk.void
Sets the tile at (x, y) with a type and no metadata.void
Sets the tile at (x, y) with a specified type and metadata map.
-
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
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
Sets the tile at (x, y) with a type and no metadata. -
setTile
-
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
Returns the internal tile map. -
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
Assigns biomes to each tile based on horizontal position and biome width. Each tile receives a "biome" key in its metadata. -
placeStructure
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
Serializes the tileMap to a file on disk.- Throws:
IOException
-
loadFromFile
Loads a previously saved tileMap from disk and replaces the current one.- Throws:
IOException
ClassNotFoundException
-