-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix vanilla dimension can't create when the number of dimensions…
… exceeds nine
- Loading branch information
Showing
9 changed files
with
440 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/test/generator/flat-gen-village/FlatVillageDimension.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "FlatVillageDimension.h" | ||
|
||
#include "test/generator/flat-gen-village/FlatVillageGenerator.h" | ||
#include "mc/world/level/BlockSource.h" | ||
#include "mc/world/level/DimensionConversionData.h" | ||
#include "mc/world/level/Level.h" | ||
#include "mc/world/level/LevelSeed64.h" | ||
#include "mc/world/level/chunk/ChunkGeneratorStructureState.h" | ||
#include "mc/world/level/chunk/VanillaLevelChunkUpgrade.h" | ||
#include "mc/world/level/dimension/DimensionBrightnessRamp.h" | ||
#include "mc/world/level/dimension/OverworldBrightnessRamp.h" | ||
#include "mc/world/level/dimension/VanillaDimensions.h" | ||
#include "mc/world/level/levelgen/structure/StructureFeatureRegistry.h" | ||
#include "mc/world/level/levelgen/structure/StructureSetRegistry.h" | ||
#include "mc/world/level/levelgen/structure/VillageFeature.h" | ||
|
||
|
||
namespace flat_village_dimension { | ||
|
||
FlatVillageDimension::FlatVillageDimension(std::string const& name, more_dimensions::DimensionFactoryInfo const& info) | ||
: Dimension(info.level, info.dimId, {-64, 320}, info.scheduler, name) { | ||
// 这里说明下,在DimensionFactoryInfo里面more-dimensions会提供维度id,请不要使用固定维度id,避免id冲突导致维度注册出现异常 | ||
mDefaultBrightness.sky = Brightness::MAX; | ||
mSeaLevel = -61; | ||
mHasWeather = true; | ||
mDimensionBrightnessRamp = std::make_unique<OverworldBrightnessRamp>(); | ||
mDimensionBrightnessRamp->buildBrightnessRamp(); | ||
} | ||
|
||
CompoundTag FlatVillageDimension::generateNewData() { return {}; } | ||
|
||
std::unique_ptr<WorldGenerator> | ||
FlatVillageDimension::createGenerator(br::worldgen::StructureSetRegistry const& structureSetRegistry) { | ||
std::unique_ptr<WorldGenerator> worldGenerator; | ||
uint seed = 2024; | ||
auto& levelData = getLevel().getLevelData(); | ||
|
||
// 实例化我们写的Generator类 | ||
worldGenerator = std::make_unique<flat_village_generator::FlatVillageGenerator>( | ||
*this, | ||
seed, | ||
levelData.getFlatWorldGeneratorOptions() | ||
); | ||
// structureSetRegistry里面仅有的土径结构村庄生成需要用到,所以我们拿一下 | ||
std::vector<std::shared_ptr<const br::worldgen::StructureSet>> structureMap; | ||
for (auto iter = structureSetRegistry.begin(); iter != structureSetRegistry.end(); iter++) { | ||
structureMap.emplace_back(iter->second); | ||
} | ||
worldGenerator->getStructureFeatureRegistry().mChunkGeneratorStructureState.mSeed = seed; | ||
worldGenerator->getStructureFeatureRegistry().mChunkGeneratorStructureState.mSeed64 = | ||
LevelSeed64::fromUnsigned32(seed); | ||
|
||
// 这个就相当于在这个生成器里注册结构了 | ||
// VillageFeature的第二第三个参数是村庄之间的最大间隔与最小间隔 | ||
worldGenerator->getStructureFeatureRegistry().mStructureFeatures.emplace_back( | ||
std::make_unique<VillageFeature>(seed, 34, 8) | ||
); | ||
// 此为必须,一些结构生成相关 | ||
worldGenerator->getStructureFeatureRegistry().mChunkGeneratorStructureState = | ||
br::worldgen::ChunkGeneratorStructureState::createFlat(seed, worldGenerator->getBiomeSource(), structureMap); | ||
|
||
// 必须调用,初始化生成器 | ||
worldGenerator->init(); | ||
return std::move(worldGenerator); | ||
} | ||
|
||
void FlatVillageDimension::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); | ||
} | ||
|
||
void FlatVillageDimension::fixWallChunk(ChunkSource& cs, LevelChunk& lc) { | ||
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false); | ||
VanillaLevelChunkUpgrade::fixWallChunk(lc, blockSource); | ||
} | ||
|
||
bool FlatVillageDimension::levelChunkNeedsUpgrade(LevelChunk const& lc) const { | ||
return VanillaLevelChunkUpgrade::levelChunkNeedsUpgrade(lc); | ||
} | ||
void FlatVillageDimension::_upgradeOldLimboEntity(CompoundTag& tag, ::LimboEntitiesVersion vers) { | ||
auto isTemplate = getLevel().getLevelData().isFromWorldTemplate(); | ||
return VanillaLevelChunkUpgrade::upgradeOldLimboEntity(tag, vers, isTemplate); | ||
} | ||
|
||
std::unique_ptr<ChunkSource> | ||
FlatVillageDimension::_wrapStorageForVersionCompatibility(std::unique_ptr<ChunkSource> cs, ::StorageVersion /*ver*/) { | ||
return cs; | ||
} | ||
|
||
Vec3 FlatVillageDimension::translatePosAcrossDimension(Vec3 const& fromPos, DimensionType fromId) const { | ||
Vec3 topos; | ||
VanillaDimensions::convertPointBetweenDimensions( | ||
fromPos, | ||
topos, | ||
fromId, | ||
mId, | ||
getLevel().getDimensionConversionData() | ||
); | ||
constexpr auto clampVal = 32000000.0f - 128.0f; | ||
|
||
topos.x = std::clamp(topos.x, -clampVal, clampVal); | ||
topos.z = std::clamp(topos.z, -clampVal, clampVal); | ||
|
||
return topos; | ||
} | ||
|
||
short FlatVillageDimension::getCloudHeight() const { return 192; } | ||
|
||
bool FlatVillageDimension::hasPrecipitationFog() const { return true; } | ||
|
||
} // namespace flat_village_dimension |
47 changes: 47 additions & 0 deletions
47
src/test/generator/flat-gen-village/FlatVillageDimension.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "mc/world/level/dimension/Dimension.h" // 新维度类需要继承的类 | ||
#include "more_dimensions/api/dimension/CustomDimensionManager.h" // 引入DimensionFactoryInfo的声明 | ||
|
||
// 建议是加一个命名空间,避免与其他插件同类名的情况 | ||
namespace flat_village_dimension { | ||
|
||
class FlatVillageDimension : public Dimension { | ||
public: | ||
// 建议固定这样写,DimensionFactoryInfo类里面提供了Dimension实例化的基本数据,name就是维度名,多维度是维度名区分不同维度 | ||
FlatVillageDimension(std::string const& name, more_dimensions::DimensionFactoryInfo const& info); | ||
|
||
// 多维度需要的一个方法,参数是你需要处理的数据,比如种子,这里不没有这样的需要,后面说原因 | ||
static CompoundTag generateNewData(); | ||
|
||
// 以下六个是必须重写的函数 | ||
// 维度地形的生成器,是本教程主要更改的地方 | ||
std::unique_ptr<WorldGenerator> createGenerator(br::worldgen::StructureSetRegistry const&) override; | ||
|
||
// 与本教程无关,按照本教程写的就行,无需留意 | ||
void upgradeLevelChunk(ChunkSource& chunkSource, LevelChunk& oldLc, LevelChunk& newLc) override; | ||
|
||
// 与本教程无关,按照本教程写的就行,无需留意 | ||
void fixWallChunk(ChunkSource& cs, LevelChunk& lc) override; | ||
|
||
// 与本教程无关,按照本教程写的就行,无需留意 | ||
bool levelChunkNeedsUpgrade(LevelChunk const& lc) const override; | ||
|
||
// 与本教程无关,按照本教程写的就行,无需留意 | ||
void _upgradeOldLimboEntity(CompoundTag& tag, ::LimboEntitiesVersion vers) override; | ||
|
||
// 与本教程无关,按照本教程写的就行,无需留意 | ||
std::unique_ptr<ChunkSource> | ||
_wrapStorageForVersionCompatibility(std::unique_ptr<ChunkSource> cs, ::StorageVersion ver) override; | ||
|
||
// 当你转到这个维度时,坐标怎么转换,比如主世界与地狱的 | ||
Vec3 translatePosAcrossDimension(Vec3 const& pos, DimensionType did) const override; | ||
|
||
// 云高度,默认是y128,但多维度高度范围是在y-64~320,与主世界相同,重写它,放高些 | ||
short getCloudHeight() const override; | ||
|
||
// 非必要。下雨时,可视范围的更改 | ||
bool hasPrecipitationFog() const override; | ||
}; | ||
|
||
} // namespace flat_village_dimension |
Oops, something went wrong.