diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/VillageFeature.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/VillageFeature.cpp')
| -rw-r--r-- | Minecraft.World/VillageFeature.cpp | 186 |
1 files changed, 115 insertions, 71 deletions
diff --git a/Minecraft.World/VillageFeature.cpp b/Minecraft.World/VillageFeature.cpp index be724be6..82974c7b 100644 --- a/Minecraft.World/VillageFeature.cpp +++ b/Minecraft.World/VillageFeature.cpp @@ -5,6 +5,9 @@ #include "net.minecraft.world.level.biome.h" #include "net.minecraft.world.level.dimension.h" +const wstring VillageFeature::OPTION_SIZE_MODIFIER = L"size"; +const wstring VillageFeature::OPTION_SPACING = L"distance"; + vector<Biome *> VillageFeature::allowedBiomes; void VillageFeature::staticCtor() @@ -13,67 +16,88 @@ void VillageFeature::staticCtor() allowedBiomes.push_back( Biome::desert ); } - -VillageFeature::VillageFeature(int villageSizeModifier, int iXZSize) : StructureFeature(), villageSizeModifier(villageSizeModifier) +void VillageFeature::_init(int iXZSize) { + villageSizeModifier = 0; + townSpacing = 32; + minTownSeparation = 8; + m_iXZSize=iXZSize; } -bool VillageFeature::isFeatureChunk(int x, int z,bool bIsSuperflat) +VillageFeature::VillageFeature(int iXZSize) { - int townSpacing; + _init(iXZSize); +} -#ifdef _LARGE_WORLDS - if(level->dimension->getXZSize() > 128) - { - townSpacing = 32; - } - else -#endif - if(bIsSuperflat) - { - townSpacing= 32; - } - else - { - townSpacing= 16;// 4J change 32; - } +VillageFeature::VillageFeature(unordered_map<wstring, wstring> options, int iXZSize) +{ + _init(iXZSize); - int minTownSeparation = 8; - - int xx = x; - int zz = z; - if (x < 0) x -= townSpacing - 1; - if (z < 0) z -= townSpacing - 1; - - int xCenterTownChunk = x / townSpacing; - int zCenterTownChunk = z / townSpacing; - Random *r = level->getRandomFor(xCenterTownChunk, zCenterTownChunk, 10387312); - xCenterTownChunk *= townSpacing; - zCenterTownChunk *= townSpacing; - xCenterTownChunk += r->nextInt(townSpacing - minTownSeparation); - zCenterTownChunk += r->nextInt(townSpacing - minTownSeparation); - x = xx; - z = zz; - - bool forcePlacement = false; - LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions(); - if( levelGenOptions != NULL ) + for (AUTO_VAR(it,options.begin()); it != options.end(); ++it) { - forcePlacement = levelGenOptions->isFeatureChunk(x,z,eFeature_Village); + if (it->first.compare(OPTION_SIZE_MODIFIER) == 0) + { + villageSizeModifier = Mth::getInt(it->second, villageSizeModifier, 0); + } + else if (it->first.compare(OPTION_SPACING) == 0) + { + townSpacing = Mth::getInt(it->second, townSpacing, minTownSeparation + 1); + } } +} - if (forcePlacement || (x == xCenterTownChunk && z == zCenterTownChunk) ) - { - bool biomeOk = level->getBiomeSource()->containsOnly(x * 16 + 8, z * 16 + 8, 0, allowedBiomes); - if (biomeOk) +wstring VillageFeature::getFeatureName() +{ + return L"Village"; +} + +bool VillageFeature::isFeatureChunk(int x, int z,bool bIsSuperflat) +{ + int townSpacing = this->townSpacing; + + if(!bIsSuperflat +#ifdef _LARGE_WORLDS + && level->dimension->getXZSize() < 128 +#endif + ) + { + townSpacing= 16;// 4J change 32; + } + + int xx = x; + int zz = z; + if (x < 0) x -= townSpacing - 1; + if (z < 0) z -= townSpacing - 1; + + int xCenterTownChunk = x / townSpacing; + int zCenterTownChunk = z / townSpacing; + Random *r = level->getRandomFor(xCenterTownChunk, zCenterTownChunk, 10387312); + xCenterTownChunk *= townSpacing; + zCenterTownChunk *= townSpacing; + xCenterTownChunk += r->nextInt(townSpacing - minTownSeparation); + zCenterTownChunk += r->nextInt(townSpacing - minTownSeparation); + x = xx; + z = zz; + + bool forcePlacement = false; + LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions(); + if( levelGenOptions != NULL ) { - //app.DebugPrintf("Biome ok for Village at %d, %d\n",(x * 16 + 8),(z * 16 + 8)); - return true; - } - } + forcePlacement = levelGenOptions->isFeatureChunk(x,z,eFeature_Village); + } - return false; + if (forcePlacement || (x == xCenterTownChunk && z == zCenterTownChunk) ) + { + bool biomeOk = level->getBiomeSource()->containsOnly(x * 16 + 8, z * 16 + 8, 0, allowedBiomes); + if (biomeOk) + { + //app.DebugPrintf("Biome ok for Village at %d, %d\n",(x * 16 + 8),(z * 16 + 8)); + return true; + } + } + + return false; } StructureStart *VillageFeature::createStructureStart(int x, int z) @@ -84,51 +108,58 @@ StructureStart *VillageFeature::createStructureStart(int x, int z) return new VillageStart(level, random, x, z, villageSizeModifier, m_iXZSize); } +VillageFeature::VillageStart::VillageStart() +{ + valid = false; // 4J added initialiser + m_iXZSize = 0; + // for reflection +} + VillageFeature::VillageStart::VillageStart(Level *level, Random *random, int chunkX, int chunkZ, int villageSizeModifier, int iXZSize) { valid = false; // 4J added initialiser m_iXZSize=iXZSize; - list<VillagePieces::PieceWeight *> *pieceSet = VillagePieces::createPieceSet(random, villageSizeModifier); + list<VillagePieces::PieceWeight *> *pieceSet = VillagePieces::createPieceSet(random, villageSizeModifier); - VillagePieces::StartPiece *startRoom = new VillagePieces::StartPiece(level->getBiomeSource(), 0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2, pieceSet, villageSizeModifier, level); + VillagePieces::StartPiece *startRoom = new VillagePieces::StartPiece(level->getBiomeSource(), 0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2, pieceSet, villageSizeModifier, level); pieces.push_back(startRoom); - startRoom->addChildren(startRoom, &pieces, random); + startRoom->addChildren(startRoom, &pieces, random); - vector<StructurePiece *> *pendingRoads = &startRoom->pendingRoads; - vector<StructurePiece *> *pendingHouses = &startRoom->pendingHouses; - while (!pendingRoads->empty() || !pendingHouses->empty()) + vector<StructurePiece *> *pendingRoads = &startRoom->pendingRoads; + vector<StructurePiece *> *pendingHouses = &startRoom->pendingHouses; + while (!pendingRoads->empty() || !pendingHouses->empty()) { - // prioritize roads - if (pendingRoads->empty()) + // prioritize roads + if (pendingRoads->empty()) { - int pos = random->nextInt((int)pendingHouses->size()); + int pos = random->nextInt((int)pendingHouses->size()); AUTO_VAR(it, pendingHouses->begin() + pos); - StructurePiece *structurePiece = *it; + StructurePiece *structurePiece = *it; pendingHouses->erase(it); - structurePiece->addChildren(startRoom, &pieces, random); - } + structurePiece->addChildren(startRoom, &pieces, random); + } else { - int pos = random->nextInt((int)pendingRoads->size()); + int pos = random->nextInt((int)pendingRoads->size()); AUTO_VAR(it, pendingRoads->begin() + pos); - StructurePiece *structurePiece = *it; + StructurePiece *structurePiece = *it; pendingRoads->erase(it); - structurePiece->addChildren(startRoom, &pieces, random); - } - } + structurePiece->addChildren(startRoom, &pieces, random); + } + } - calculateBoundingBox(); + calculateBoundingBox(); - int count = 0; + int count = 0; for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ ) { StructurePiece *piece = *it; - if (dynamic_cast<VillagePieces::VillageRoadPiece *>(piece) == NULL) + if (dynamic_cast<VillagePieces::VillageRoadPiece *>(piece) == NULL) { - count++; - } + count++; + } } valid = count > 2; } @@ -142,3 +173,16 @@ bool VillageFeature::VillageStart::isValid() } return valid; } + +void VillageFeature::VillageStart::addAdditonalSaveData(CompoundTag *tag) +{ + StructureStart::addAdditonalSaveData(tag); + + tag->putBoolean(L"Valid", valid); +} + +void VillageFeature::VillageStart::readAdditonalSaveData(CompoundTag *tag) +{ + StructureStart::readAdditonalSaveData(tag); + valid = tag->getBoolean(L"Valid"); +}
\ No newline at end of file |
