-
Notifications
You must be signed in to change notification settings - Fork 0
Home
ikbLib is a library mod which currently implements the following:
- A family of voronoi/cellular noise density functions
- An API for creating new density functions which use the world seed to generate noise
- An API for creating fluids which flow over or under one another
ikbLib's voronoi noise functions all use a common system based on the FastNoiseLite library. Each divides the world into a series of square regions called plates, then places a point in the center of each plate and offsets it by a random amount in the x and z directions. When the function is called, it compares the current block position to the plate it lies inside and its eight neighbors. The plates are put into a sorted list from closest center point to furthest center point. Then a plate is chosen from the list, and a corresponding value is output.
This is a basic voronoi noise function. It recalculates each time it's called, making it ideal for one-time uses. It takes the following parameters (and their data types):
-
"scale"(double) the width of an average cell. This value must be defined by a data pack. Literally, this defines the size of the grid used for plates. -
"salt"(long) a value which is added to the seed. Defaults to 0. -
"flat"(boolean) whether or not to use "flat mode" calculations. By default, all plate centers and y positions are calculated as y = 0. When turned off, the actual y position is used and plates are offset in the y direction. Can be used with or without flat_cache to fix y positions without moving the y offset of plates. Not recommended with high scales. -
"jitter"(double) a value from 0 to 0.5 which scales the random offset of each plate's center. Defaults to 0.4. At 0, creates a perfectly square grid of points. -
"metric"(int) a value from 0 to 5 which determines which distance metric to use. Defaults to 1 (see below). -
"mode"(int) a value from 0 to 1 which determines the output mode. Defaults to 0 (see below). -
"ordinal"(int) a value from 1 to 9 which determines which plate's values to output; 1 (default) is the plate with the closest center, 2 is the second closest, etc.
ikbLib's voronoi functions have three output modes:
- 0: Distance (default) outputs the distance between the given block position and a nearby plate's center. The output is given relative to the scale parameter; 0 means the block is exactly at the plate's center, 0.5 means the distance is equal to half the scale, etc. Normal output range is 0 to 2. The higher the jitter, the more commonly outputs exceed 1. For the distance from a boundary, subtract the neighboring plate's distance from the nearest plate's distance.
- 1: Value outputs a random value between 0 and 1. Each plate has a different value.
- 2: Velocity (relative) outputs the relative velocity between the nearest plate and a neighboring plate, intended for tectonic plate simulations. Output range is untested, but estimated and -2 to 2; a result of 0 represents a passive margin or transform boundary. Ordinal 1 always gives a result of 0.
- 3: Passive Margin Check checks if two plates have identical velocities. Outputs 1 if true and 0 if false.
ikbLib's voronoi functions come with six integrated distance functions:
- 0: Taxicab/Manhattan. The difference in x, y, and z values are calculated separately, then added together. On a chessboard, this is the distance a rook would take to reach a point. This and Chebyshev both give cells with lines that run parallel to the x and z axes or at a 45 degree diagonal.
- 1: Euclidean (default). This is the normal distance, where the diagonal of a square is about 1.4 times the size of its side length. On a chessboard, this is the distance an ant would take to reach a point.
- 2: Chebyshev. The difference in x, y, and z values are calculated separately, then only the largest is used. On a chessboard, this is the distance a king would take to reach a point.
- 3, 4, 5: Averages: 3, 4, and 5 each calculate two of the other metrics, then average them together. 3 is Taxicab + Euclidean, 4 is Taxicab + Chebyshev, and 5 is Chebyshev and Euclidean.
These two technical functions work in tandem to yield multiple values from a single voronoi diagram. Because the calculations are slightly more involved, but don't have to repeat for each point, this is recommended if you need to make complex calculations based on several values taken from nearby plates.
The cached_voronoi function defines the voronoi diagram which you're sampling from, and stores several different values for it. It accepts the following parameters:
-
"salt", "flat", "scale", "jitter", "metric"see above. As withvoronoi, only scale must be defined. -
"maxCheck"(int) a value from 1 to 9 which tells minecraft how many plates to save data for. At the default value of 3, for example, it saves only the three nearest plates to a given point. If you attempt to pull values for a fourth, the function will fail and output 0 by default.
Then, pull_from_voronoi is used to take a cached value from the cached_voronoi (if you try to calculate from cached_voronoi as a normal density function, it simply returns 0). It accepts the following parameters:
- `"mode", "ordinal" see above. Both are optional and act as they do with the basic function.
-
"cache"(densityFunction) a required parameter which indicates whichcached_voronoifunction to pull from. It can also pull from aflat_cache,cache_once, or the like as long as it wraps acached_voronoi. Multiplepull_from_voronoifunctions can (and should) use the samecacheparameter.