diff --git a/Minecraft.World/MesaBiome.cpp b/Minecraft.World/MesaBiome.cpp index dc4fa951..a8db7952 100644 --- a/Minecraft.World/MesaBiome.cpp +++ b/Minecraft.World/MesaBiome.cpp @@ -18,9 +18,9 @@ #undef max #undef min -MesaBiome::MesaBiome(int id, bool mesaPlateau, bool hasTrees) : Biome(id) +MesaBiome::MesaBiome(int id, bool isBryce, bool hasTrees) : Biome(id) { - this->isMesaPlateau = mesaPlateau; + this->isBryce = isBryce; this->hasTrees = hasTrees; this->setNoRain(); @@ -33,8 +33,8 @@ MesaBiome::MesaBiome(int id, bool mesaPlateau, bool hasTrees) : Biome(id) this->lastSeed = INVALID_SEED; this->clayBands = nullptr; + this->cliffNoise = nullptr; this->pillarNoise = nullptr; - this->pillarRoofNoise = nullptr; this->clayBandsOffsetNoise = nullptr; if (decorator) @@ -52,10 +52,10 @@ MesaBiome::~MesaBiome() delete[] clayBands; clayBands = nullptr; + delete cliffNoise; + cliffNoise = nullptr; delete pillarNoise; pillarNoise = nullptr; - delete pillarRoofNoise; - pillarRoofNoise = nullptr; delete clayBandsOffsetNoise; clayBandsOffsetNoise = nullptr; } @@ -215,49 +215,36 @@ void MesaBiome::buildSurfaceAtDefault(Level* level, Random* random, if (!clayBands || lastSeed != seed) generateBands(seed); - if (!pillarNoise || !pillarRoofNoise || lastSeed != seed) + if (!cliffNoise || !pillarNoise || lastSeed != seed) { Random noiseRand(seed); + delete cliffNoise; delete pillarNoise; - delete pillarRoofNoise; - - pillarNoise = new PerlinSimplexNoise(&noiseRand, 4); - pillarRoofNoise = new PerlinSimplexNoise(&noiseRand, 1); + cliffNoise = new PerlinSimplexNoise(&noiseRand, 4); + pillarNoise = new PerlinSimplexNoise(&noiseRand, 1); } lastSeed = seed; - const int localX = x & 0xF; - const int localZ = z & 0xF; - double pillarHeight = 0.0; - - if (isMesaPlateau&& id == Biome::mesaBryce->id) -{ - double nx = static_cast((x & ~0xF) + localZ); - double nz = static_cast((z & ~0xF) + localX); - - - double roofVal = pillarNoise->getValue(nx * 0.25, nz * 0.25); - double d0 = std::abs(noiseVal) - roofVal; - - - if (d0 > 0.0) + if (isBryce) { - - double pillarScale = pillarRoofNoise->getValue( - nx * 0.001953125, - nz * 0.001953125); + const double nx = static_cast((z & ~0xF) + (x & 0xF)); + const double nz = static_cast((x & ~0xF) + (z & 0xF)); + double cliff = std::min( + std::abs(noiseVal), + cliffNoise->getValue(nx * 0.25, nz * 0.25)); - - double scaled = std::ceil(std::abs(pillarScale) * 50.0); - double height = d0 * d0 * 2.5; - double cap = scaled + 14.0; - if (height > cap) height = cap; - pillarHeight = height + 64.0; + if (cliff > 0.0) + { + double pillarScale = std::abs( + pillarNoise->getValue(nx * 0.001953125, nz * 0.001953125)); + double height = cliff * cliff * 2.5; + double cap = std::ceil(pillarScale * 50.0) + 14.0; + pillarHeight = std::min(height, cap) + 64.0; + } } -} const int localX2 = x & 0xF; const int localZ2 = z & 0xF; @@ -392,7 +379,7 @@ MesaBiome* MesaBiome::createMutatedCopy(int newId) bool isMesaBase = (this->id == Biome::mesa->id); - MesaBiome* copy = new MesaBiome(newId, isMesaBase, this->hasTrees); + MesaBiome* copy = new MesaBiome(newId, newId == Biome::mesaBryce->id, this->hasTrees); if (!isMesaBase) { diff --git a/Minecraft.World/MesaBiome.h b/Minecraft.World/MesaBiome.h index d0df393d..c3cd2eff 100644 --- a/Minecraft.World/MesaBiome.h +++ b/Minecraft.World/MesaBiome.h @@ -33,7 +33,7 @@ public: static constexpr int64_t INVALID_SEED = 0LL; - MesaBiome(int id, bool isMesaPlateau, bool hasTrees); + MesaBiome(int id, bool isBryce, bool hasTrees); virtual ~MesaBiome(); virtual void decorate(Level* level, Random* random, int xo, int zo) override; @@ -50,13 +50,13 @@ private: void generateBands(int64_t seed); BandEntry getBand(int x, int y, int z); - bool isMesaPlateau; //0x104 + bool isBryce; //0x104 bool hasTrees; //0x105 int64_t lastSeed; //0xF0/0xF4 BandEntry* clayBands; //0xE8 - PerlinSimplexNoise* pillarNoise; //0xF8 - PerlinSimplexNoise* pillarRoofNoise; //0xFC + PerlinSimplexNoise* cliffNoise; + PerlinSimplexNoise* pillarNoise; PerlinSimplexNoise* clayBandsOffsetNoise; //0x100 }; \ No newline at end of file diff --git a/Minecraft.World/MineShaftFeature.cpp b/Minecraft.World/MineShaftFeature.cpp index b331d7e6..ef996f62 100644 --- a/Minecraft.World/MineShaftFeature.cpp +++ b/Minecraft.World/MineShaftFeature.cpp @@ -6,6 +6,16 @@ const wstring MineShaftFeature::OPTION_CHANCE = L"chance"; +namespace +{ +bool isMesaBiome(Biome* biome) +{ + return biome == Biome::mesa || biome == Biome::mesaPlateauF || biome == Biome::mesaPlateau + || biome == Biome::mesaBryce || biome == Biome::mesaPlateauFM || biome == Biome::mesaPlateauM; +} + +} + MineShaftFeature::MineShaftFeature() { chance = 0.01; @@ -39,14 +49,31 @@ bool MineShaftFeature::isFeatureChunk(int x, int z, bool bIsSuperflat) } double effectiveChance = chance; + bool mesaBiome = false; if (level != nullptr) { - Biome *b = level->getBiome(x * 16, z * 16); - if (b == Biome::mesa || b == Biome::mesaPlateauF || b == Biome::mesaPlateau || - b == Biome::mesaBryce || b == Biome::mesaPlateauFM || b == Biome::mesaPlateauM) + Biome *b = level->getBiome(x * 16 + 8, z * 16 + 8); + mesaBiome = isMesaBiome(b); + if (mesaBiome) effectiveChance = 0.9; } + if (mesaBiome && !forcePlacement) + { + const int originX = (x << 4) + 2; + const int originZ = (z << 4) + 2; + for (const auto& entry : cachedStructures) + { + StructureStart* start = entry.second; + BoundingBox* box = start->getBoundingBox(); + if (start->isValid() && box != nullptr + && box->intersects(originX, originZ, originX + 12, originZ + 12)) + { + return false; + } + } + } + return forcePlacement || (random->nextDouble() < effectiveChance && random->nextInt(80) < max(abs(x), abs(z))); } diff --git a/Minecraft.World/MineShaftPieces.cpp b/Minecraft.World/MineShaftPieces.cpp index d8c005c0..bed1b6a1 100644 --- a/Minecraft.World/MineShaftPieces.cpp +++ b/Minecraft.World/MineShaftPieces.cpp @@ -12,6 +12,50 @@ WeighedTreasureArray MineShaftPieces::smallTreasureItems;; +namespace +{ +int getMineShaftPlanksData(bool mesaWood) +{ + return mesaWood ? 5 : 0; +} + +int getMineShaftFenceId(bool mesaWood) +{ + return mesaWood ? Tile::dark_oak_fence_Id : Tile::fence_Id; +} + +bool isMesaTerrainBlock(int block) +{ + return block == Tile::stone_Id || block == Tile::dirt_Id || block == Tile::sand_Id + || block == Tile::gravel_Id || block == Tile::sandstone_Id || block == Tile::clay_Id + || block == Tile::stained_hardened_clay_Id || block == Tile::hardened_clay_Id + || block == Tile::red_sandstone_Id; +} + +bool hasSupportAbove(Level* level, StructurePiece* piece, BoundingBox* chunkBB, + int x0, int x1, int y, int z, bool mesaWood) +{ + bool checkedSupport = false; + for (int x = x0; x <= x1; ++x) + { + const int worldX = piece->getWorldX(x, z); + const int worldY = piece->getWorldY(y + 1); + const int worldZ = piece->getWorldZ(x, z); + if (!chunkBB->isInside(worldX, worldY, worldZ)) + { + continue; + } + checkedSupport = true; + const int block = piece->getBlock(level, x, y + 1, z, chunkBB); + if (block == 0 || (mesaWood && !isMesaTerrainBlock(block))) + { + return false; + } + } + return checkedSupport; +} +} + void MineShaftPieces::staticCtor() { smallTreasureItems = WeighedTreasureArray(13); @@ -39,7 +83,7 @@ void MineShaftPieces::loadStatic() StructureFeatureIO::setPieceId( eStructurePiece_MineShaftStairs, MineShaftStairs::Create, L"MSStairs"); } -StructurePiece *MineShaftPieces::createRandomShaftPiece(list *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth) +StructurePiece *MineShaftPieces::createRandomShaftPiece(list *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth, bool mesaWood) { int randomSelection = random->nextInt(100); if (randomSelection >= 80) @@ -47,7 +91,7 @@ StructurePiece *MineShaftPieces::createRandomShaftPiece(list * BoundingBox *crossingBox = MineShaftCrossing::findCrossing(pieces, random, footX, footY, footZ, direction); if (crossingBox != nullptr) { - return new MineShaftCrossing(genDepth, random, crossingBox, direction); + return new MineShaftCrossing(genDepth, random, crossingBox, direction, mesaWood); } } else if (randomSelection >= 70) @@ -55,7 +99,7 @@ StructurePiece *MineShaftPieces::createRandomShaftPiece(list * BoundingBox *stairsBox = MineShaftStairs::findStairs(pieces, random, footX, footY, footZ, direction); if (stairsBox != nullptr) { - return new MineShaftPieces::MineShaftStairs(genDepth, random, stairsBox, direction); + return new MineShaftPieces::MineShaftStairs(genDepth, random, stairsBox, direction, mesaWood); } } else @@ -63,7 +107,7 @@ StructurePiece *MineShaftPieces::createRandomShaftPiece(list * BoundingBox *corridorBox = MineShaftCorridor::findCorridorSize(pieces, random, footX, footY, footZ, direction); if (corridorBox != nullptr) { - return new MineShaftCorridor(genDepth, random, corridorBox, direction); + return new MineShaftCorridor(genDepth, random, corridorBox, direction, mesaWood); } } @@ -81,7 +125,8 @@ StructurePiece *MineShaftPieces::generateAndAddPiece(StructurePiece *startPiece, return nullptr; } - StructurePiece *newPiece = createRandomShaftPiece(pieces, random, footX, footY, footZ, direction, depth + 1); + const bool mesaWood = static_cast(startPiece)->usesMesaWood(); + StructurePiece *newPiece = createRandomShaftPiece(pieces, random, footX, footY, footZ, direction, depth + 1, mesaWood); if (newPiece != nullptr) { MemSect(50); @@ -94,11 +139,12 @@ StructurePiece *MineShaftPieces::generateAndAddPiece(StructurePiece *startPiece, MineShaftPieces::MineShaftRoom::MineShaftRoom() { - // for reflection + mesaWood = false; } -MineShaftPieces::MineShaftRoom::MineShaftRoom(int genDepth, Random *random, int west, int north) : StructurePiece(genDepth) +MineShaftPieces::MineShaftRoom::MineShaftRoom(int genDepth, Random *random, int west, int north, bool mesaWood) : StructurePiece(genDepth) { + this->mesaWood = mesaWood; boundingBox = new BoundingBox(west, 50, north, west + 7 + random->nextInt(6), 54 + random->nextInt(6), north + 7 + random->nextInt(6)); } @@ -216,6 +262,7 @@ bool MineShaftPieces::MineShaftRoom::postProcess(Level *level, Random *random, B void MineShaftPieces::MineShaftRoom::addAdditonalSaveData(CompoundTag *tag) { + tag->putBoolean(L"Mesa", mesaWood); ListTag *entrances = new ListTag(L"Entrances"); for (auto& bb : childEntranceBoxes) { @@ -226,6 +273,7 @@ void MineShaftPieces::MineShaftRoom::addAdditonalSaveData(CompoundTag *tag) void MineShaftPieces::MineShaftRoom::readAdditonalSaveData(CompoundTag *tag) { + mesaWood = tag->getBoolean(L"Mesa"); ListTag *entrances = (ListTag *) tag->getList(L"Entrances"); for (int i = 0; i < entrances->size(); i++) { @@ -235,7 +283,7 @@ void MineShaftPieces::MineShaftRoom::readAdditonalSaveData(CompoundTag *tag) MineShaftPieces::MineShaftCorridor::MineShaftCorridor() { - // for reflection + mesaWood = false; } void MineShaftPieces::MineShaftCorridor::addAdditonalSaveData(CompoundTag *tag) @@ -244,6 +292,7 @@ void MineShaftPieces::MineShaftCorridor::addAdditonalSaveData(CompoundTag *tag) tag->putBoolean(L"sc", spiderCorridor); tag->putBoolean(L"hps", hasPlacedSpider); tag->putInt(L"Num", numSections); + tag->putBoolean(L"Mesa", mesaWood); } void MineShaftPieces::MineShaftCorridor::readAdditonalSaveData(CompoundTag *tag) @@ -252,11 +301,13 @@ void MineShaftPieces::MineShaftCorridor::readAdditonalSaveData(CompoundTag *tag) spiderCorridor = tag->getBoolean(L"sc"); hasPlacedSpider = tag->getBoolean(L"hps"); numSections = tag->getInt(L"Num"); + mesaWood = tag->getBoolean(L"Mesa"); } -MineShaftPieces::MineShaftCorridor::MineShaftCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction) +MineShaftPieces::MineShaftCorridor::MineShaftCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction, bool mesaWood) : StructurePiece(genDepth) { + this->mesaWood = mesaWood; orientation = direction; boundingBox = corridorBox; hasRails = random->nextInt(3) == 0; @@ -457,6 +508,8 @@ bool MineShaftPieces::MineShaftCorridor::postProcess(Level *level, Random *rando const int y0 = 0; const int y1 = DEFAULT_SHAFT_HEIGHT - 1; const int length = (numSections * DEFAULT_SHAFT_LENGTH) - 1; + const int planksData = getMineShaftPlanksData(mesaWood); + const int fenceId = getMineShaftFenceId(mesaWood); // corridor air generateBox(level, chunkBB, x0, 0, y0, x1, y1 - 1, length, 0, 0, false); @@ -473,17 +526,19 @@ bool MineShaftPieces::MineShaftCorridor::postProcess(Level *level, Random *rando int z = 2 + section * DEFAULT_SHAFT_LENGTH; - // 4J-PB - Bringing forward the changes in 1.2.3 - generateBox(level, chunkBB, x0, y0, z, x0, y1 - 1, z, Tile::fence_Id, 0, false); - generateBox(level, chunkBB, x1, y0, z, x1, y1 - 1, z, Tile::fence_Id, 0, false); - if (random->nextInt(4) == 0) + if (hasSupportAbove(level, this, chunkBB, x0, x1, y1, z, mesaWood)) { - generateBox(level, chunkBB, x0, y1, z, x0, y1, z, Tile::planks_Id, 0, false); - generateBox(level, chunkBB, x1, y1, z, x1, y1, z, Tile::planks_Id, 0, false); - } - else - { - generateBox(level, chunkBB, x0, y1, z, x1, y1, z, Tile::planks_Id, 0, false); + generateBox(level, chunkBB, x0, y0, z, x0, y1 - 1, z, fenceId, 0, fenceId, 0, false); + generateBox(level, chunkBB, x1, y0, z, x1, y1 - 1, z, fenceId, 0, fenceId, 0, false); + if (random->nextInt(4) == 0) + { + generateBox(level, chunkBB, x0, y1, z, x0, y1, z, Tile::planks_Id, planksData, Tile::planks_Id, planksData, false); + generateBox(level, chunkBB, x1, y1, z, x1, y1, z, Tile::planks_Id, planksData, Tile::planks_Id, planksData, false); + } + else + { + generateBox(level, chunkBB, x0, y1, z, x1, y1, z, Tile::planks_Id, planksData, Tile::planks_Id, planksData, false); + } } maybeGenerateBlock(level, chunkBB, random, .1f, x0, y1, z - 1, Tile::web_Id, 0); maybeGenerateBlock(level, chunkBB, random, .1f, x1, y1, z - 1, Tile::web_Id, 0); @@ -525,15 +580,17 @@ bool MineShaftPieces::MineShaftCorridor::postProcess(Level *level, Random *rando } } - // prevent air floating - for (int x = x0; x <= x1; x++) + if (planksData == 0) { - for (int z = 0; z <= length; z++) + for (int x = x0; x <= x1; x++) { - int block = getBlock(level, x, -1, z, chunkBB); - if (block == 0) + for (int z = 0; z <= length; z++) { - placeBlock(level, Tile::planks_Id, 0, x, -1, z, chunkBB); + int block = getBlock(level, x, -1, z, chunkBB); + if (block == 0) + { + placeBlock(level, Tile::planks_Id, planksData, x, -1, z, chunkBB); + } } } } @@ -555,23 +612,25 @@ bool MineShaftPieces::MineShaftCorridor::postProcess(Level *level, Random *rando MineShaftPieces::MineShaftCrossing::MineShaftCrossing() { - // for reflection + mesaWood = false; } void MineShaftPieces::MineShaftCrossing::addAdditonalSaveData(CompoundTag *tag) { tag->putBoolean(L"tf", isTwoFloored); tag->putInt(L"D", direction); + tag->putBoolean(L"Mesa", mesaWood); } void MineShaftPieces::MineShaftCrossing::readAdditonalSaveData(CompoundTag *tag) { isTwoFloored = tag->getBoolean(L"tf"); direction = tag->getInt(L"D"); + mesaWood = tag->getBoolean(L"Mesa"); } -MineShaftPieces::MineShaftCrossing::MineShaftCrossing(int genDepth, Random *random, BoundingBox *crossingBox, int direction) - : StructurePiece(genDepth), direction(direction), isTwoFloored( crossingBox->getYSpan() > DEFAULT_SHAFT_HEIGHT ) +MineShaftPieces::MineShaftCrossing::MineShaftCrossing(int genDepth, Random *random, BoundingBox *crossingBox, int direction, bool mesaWood) + : StructurePiece(genDepth), direction(direction), isTwoFloored( crossingBox->getYSpan() > DEFAULT_SHAFT_HEIGHT ), mesaWood(mesaWood) { boundingBox = crossingBox; } @@ -665,6 +724,7 @@ bool MineShaftPieces::MineShaftCrossing::postProcess(Level *level, Random *rando { return false; } + const int planksData = getMineShaftPlanksData(mesaWood); // corridor air if (isTwoFloored) @@ -682,22 +742,32 @@ bool MineShaftPieces::MineShaftCrossing::postProcess(Level *level, Random *rando } // support pillars - generateBox(level, chunkBB, boundingBox->x0 + 1, boundingBox->y0, boundingBox->z0 + 1, boundingBox->x0 + 1, boundingBox->y1, boundingBox->z0 + 1, Tile::planks_Id, 0, false); - generateBox(level, chunkBB, boundingBox->x0 + 1, boundingBox->y0, boundingBox->z1 - 1, boundingBox->x0 + 1, boundingBox->y1, boundingBox->z1 - 1, Tile::planks_Id, 0, false); - generateBox(level, chunkBB, boundingBox->x1 - 1, boundingBox->y0, boundingBox->z0 + 1, boundingBox->x1 - 1, boundingBox->y1, boundingBox->z0 + 1, Tile::planks_Id, 0, false); - generateBox(level, chunkBB, boundingBox->x1 - 1, boundingBox->y0, boundingBox->z1 - 1, boundingBox->x1 - 1, boundingBox->y1, boundingBox->z1 - 1, Tile::planks_Id, 0, false); - - // prevent air floating - // note: use world coordinates because the corridor hasn't defined - // orientation - for (int x = boundingBox->x0; x <= boundingBox->x1; x++) + const int supportXs[] = { boundingBox->x0 + 1, boundingBox->x0 + 1, boundingBox->x1 - 1, boundingBox->x1 - 1 }; + const int supportZs[] = { boundingBox->z0 + 1, boundingBox->z1 - 1, boundingBox->z0 + 1, boundingBox->z1 - 1 }; + for (int i = 0; i < 4; ++i) { - for (int z = boundingBox->z0; z <= boundingBox->z1; z++) + const int x = supportXs[i]; + const int z = supportZs[i]; + const int blockAbove = getBlock(level, x, boundingBox->y1 + 1, z, chunkBB); + if (blockAbove != 0 && (!mesaWood || isMesaTerrainBlock(blockAbove))) { - int block = getBlock(level, x, boundingBox->y0 - 1, z, chunkBB); - if (block == 0) + generateBox(level, chunkBB, x, boundingBox->y0, z, x, boundingBox->y1, z, + Tile::planks_Id, planksData, Tile::planks_Id, planksData, false); + } + } + + if (planksData == 0) + { + // The crossing has no orientation, so these are world coordinates. + for (int x = boundingBox->x0; x <= boundingBox->x1; x++) + { + for (int z = boundingBox->z0; z <= boundingBox->z1; z++) { - placeBlock(level, Tile::planks_Id, 0, x, boundingBox->y0 - 1, z, chunkBB); + int block = getBlock(level, x, boundingBox->y0 - 1, z, chunkBB); + if (block == 0) + { + placeBlock(level, Tile::planks_Id, planksData, x, boundingBox->y0 - 1, z, chunkBB); + } } } } @@ -707,22 +777,25 @@ bool MineShaftPieces::MineShaftCrossing::postProcess(Level *level, Random *rando MineShaftPieces::MineShaftStairs::MineShaftStairs() { - // for reflection + mesaWood = false; } -MineShaftPieces::MineShaftStairs::MineShaftStairs(int genDepth, Random *random, BoundingBox *stairsBox, int direction) : StructurePiece(genDepth) +MineShaftPieces::MineShaftStairs::MineShaftStairs(int genDepth, Random *random, BoundingBox *stairsBox, int direction, bool mesaWood) : StructurePiece(genDepth) { this->orientation = direction; + this->mesaWood = mesaWood; boundingBox = stairsBox; } void MineShaftPieces::MineShaftStairs::addAdditonalSaveData(CompoundTag *tag) { + tag->putBoolean(L"Mesa", mesaWood); } void MineShaftPieces::MineShaftStairs::readAdditonalSaveData(CompoundTag *tag) { + mesaWood = tag->getBoolean(L"Mesa"); } BoundingBox *MineShaftPieces::MineShaftStairs::findStairs(list *pieces, Random *random, int footX, int footY, int footZ, int direction) diff --git a/Minecraft.World/MineShaftPieces.h b/Minecraft.World/MineShaftPieces.h index af71da62..dfafaac1 100644 --- a/Minecraft.World/MineShaftPieces.h +++ b/Minecraft.World/MineShaftPieces.h @@ -15,7 +15,7 @@ public: static void loadStatic(); private: - static StructurePiece *createRandomShaftPiece(list *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth); + static StructurePiece *createRandomShaftPiece(list *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth, bool mesaWood); static StructurePiece *generateAndAddPiece(StructurePiece *startPiece, list *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth); /** @@ -31,11 +31,13 @@ public: private: list childEntranceBoxes; + bool mesaWood; public: MineShaftRoom(); - MineShaftRoom(int genDepth, Random *random, int west, int north); + MineShaftRoom(int genDepth, Random *random, int west, int north, bool mesaWood = false); ~MineShaftRoom(); + bool usesMesaWood() const { return mesaWood; } virtual void addChildren(StructurePiece *startPiece, list *pieces, Random *random); virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB); @@ -60,6 +62,7 @@ public: bool spiderCorridor; // was final bool hasPlacedSpider; int numSections; + bool mesaWood; public: MineShaftCorridor(); @@ -69,7 +72,7 @@ public: void readAdditonalSaveData(CompoundTag *tag); public: - MineShaftCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction); + MineShaftCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction, bool mesaWood = false); static BoundingBox *findCorridorSize(list *pieces, Random *random, int footX, int footY, int footZ, int direction); virtual void addChildren(StructurePiece *startPiece, list *pieces, Random *random); @@ -94,6 +97,7 @@ public: private: int direction; bool isTwoFloored; + bool mesaWood; public: MineShaftCrossing(); @@ -103,7 +107,7 @@ public: void readAdditonalSaveData(CompoundTag *tag); public: - MineShaftCrossing(int genDepth, Random *random, BoundingBox *crossingBox, int direction); + MineShaftCrossing(int genDepth, Random *random, BoundingBox *crossingBox, int direction, bool mesaWood = false); static BoundingBox *findCrossing(list *pieces, Random *random, int footX, int footY, int footZ, int direction); virtual void addChildren(StructurePiece *startPiece, list *pieces, Random *random); @@ -116,13 +120,15 @@ public: */ class MineShaftStairs : public StructurePiece { + private: + bool mesaWood; + public: static StructurePiece *Create() { return new MineShaftStairs(); } virtual EStructurePiece GetType() { return eStructurePiece_MineShaftStairs; } - public: MineShaftStairs(); - MineShaftStairs(int genDepth, Random *random, BoundingBox *stairsBox, int direction); + MineShaftStairs(int genDepth, Random *random, BoundingBox *stairsBox, int direction, bool mesaWood = false); protected: void addAdditonalSaveData(CompoundTag *tag); diff --git a/Minecraft.World/MineShaftStart.cpp b/Minecraft.World/MineShaftStart.cpp index eaf9f7c8..12da92f2 100644 --- a/Minecraft.World/MineShaftStart.cpp +++ b/Minecraft.World/MineShaftStart.cpp @@ -1,17 +1,134 @@ #include "stdafx.h" #include "net.minecraft.world.level.levelgen.structure.h" +#include "net.minecraft.world.level.biome.h" +#include "net.minecraft.world.level.tile.h" + +namespace +{ +bool isMesaBiome(Biome* biome) +{ + return biome == Biome::mesa || biome == Biome::mesaPlateauF || biome == Biome::mesaPlateau + || biome == Biome::mesaBryce || biome == Biome::mesaPlateauFM || biome == Biome::mesaPlateauM; +} + +bool isMesaTerrainBlock(int block) +{ + return block == Tile::stone_Id || block == Tile::dirt_Id || block == Tile::sand_Id + || block == Tile::gravel_Id || block == Tile::sandstone_Id || block == Tile::clay_Id + || block == Tile::stained_hardened_clay_Id || block == Tile::hardened_clay_Id + || block == Tile::red_sandstone_Id; +} + +bool hasMesaTerrainAboveOrBelow(Level* level, BoundingBox* pieceBox, BoundingBox* chunkBB) +{ + const int x0 = max(pieceBox->x0, chunkBB->x0); + const int x1 = min(pieceBox->x1, chunkBB->x1); + const int z0 = max(pieceBox->z0, chunkBB->z0); + const int z1 = min(pieceBox->z1, chunkBB->z1); + if (x0 > x1 || z0 > z1) + { + return false; + } + + const int aboveY = pieceBox->y1 + 1; + const int belowY = pieceBox->y0 - 1; + for (int x = x0; x <= x1; ++x) + { + for (int z = z0; z <= z1; ++z) + { + const bool terrainAbove = aboveY < Level::maxBuildHeight + && isMesaTerrainBlock(level->getTile(x, aboveY, z)); + const bool terrainBelow = belowY >= Level::minBuildHeight + && isMesaTerrainBlock(level->getTile(x, belowY, z)); + if (!terrainAbove && !terrainBelow) + { + return false; + } + } + } + return true; +} +} MineShaftStart::MineShaftStart() { - // for reflection + mesaWood = false; } MineShaftStart::MineShaftStart(Level *level, Random *random, int chunkX, int chunkZ) : StructureStart(chunkX, chunkZ) { - MineShaftPieces::MineShaftRoom *mineShaftRoom = new MineShaftPieces::MineShaftRoom(0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2); + Biome* biome = level->getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8); + mesaWood = isMesaBiome(biome); + MineShaftPieces::MineShaftRoom *mineShaftRoom = new MineShaftPieces::MineShaftRoom(0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2, mesaWood); pieces.push_back(mineShaftRoom); mineShaftRoom->addChildren(mineShaftRoom, &pieces, random); calculateBoundingBox(); - moveBelowSeaLevel(level, random, 10); + if (mesaWood) + { + const int yShift = level->getSeaLevel() - boundingBox->y1 + boundingBox->getYSpan() / 2 + 5; + boundingBox->move(0, yShift, 0); + for (auto& piece : pieces) + { + piece->getBoundingBox()->move(0, yShift, 0); + } + } + else + { + moveBelowSeaLevel(level, random, 10); + } +} + +void MineShaftStart::postProcess(Level *level, Random *random, BoundingBox *chunkBB) +{ + if (!mesaWood) + { + StructureStart::postProcess(level, random, chunkBB); + return; + } + + auto it = pieces.begin(); + while (it != pieces.end()) + { + StructurePiece* piece = *it; + BoundingBox* pieceBox = piece->getBoundingBox(); + if (!pieceBox->intersects(chunkBB)) + { + ++it; + continue; + } + + const int centerX = (max(pieceBox->x0, chunkBB->x0) + min(pieceBox->x1, chunkBB->x1)) / 2; + const int centerZ = (max(pieceBox->z0, chunkBB->z0) + min(pieceBox->z1, chunkBB->z1)) / 2; + if (!isMesaBiome(level->getBiome(centerX, centerZ)) + || !hasMesaTerrainAboveOrBelow(level, pieceBox, chunkBB)) + { + ++it; + continue; + } + + if (!piece->postProcess(level, random, chunkBB)) + { + it = pieces.erase(it); + } + else + { + ++it; + } + } +} + +void MineShaftStart::addAdditonalSaveData(CompoundTag *tag) +{ + tag->putBoolean(L"Mesa", mesaWood); +} + +void MineShaftStart::readAdditonalSaveData(CompoundTag *tag) +{ + mesaWood = tag->getBoolean(L"Mesa"); + if (!tag->contains(L"Mesa") && !pieces.empty()) + { + MineShaftPieces::MineShaftRoom* room = dynamic_cast(pieces.front()); + mesaWood = room != nullptr && room->usesMesaWood(); + } } \ No newline at end of file diff --git a/Minecraft.World/MineShaftStart.h b/Minecraft.World/MineShaftStart.h index 7afb9b62..b3e097d4 100644 --- a/Minecraft.World/MineShaftStart.h +++ b/Minecraft.World/MineShaftStart.h @@ -4,11 +4,18 @@ class MineShaftStart : public StructureStart { +private: + bool mesaWood; + public: static StructureStart *Create() { return new MineShaftStart(); } virtual EStructureStart GetType() { return eStructureStart_MineShaftStart; } -public: MineShaftStart(); MineShaftStart(Level *level, Random *random, int chunkX, int chunkZ); + virtual void postProcess(Level *level, Random *random, BoundingBox *chunkBB); + +protected: + virtual void addAdditonalSaveData(CompoundTag *tag); + virtual void readAdditonalSaveData(CompoundTag *tag); }; \ No newline at end of file diff --git a/Minecraft.World/StructureStart.h b/Minecraft.World/StructureStart.h index 72035367..de74a795 100644 --- a/Minecraft.World/StructureStart.h +++ b/Minecraft.World/StructureStart.h @@ -21,7 +21,7 @@ public: ~StructureStart(); BoundingBox *getBoundingBox(); list *getPieces(); - void postProcess(Level *level, Random *random, BoundingBox *chunkBB); + virtual void postProcess(Level *level, Random *random, BoundingBox *chunkBB); protected: void calculateBoundingBox();