-
Notifications
You must be signed in to change notification settings - Fork 3
API Relence(English)
Create APIs related to dimensions.
template <std::derived_from<Dimension> D, class... Args>
DimensionType addDimension(std::string const& dimName, Args&&... args)
Add a dimension with the name dimName
. If successful, it will return the DimensionType
of this dimension. Otherwise, it will return a DimensionType
with an id
of -1.
When calling this function, there must be a static function named generateNewData
in the dimension class, which returns a CompoundTag
. The purpose of generateNewData
is to transfer the parameters needed for initialization to your custom dimension class.
For example, the simple dimension class SimpleCustomDimension
provided by MoreDimensions needs to know the type and seed of the generated dimension. We pass them through generateNewData
.
The purpose of this wrapper is to avoid exposing the ID of the dimension, preventing developers from customizing the ID and causing confusion and conflicts. The ID of the dimension is completely managed by CustomDimensionManager
. Developers only need to provide the dimension name and don't need to consider ID conflicts.
The parameters of args
are determined based on the generateNewData
in the dimension class.
For example, the SimpleCustomDimension::generateNewData
in MoreDimensions accepts a uint seed parameter and a GeneratorType generation type parameter. So, you can call it like this:
more_dimensions::CustomDimensionManager::getInstance()
.addDimension<more_dimensions::SimpleCustomDimension>("Dimensin Name", 12345678, GeneratorType::Flat);
static DimensionType getDimensionIdFromName(std::string const& dimName);
Note that we do not recommend using this API. It is recommended to use VanillaDimensions::fromString
directly.
Get the dimension ID. Use the dimension name dimName
to get the corresponding DimensionType
.
A simple dimension class provided by MoreDimensions, which can create the original five types of dimensions: Void
, Flat
, Overworld
, Nether
, and TheEnd
.
This is also an example dimension class, the following mainly explains the functions of these functions for developers to refer to.
static CompoundTag generateNewData('Custom parameters');
This is a static function that must be provided, its parameters are customized by the developer, and its function is to transfer some parameters that need to be used when initializing the dimension.
This function simply packages these custom parameters into a CompoundTag
, which will eventually be passed to the dimension class's instantiation function.
SimpleCustomDimension(std::string const& name, DimensionFactoryInfo const& info);
The instantiation function of the dimension class, its parameters are fixed, if you need to transfer more parameters needed when instantiating, you need to customize them in generateNewData
.
The implementation of this function must call the instantiation function of the parent class Dimension
, refer to the writing of this example class:
SimpleCustomDimension::SimpleCustomDimension(std::string const& name, DimensionFactoryInfo const& info)
: Dimension(info.level, info.dimId, {-64, 320}, info.scheduler, name) {
...code...
}
Here's an explanation of the parameters accepted by the Dimension instantiation function:
Dimension(
info.level, /*This is the base class pointer ILevel of Level*/
info.dimId, /*Dimension id, do not change*/
{-64, 320}, /*Dimension height, this setting is sufficient*/
info.scheduler, /*Don't know what it does, it's not used, ignore it*/
name /*Dimension name*/
)
In this instantiation function, the parameter info
contains the remaining parameters required to call the parent class instantiation function, where the custom parameters in generateNewData
are in info.data
:
SimpleCustomDimension::SimpleCustomDimension(std::string const& name, DimensionFactoryInfo const& info)
: Dimension(info.level, info.dimId, {-64, 320}, info.scheduler, name) {
loggerMoreDim.debug("{} dimension name:{}", __FUNCTION__, name);
mDefaultBrightness.sky = Brightness::MAX;
generatorType = *magic_enum::enum_cast<GeneratorType>((std::string_view)info.data["generatorType"]);
seed = info.data["seed"];
...code...
}
Within the instantiation function, the minimum initialized member variables are: mDefaultBrightness
, mSeaLevel
, mHasWeather
, mDimensionBrightnessRamp
If you have custom variables, it's best to initialize them as well.
SimpleCustomDimension::SimpleCustomDimension(std::string const& name, DimensionFactoryInfo const& info)
: Dimension(info.level, info.dimId, {-64, 320}, info.scheduler, name) {
loggerMoreDim.debug("{} dimension name:{}", __FUNCTION__, name);
mDefaultBrightness.sky = Brightness::MAX;
generatorType = *magic_enum::enum_cast<GeneratorType>((std::string_view)info.data["generatorType"]);
seed = info.data["seed"];
switch (generatorType) {
case GeneratorType::TheEnd: {
mSeaLevel = 63;
mHasWeather = false;
mDimensionBrightnessRamp = std::make_unique<OverworldBrightnessRamp>();
}
case GeneratorType::Nether: {
mSeaLevel = 32;
mHasWeather = false;
mDimensionBrightnessRamp = std::make_unique<NetherBrightnessRamp>();
}
default:
mSeaLevel = 63;
mHasWeather = true;
mDimensionBrightnessRamp = std::make_unique<OverworldBrightnessRamp>();
}
mDimensionBrightnessRamp->buildBrightnessRamp();
}
Looking at the example code, you'll find that buildBrightnessRamp()
is called at the end, which is also necessary.
For the assignment of mDimensionBrightnessRamp
, if you don't know what it does or don't use it, you can use OverworldBrightnessRamp
to build one.
void init(br::worldgen::StructureSetRegistry const& structureSetRegistry)
This is an overridden function.
It is called when the dimension is initialized and must call the parent class Dimension
's init
function.
Unless there is a specific need, you can directly call the parent's init
function:
void SimpleCustomDimension::init(br::worldgen::StructureSetRegistry const& structureSetRegistry) {
setSkylight(false);
Dimension::init(structureSetRegistry);
}
std::unique_ptr<WorldGenerator> createGenerator(br::worldgen::StructureSetRegistry const&)
This is an overridden function.
Creates a WorldGenerator
object for generating the terrain structure of this dimension.
If you need to customize the terrain of the dimension, you can start with this WorldGenerator
. This example code selects different terrain generators based on the selected terrain type.
For detailed explanation, please refer to the WorldGenerator section of the Wiki's example plugin FlatGeneratedVillages.
There is also a terrain system based on the Flat world type generator-terrain.
This example class shows how to create a WorldGenerator
object usable by BDS. The content is quite long, please refer to the source code.
This is an overridden function.
void upgradeLevelChunk(ChunkSource& chunkSource, LevelChunk& oldLc, LevelChunk& newLc)
Updates the old chunk.
This function is mainly for updating old version chunks, such as the cave update in 1.18, replacing the bedrock near y0 in old chunks and filling the space below y0.
If there is no specific need, you can write it according to this example class:
void SimpleCustomDimension::upgradeLevelChunk(ChunkSource& cs, LevelChunk& lc, LevelChunk& generatedChunk) {
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false);
VanillaLevelChunkUpgrade::_upgradeLevelChunkViaMetaData(lc, generatedChunk, blockSource);
VanillaLevelChunkUpgrade::_upgradeLevelChunkLegacy(lc, blockSource);
}
This is an overridden function.
Its function is currently unknown.
This is an overridden function.
Its function is currently unknown.
This is an overridden function.
Its function is currently unknown.
This is an overridden function.
Coordinate conversion between different dimensions
In the original version, the Nether
coordinates are eight times the Overworld
coordinates, which is converted by this function.
This is an overridden function.
Its function is currently unknown.
This is an overridden function.
Its function is currently unknown.
This is an overridden function.
Gets the cloud height. Its function in BDS is unknown.
This is an overridden function.
Its function is currently unknown.