BiomeGeneration
Cubiomes.BiomeGeneration
— ModuleBiomeGeneration
Module for generating biomes in Minecraft worlds.
Like almost everything in this package, the coordinates order is always(x, z, y)
, not (x, y, z)
weither it is for function calls, world indexing, etc. If it is too confusing, hide the order by working directly over the coordinate objects, or use keyword arguments.
The typical workflow is:
- Create a dimension object (e.g.
Overworld
,Nether
,End
) ->Dimension
- Set the seed of the dimension ->
setseed!
- Get the biome at a specific coordinate ->
getbiome
Or:
- Create a world object ->
WorldMap
- Generate the biomes in the world ->
genbiomes!
The biomes are stored in a WorldMap
object, which is a 3D array of biomes. To get the coordinates of the biomes, use the coordinates
function. It gives an iterator of CartesianIndex
objects, a built-in Julia type. So any intuitive indexing should work out of the box.
Index
Cubiomes.BiomeGeneration.Dimension
Cubiomes.BiomeGeneration.End
Cubiomes.BiomeGeneration.Nether
Cubiomes.BiomeGeneration.Overworld
Cubiomes.BiomeGeneration.Scale
Cubiomes.BiomeGeneration.SomeSha
Cubiomes.BiomeGeneration.fill_radius!
Cubiomes.BiomeGeneration.genbiomes!
Cubiomes.BiomeGeneration.getbiome
Cubiomes.BiomeGeneration.original_getbiome
Cubiomes.BiomeGeneration.setseed!
Cubiomes.BiomeGeneration.similar_expand
Cubiomes.BiomeGeneration.view_reshape_cache_like
API
Cubiomes.BiomeGeneration.Dimension
— TypeDimension
The parent type of every Minecraft dimension. There is generally three steps to use a dimension:
- Create one dimension with a specific
MCVersion
and maybe some specific arguments. - Set the seed of the dimension with
setseed!
. - Do whatever you want with the dimension: get biomes, generate biomes, etc.
Examples
julia> overworld = Overworld(undef, mcv"1.18");
julia> setseed!(overworld, 42)
julia> getbiome(overworld, 0, 0, 63)
dark_forest::Biome = 0x1d
julia> setseed!(overworld, "I love cats")
julia> world = WorldMap(x=-100:100, z=-100:100, y=63);
julia> genbiomes!(overworld, world, scale=📏"1:4")
See also:
Extended help
Extended help
This section is for developers that want to implement a new dimension.
The concrete type TheDim
MUST implement:
- An uninitialized constructor
TheDim(::UndefInitializer, ::MCVersion, args...)
- An inplace constructor
setseed!(dim::TheDim, seed::UInt64, args...)
. Be aware that the seed must be constrained toUInt64
dispatch to work. - getbiome(dim::TheDim, coord, scale::Scale, args...) -> Biome where
coord
can be either (x::Real, z::Real, y::Real) or NTuple{3} - genbiomes!(dim::TheDim, out::WorldMap, scale::Scale, args...)
Cubiomes.BiomeGeneration.End
— TypeEnd(::UndefInitializer, version::MCVersion)
The Minecraft End dimension.
Cubiomes.BiomeGeneration.Nether
— TypeNether(::UndefInitializer, V::MCVersion)
The Nether dimension. See Dimension
for general usage.
Minecraft version <1.16
Before version 1.16, the Nether is only composed of nether wastes. Nothing else.
Minecraft version >= 1.16 specificities
If the 1:1 scale will never be used, adding
sha=Val(false)
tosetseed!
will save a very small amount of time (of the order of 100ns up to 1µs). The sha is a precomputed value only used for the 1:1 scale. But the default behavior is to compute the sha at each seed change for simplicity.In the biome generation functions, a last paramter
confidence
can be passed. It is a performance-related parameter between 0 and 1. A bit the same as thescale
parameter, but it is a continuous value, and the scale is not modified.
Cubiomes.BiomeGeneration.Overworld
— TypeOverworld(::UndefInitializer, ::mcvt">=1.18")
The Overworld dimension. See Dimension
for general usage.
At the moment, only version 1.18 and above are supported. Older versions will be supported in the future.
Minecraft version >= 1.18 specificities
If the 1:1 scale will never be used, adding
sha=Val(false)
tosetseed!
will save a very small amount of time (of the order of 100ns up to 1µs). The sha is a precomputed value only used for the 1:1 scale. But the default behavior is to compute the sha at each seed change for simplicity.Two keyword arguments are added to the biome generation:
skip_depth=Val(false)
: ifVal(true)
, the depth sampling is skipped. Time saved: 1/3 of the biome generation time.skip_shift=Val(false)
: only for the 1:1 and 1:4 scales. IfVal(true)
, the shift sampling is skipped. Time saved: 1/10 of the biome generation time.
Cubiomes.BiomeGeneration.Scale
— TypeScale{N}
Scale(N::Integer)
📏"1:N"
The scale of a map. It represents the ratio between the size of the map an the real world. For example, a 1:4 scale map means that each block in the map represents a 4x4 area in the real world. So the coordinates (5, 5) are equal to the real world coordinates (20, 20).
N
MUST ne to the form $4^n, n \geq 0$. So the more common scales are 1:1, 1:4, 1:16, 1:64, 1:256. The support for big scales is not guaranteed and depends on the function that uses it. Read the documentation of the function that uses it to know the supported values.
It is possible to use the alternative syntax 📏"1:N"
. The emoji name is :straight_ruler:
.
Examples
julia> Scale(4)
Scale{4}()
julia> Scale(5)
ERROR: ArgumentError: The scale must be to the form 4^n. Got 1:5. The closest valid scales are 1:4 and 1:16.
julia> 📏"1:4" === Scale(4) === Scale{4}()
true
Cubiomes.BiomeGeneration.genbiomes!
— Methodgenbiomes!(dim::Dimension, world::WorldMap, [scale::Scale,], args...; kwargs...) -> Nothing
Fill the world map with the biomes of the dimension dim
. The scale is defaulted to 1:1. The args are specific to the dimension. See the documentation of the dimension for more information.
Cubiomes.BiomeGeneration.getbiome
— Functiongetbiome(dim::Dimension, x::Real, z::Real, y::Real, [scale::Scale,], args...; kwargs...) -> Biome
getbiome(dim::Dimension, coord, [scale::Scale,], args...; kwargs...) -> Biome
Get the biome at the coordinates (x, z, y)
in the dimension dim
. The coordinates can be passed as numbers or as tuples or as CartesianIndex
(the coords returned by coordinates
). The scale is defaulted to 1:1 (the more precise).
The scale is defaulted to 1:1, i.e. the exact coordinates. The args are specific to the dimension. See the documentation of the dimension for more information.
See also: - Scale
, genbiomes!
, Dimension
Cubiomes.BiomeGeneration.setseed!
— Methodsetseed!(dim::Dimension, seed; kwargs...)
Set the seed of the dimension generator. It can be any valid seed you can pass like in Minecraft, but UInt64 is better if performance is a concern. To transform an UInt64 seed to a "normal" one, use signed(seed)
.
Other keyword arguments can be passed, specific to the dimension / minecraft version. They are often related to some micro-optimizations. See the documentation of the specific dimension for more information.
Cubiomes.BiomeGeneration.BiomeArrays.WorldMap
— MethodWorldMap{N} where N (N = 2, 3)
WorldMap(xrange::UnitRange, zrange::UnitRange, yrange::UnitRange)
WorldMap(xrange::UnitRange, zrange::UnitRange, y::Number)
WorldMap(xrange::UnitRange, zrange::UnitRange)
WorldMap(;x, z, y)
A 2D or 3D array of biomes. It is the main data structure used to store the biomes of a Minecraft world. It is a simple wrapper around AbstractArray{Biome, N}
. So anything that works with arrays should work with WorldMap
.
See also: view2d
, coordinates
Cubiomes.BiomeGeneration.BiomeArrays.coordinates
— Methodcoordinates(M::WorldMap) -> CartesianIndices
Wrapper around CartesianIndices
to get the coordinates of the biomes in the map. Useful to iterate over the coordinates of the map.
Cubiomes.BiomeGeneration.BiomeArrays.view2d
— Methodview2d(W::WorldMap{3}) -> WorldMap{2}
View a 3D world as a 2D world. Only works if the y size is 1. Otherwise, it throws an error. Useful for functions that only work with 2D worlds, even if the y size is 1, like 2d visualization.
The returned object is a view, so modifying it will also modify the original world. Use copy
to get a new independent world.
Private API
Click to see
Cubiomes.BiomeGeneration.SomeSha
— TypeSomeSha
A struct that holds a UInt64
or nothing
. It is used to store the SHA of the seed if it is needed. Acts like a reference (a zero dimension array) to a UInt64
or nothing
. Use sha[]
to get or store the value, or directly setseed!(sha, seed)
to compute the SHA of the seed and store it and reset!(sha)
to set it to nothing
.
Cubiomes.BiomeGeneration.fill_radius!
— Methodfill_radius!(out::WorldMap{N}, center::CartesianIndex{2}, id::Biome, radius)
Fills a circular area around the point center
in out
with the biome id
, within a given radius
. Assuming radius
>=0. If center
is outside the out
coordinates, nothing is done.
Cubiomes.BiomeGeneration.original_getbiome
— Methodoriginal_getbiome(end_noise::EndNoise, x, z)
Original algorithm to get the biome at a given point in the End dimension. It is only here for documentation purposes, because everything else is just optimizations and scaling on this basis (for scale >= 4).
But not so sure that the optimizations are really important, most of ones are just avoid √ operations, but hypot is already really fast in Julia.
Cubiomes.BiomeGeneration.similar_expand
— Methodsimilar_expand{T}(mc_map::OffsetMatrix, expand_x::Int, expand_z::Int) where T
Create an uninitialized OffsetMatrix of type T
but with additional rows and columns on each side of the original matrix.
Cubiomes.BiomeGeneration.view_reshape_cache_like
— Functionview_reshape_cache_like(axes)
Create a view of the cache with the same shape as the axes.
This function is not thread-safe and should not be used in a multithreaded context.
Cubiomes.BiomeGeneration.Voronoi.voronoi_access
— Methodvoronoi_access(sha::UInt64, coord::Union{CartesianIndex{3}, NTuple{3, T}}) where {T}
voronoi_access(sha::UInt64, x, z, y)
Compute the closest Voronoi cell based on the given coordinates (at 1:4 scale). Used by Minecraft to translate the 1:4 scale coordinates to the 1:1 scale.
For example we can find in some part of the biome generation source code:
>>> function getbiome(dimension, x, z, y, ::Scale{1})
sx, sz, zy = voronoi_access(dimension, x, z, y)
getbiome(dimension, sx, sz, sy, Scale(4))
end