Skip to content

Commit c1281d5

Browse files
committed
test: fix test
1 parent afe8a37 commit c1281d5

16 files changed

+220
-95
lines changed

src/test/TestCustomDimension.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// #include "test/generator/flat-gen-village/FlatVillageDimension.h"
1+
#include "test/generator/flat-gen-village/FlatVillageDimension.h"
22
// #include "test/generator/generator-custom-structure/dimension/CustomStructureDimension.h"
3-
// #include "test/generator/generator-terrain/NxnBorderTerrainDimension.h"
3+
#include "test/generator/generator-terrain/NxnBorderTerrainDimension.h"
44

55
#include "ll/api/event/EventBus.h"
66
#include "ll/api/event/server/ServerStartedEvent.h"
@@ -33,14 +33,14 @@ static bool reg = [] {
3333
more_dimensions::CustomDimensionManager::getInstance()
3434
.addDimension<more_dimensions::SimpleCustomDimension>("testNewVoidDimension", 345, GeneratorType::Void);
3535

36-
// // custom diomension test
37-
// // flat type generator village dimension test
38-
// more_dimensions::CustomDimensionManager::getInstance()
39-
// .addDimension<flat_village_dimension::FlatVillageDimension>("testFlatVillage");
36+
// custom diomension test
37+
// flat type generator village dimension test
38+
more_dimensions::CustomDimensionManager::getInstance()
39+
.addDimension<flat_village_dimension::FlatVillageDimension>("testFlatVillage");
4040

41-
// // flat type custom terrain dimension test
42-
// more_dimensions::CustomDimensionManager::getInstance()
43-
// .addDimension<nxn_border_terrain::NxnBorderTerrainDimension>("testFlatTerrain", 5);
41+
// flat type custom terrain dimension test
42+
more_dimensions::CustomDimensionManager::getInstance()
43+
.addDimension<nxn_border_terrain::NxnBorderTerrainDimension>("testFlatTerrain", 5);
4444

4545
// // flat type custom structure dimension test
4646
// more_dimensions::CustomDimensionManager::getInstance()

src/test/generator/flat-gen-village/FlatVillageDimension.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,30 @@ std::unique_ptr<WorldGenerator>
3939
FlatVillageDimension::createGenerator(br::worldgen::StructureSetRegistry const& structureSetRegistry) {
4040
std::unique_ptr<WorldGenerator> worldGenerator;
4141
uint seed = 2024;
42-
auto& levelData = getLevel().getLevelData();
42+
auto& levelData = mLevel.getLevelData();
4343

4444
// 实例化我们写的Generator类
4545
worldGenerator = std::make_unique<flat_village_generator::FlatVillageGenerator>(
4646
*this,
4747
seed,
48-
levelData.getFlatWorldGeneratorOptions()
48+
levelData.mFlatworldGeneratorOptions
4949
);
5050
// structureSetRegistry里面仅有的土径结构村庄生成需要用到,所以我们拿一下
5151
std::vector<std::shared_ptr<const br::worldgen::StructureSet>> structureMap;
5252
for (auto iter = structureSetRegistry.mStructureSets->begin(); iter != structureSetRegistry.mStructureSets->end();
5353
iter++) {
5454
structureMap.emplace_back(iter->second);
5555
}
56-
worldGenerator->getStructureFeatureRegistry().mGeneratorState->mSeed = seed;
57-
worldGenerator->getStructureFeatureRegistry().mGeneratorState->mSeed64 = LevelSeed64{seed};
56+
worldGenerator->mStructureFeatureRegistry->mGeneratorState->mSeed = seed;
57+
worldGenerator->mStructureFeatureRegistry->mGeneratorState->mSeed64 = LevelSeed64{seed};
5858

5959
// 这个就相当于在这个生成器里注册结构了
6060
// VillageFeature的第二第三个参数是村庄之间的最大间隔与最小间隔
61-
worldGenerator->getStructureFeatureRegistry().mStructureFeatures->emplace_back(
61+
worldGenerator->mStructureFeatureRegistry->mStructureFeatures->emplace_back(
6262
std::make_unique<VillageFeature>(seed, 34, 8)
6363
);
6464
// 此为必须,一些结构生成相关
65-
worldGenerator->getStructureFeatureRegistry().mGeneratorState =
65+
worldGenerator->mStructureFeatureRegistry->mGeneratorState =
6666
br::worldgen::ChunkGeneratorStructureState::createFlat(seed, worldGenerator->getBiomeSource(), structureMap);
6767

6868
// 必须调用,初始化生成器
@@ -71,21 +71,21 @@ FlatVillageDimension::createGenerator(br::worldgen::StructureSetRegistry const&
7171
}
7272

7373
void FlatVillageDimension::upgradeLevelChunk(ChunkSource& cs, LevelChunk& lc, LevelChunk& generatedChunk) {
74-
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false);
74+
auto blockSource = BlockSource(static_cast<Level&>(mLevel), *this, cs, false, true, false);
7575
VanillaLevelChunkUpgrade::_upgradeLevelChunkViaMetaData(lc, generatedChunk, blockSource);
7676
VanillaLevelChunkUpgrade::_upgradeLevelChunkLegacy(lc, blockSource);
7777
}
7878

7979
void FlatVillageDimension::fixWallChunk(ChunkSource& cs, LevelChunk& lc) {
80-
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false);
80+
auto blockSource = BlockSource(static_cast<Level&>(mLevel), *this, cs, false, true, false);
8181
VanillaLevelChunkUpgrade::fixWallChunk(lc, blockSource);
8282
}
8383

8484
bool FlatVillageDimension::levelChunkNeedsUpgrade(LevelChunk const& lc) const {
8585
return VanillaLevelChunkUpgrade::levelChunkNeedsUpgrade(lc);
8686
}
8787
void FlatVillageDimension::_upgradeOldLimboEntity(CompoundTag& tag, ::LimboEntitiesVersion vers) {
88-
auto isTemplate = getLevel().getLevelData().isFromWorldTemplate();
88+
auto isTemplate = mLevel.getLevelData().mIsFromLockedTemplate;
8989
return VanillaLevelChunkUpgrade::upgradeOldLimboEntity(tag, vers, isTemplate);
9090
}
9191

@@ -101,7 +101,7 @@ Vec3 FlatVillageDimension::translatePosAcrossDimension(Vec3 const& fromPos, Dime
101101
topos,
102102
fromId,
103103
mId,
104-
getLevel().getDimensionConversionData()
104+
mLevel.getDimensionConversionData()
105105
);
106106
constexpr auto clampVal = 32000000.0f - 128.0f;
107107

@@ -113,6 +113,6 @@ Vec3 FlatVillageDimension::translatePosAcrossDimension(Vec3 const& fromPos, Dime
113113

114114
short FlatVillageDimension::getCloudHeight() const { return 192; }
115115

116-
bool FlatVillageDimension::hasPrecipitationFog() const { return true; }
116+
// bool FlatVillageDimension::hasPrecipitationFog() const { return true; }
117117

118118
} // namespace flat_village_dimension

src/test/generator/flat-gen-village/FlatVillageDimension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FlatVillageDimension : public Dimension {
4141
short getCloudHeight() const override;
4242

4343
// 非必要。下雨时,可视范围的更改
44-
bool hasPrecipitationFog() const override;
44+
// bool hasPrecipitationFog() const override;
4545
};
4646

4747
} // namespace flat_village_dimension

src/test/generator/flat-gen-village/FlatVillageGenerator.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "FlatVillageGenerator.h"
22

3+
#include "mc/world/level/chunk/ChunkState.h"
4+
#include "test/mc/FixedBiomeSource.h"
5+
36
#include "mc/deps/core/math/Random.h"
47
#include "mc/platform/threading/Mutex.h"
58
#include "mc/util/ThreadOwner.h"
@@ -8,7 +11,6 @@
811
#include "mc/world/level/Level.h"
912
#include "mc/world/level/biome/registry/BiomeRegistry.h"
1013
#include "mc/world/level/biome/registry/VanillaBiomeNames.h"
11-
#include "mc/world/level/biome/source/FixedBiomeSource.h"
1214
#include "mc/world/level/chunk/ChunkViewSource.h"
1315
#include "mc/world/level/chunk/LevelChunk.h"
1416
#include "mc/world/level/chunk/PostprocessingManager.h"
@@ -17,6 +19,7 @@
1719

1820

1921

22+
2023
namespace flat_village_generator {
2124

2225
FlatVillageGenerator::FlatVillageGenerator(Dimension& dimension, uint seed, Json::Value const& generationOptionsJSON)
@@ -25,42 +28,42 @@ FlatVillageGenerator::FlatVillageGenerator(Dimension& dimension, uint seed, Json
2528
random.mRandom->mObject.mSeed = seed;
2629
mSeed = seed;
2730

28-
mBiome = getLevel().getBiomeRegistry().lookupByHash(VanillaBiomeNames::Plains());
31+
mBiome = mLevel->getBiomeRegistry().lookupByHash(VanillaBiomeNames::Plains());
2932
mBiomeSource = std::make_unique<FixedBiomeSource>(*mBiome);
3033
}
3134

3235
bool FlatVillageGenerator::postProcess(ChunkViewSource& neighborhood) {
3336
ChunkPos chunkPos;
34-
chunkPos.x = neighborhood.getArea().mBounds.mMin->x;
35-
chunkPos.z = neighborhood.getArea().mBounds.mMin->z;
37+
chunkPos.x = neighborhood.mArea->mBounds.mMin->x;
38+
chunkPos.z = neighborhood.mArea->mBounds.mMin->z;
3639
auto levelChunk = neighborhood.getExistingChunk(chunkPos);
3740

3841
auto seed = mSeed;
3942

4043
// 必须,需要给区块上锁
4144
auto lockChunk =
42-
levelChunk->getDimension().mPostProcessingManager->tryLock(levelChunk->getPosition(), neighborhood);
45+
levelChunk->mDimension.mPostProcessingManager->tryLock(levelChunk->mPosition, neighborhood);
4346

4447
if (!lockChunk.has_value()) {
4548
return false;
4649
}
47-
BlockSource blockSource(getLevel(), neighborhood.getDimension(), neighborhood, false, true, true);
48-
auto chunkPosL = levelChunk->getPosition();
50+
BlockSource blockSource(*mLevel, *neighborhood.mDimension, neighborhood, false, true, true);
51+
auto chunkPosL = levelChunk->mPosition;
4952
random.mRandom->mObject.mSeed = seed;
5053
auto one = 2 * (random.nextInt() / 2) + 1;
5154
auto two = 2 * (random.nextInt() / 2) + 1;
52-
random.mRandom->mObject.mSeed = seed ^ (chunkPosL.x * one + chunkPosL.z * two);
55+
random.mRandom->mObject.mSeed = seed ^ (chunkPosL->x * one + chunkPosL->z * two);
5356
// 放置结构体,如果包含有某个结构的区块,就会放置loadChunk准备的结构
54-
WorldGenerator::postProcessStructureFeatures(blockSource, random, chunkPosL.x, chunkPosL.z);
57+
WorldGenerator::postProcessStructureFeatures(blockSource, random, chunkPosL->x, chunkPosL->z);
5558
// 处理其它单体结构,比如沉船,这里不是必须
56-
WorldGenerator::postProcessStructures(blockSource, random, chunkPosL.x, chunkPosL.z);
59+
WorldGenerator::postProcessStructures(blockSource, random, chunkPosL->x, chunkPosL->z);
5760
// 1.21.50.10 起,有更改,需添加以下调用
5861
levelChunk->finalizePostProcessing();
5962
return true;
6063
}
6164

6265
void FlatVillageGenerator::loadChunk(LevelChunk& levelchunk, bool forceImmediateReplacementDataLoad) {
63-
auto chunkPos = levelchunk.getPosition();
66+
auto chunkPos = levelchunk.mPosition;
6467

6568
auto blockPos = BlockPos(chunkPos, 0);
6669
DividedPos2d<4> dividedPos2D;
@@ -70,7 +73,7 @@ void FlatVillageGenerator::loadChunk(LevelChunk& levelchunk, bool forceImmediate
7073
// 处理其它单体结构,比如沉船,这里不是必须
7174
// WorldGenerator::preProcessStructures(getDimension(), chunkPos, getBiomeSource());
7275
// 准备要放置的结构,如果是某个某个结构的区块,就会准备结构
73-
WorldGenerator::prepareStructureFeatureBlueprints(getDimension(), chunkPos, getBiomeSource(), *this);
76+
WorldGenerator::prepareStructureFeatureBlueprints(*mDimension, chunkPos, getBiomeSource(), *this);
7477

7578
// 这里并没有放置结构,只有单纯基本地形
7679
levelchunk.setBlockVolume(mPrototype, 0);
@@ -79,7 +82,8 @@ void FlatVillageGenerator::loadChunk(LevelChunk& levelchunk, bool forceImmediate
7982
ChunkLocalNoiseCache chunkLocalNoiseCache(dividedPos2D, 8);
8083
mBiomeSource->fillBiomes(levelchunk, chunkLocalNoiseCache);
8184
levelchunk.setSaved();
82-
levelchunk.changeState(ChunkState::Generating, ChunkState::Generated);
85+
auto loadState = ChunkState::Generating;
86+
levelchunk.mLoadState->compare_exchange_weak(loadState, ChunkState::Generated);
8387
}
8488

8589
std::optional<short> FlatVillageGenerator::getPreliminarySurfaceLevel(DividedPos2d<4> worldPos) const {

src/test/generator/generator-custom-structure/CustomStructure.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
namespace custom_structure {
2828

2929
void CustomJigsawStructureBlockRules::initialize(JigsawStructureRegistry& registry) {
30-
auto& jigsawBlockRulesRegistry = registry.getJigsawStructureBlockRulesRegistry();
30+
auto& jigsawBlockRulesRegistry = registry.mUnk807a76.as<JigsawStructureBlockRulesRegistry>();
3131
// auto& DefaultBlockState =
3232
// BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::PolishedBlackstoneBricks(), 1);
3333
auto& resultBlock = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::RedstoneBlock(), 1);
@@ -40,7 +40,6 @@ void CustomJigsawStructureBlockRules::initialize(JigsawStructureRegistry& regist
4040

4141
auto blockRule =
4242
std::make_unique<StructurePoolBlockRule>(std::move(sourceBlock), std::move(targetBlock), &resultBlock);
43-
4443
auto ruleList = std::make_unique<std::vector<std::unique_ptr<StructurePoolBlockRule>>>();
4544

4645
ruleList->push_back(std::move(blockRule));
@@ -53,8 +52,8 @@ void CustomJigsawStructureElements::initialize(
5352
FeatureRegistry& featureRegistry,
5453
JigsawStructureRegistry& jigsawRegistry
5554
) {
56-
auto& jigsawBlockRulesRegistry = jigsawRegistry.getJigsawStructureBlockRulesRegistry();
57-
auto& jigsawStructureElementRegistry = jigsawRegistry.getJigsawStructureElementRegistry();
55+
auto& jigsawBlockRulesRegistry = jigsawRegistry.mUnk807a76.as<JigsawStructureBlockRulesRegistry>();
56+
auto& jigsawStructureElementRegistry = jigsawRegistry.mUnk8230cc.as<JigsawStructureElementRegistry>();
5857
auto ruleList = jigsawBlockRulesRegistry.lookupByName("custom:custom_structure_block_rule");
5958
std::vector<std::unique_ptr<StructurePoolBlockTagRule>> blockTag{};
6059
std::vector<std::unique_ptr<StructurePoolActorRule>> actorRule{};
@@ -109,7 +108,7 @@ void CustomJigsawStructure::initialize(
109108
) {
110109
CustomJigsawStructureBlockRules::initialize(registry);
111110
CustomJigsawStructureElements::initialize(manager, featureRegistry, registry);
112-
auto& jigsawStructureElementRegistry = registry.getJigsawStructureElementRegistry();
111+
auto& jigsawStructureElementRegistry = registry.mUnk8230cc.as<JigsawStructureElementRegistry>();
113112

114113
std::vector<std::pair<StructurePoolElement const*, int>> templates_room{
115114
{jigsawStructureElementRegistry.lookupByName("mike:21room"), 1}

src/test/generator/generator-custom-structure/dimension/CustomStructureDimension.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,55 @@ CompoundTag CustomStructureDimension::generateNewData() { return {}; }
4242
std::unique_ptr<WorldGenerator>
4343
CustomStructureDimension::createGenerator(br::worldgen::StructureSetRegistry const& structureSetRegistry) {
4444
std::unique_ptr<WorldGenerator> worldGenerator;
45-
uint seed = 2024;
46-
auto& levelData = getLevel().getLevelData();
45+
uint seed = 2025;
46+
auto& levelData = mLevel.getLevelData();
4747

4848
// 实例化我们写的Generator类
4949
worldGenerator = std::make_unique<custom_structure_generator::CustomStructureGenerator>(
5050
*this,
5151
seed,
52-
levelData.getFlatWorldGeneratorOptions()
52+
levelData.mFlatworldGeneratorOptions
5353
);
5454
// structureSetRegistry里面仅有的土径结构村庄生成需要用到,所以我们拿一下
5555
std::vector<std::shared_ptr<const br::worldgen::StructureSet>> structureMap;
5656
for (auto iter = structureSetRegistry.mStructureSets->begin(); iter != structureSetRegistry.mStructureSets->end(); iter++) {
5757
structureMap.emplace_back(iter->second);
5858
}
59-
worldGenerator->getStructureFeatureRegistry().mGeneratorState->mSeed = seed;
60-
worldGenerator->getStructureFeatureRegistry().mGeneratorState->mSeed64 =
59+
worldGenerator->mStructureFeatureRegistry->mGeneratorState->mSeed = seed;
60+
worldGenerator->mStructureFeatureRegistry->mGeneratorState->mSeed64 =
6161
LevelSeed64(seed);
6262

6363
// 这个就相当于在这个生成器里注册结构了
6464
// VillageFeature的第二第三个参数是村庄之间的最大间隔与最小间隔
65-
worldGenerator->getStructureFeatureRegistry().mStructureFeatures->emplace_back(
65+
worldGenerator->mStructureFeatureRegistry->mStructureFeatures->emplace_back(
6666
std::make_unique<VillageFeature>(seed, 34, 8)
6767
);
68-
worldGenerator->getStructureFeatureRegistry().mStructureFeatures->emplace_back(
68+
worldGenerator->mStructureFeatureRegistry->mStructureFeatures->emplace_back(
6969
std::make_unique<custom_structure::CustomStructureFeature>(seed)
7070
);
7171
// 此为必须,一些结构生成相关
72-
worldGenerator->getStructureFeatureRegistry().mGeneratorState =
72+
worldGenerator->mStructureFeatureRegistry->mGeneratorState =
7373
br::worldgen::ChunkGeneratorStructureState::createFlat(seed, worldGenerator->getBiomeSource(), structureMap);
7474

7575
return std::move(worldGenerator);
7676
}
7777

7878
void CustomStructureDimension::upgradeLevelChunk(ChunkSource& cs, LevelChunk& lc, LevelChunk& generatedChunk) {
79-
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false);
79+
auto blockSource = BlockSource(static_cast<Level&>(mLevel), *this, cs, false, true, false);
8080
VanillaLevelChunkUpgrade::_upgradeLevelChunkViaMetaData(lc, generatedChunk, blockSource);
8181
VanillaLevelChunkUpgrade::_upgradeLevelChunkLegacy(lc, blockSource);
8282
}
8383

8484
void CustomStructureDimension::fixWallChunk(ChunkSource& cs, LevelChunk& lc) {
85-
auto blockSource = BlockSource(getLevel(), *this, cs, false, true, false);
85+
auto blockSource = BlockSource(static_cast<Level&>(mLevel), *this, cs, false, true, false);
8686
VanillaLevelChunkUpgrade::fixWallChunk(lc, blockSource);
8787
}
8888

8989
bool CustomStructureDimension::levelChunkNeedsUpgrade(LevelChunk const& lc) const {
9090
return VanillaLevelChunkUpgrade::levelChunkNeedsUpgrade(lc);
9191
}
9292
void CustomStructureDimension::_upgradeOldLimboEntity(CompoundTag& tag, ::LimboEntitiesVersion vers) {
93-
auto isTemplate = getLevel().getLevelData().isFromWorldTemplate();
93+
auto isTemplate = mLevel.getLevelData().mIsFromLockedTemplate;
9494
return VanillaLevelChunkUpgrade::upgradeOldLimboEntity(tag, vers, isTemplate);
9595
}
9696

@@ -106,7 +106,7 @@ Vec3 CustomStructureDimension::translatePosAcrossDimension(Vec3 const& fromPos,
106106
topos,
107107
fromId,
108108
mId,
109-
getLevel().getDimensionConversionData()
109+
mLevel.getDimensionConversionData()
110110
);
111111
constexpr auto clampVal = 32000000.0f - 128.0f;
112112

@@ -118,6 +118,6 @@ Vec3 CustomStructureDimension::translatePosAcrossDimension(Vec3 const& fromPos,
118118

119119
short CustomStructureDimension::getCloudHeight() const { return 192; }
120120

121-
bool CustomStructureDimension::hasPrecipitationFog() const { return true; }
121+
// bool CustomStructureDimension::hasPrecipitationFog() const { return true; }
122122

123123
} // namespace custom_structure_dimension

src/test/generator/generator-custom-structure/dimension/CustomStructureDimension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CustomStructureDimension : public Dimension {
4141
short getCloudHeight() const override;
4242

4343
// 非必要。下雨时,可视范围的更改
44-
bool hasPrecipitationFog() const override;
44+
// bool hasPrecipitationFog() const override;
4545
};
4646

4747
} // namespace custom_structure_dimension

0 commit comments

Comments
 (0)