4jcraft/Minecraft.World/WorldGen/Features/CaveFeature.cpp
MatthewBeshay a0fdc643d1 Merge branch 'upstream-dev' into cleanup/nullptr-replacement
# Conflicts:
#	Minecraft.Client/Network/PlayerChunkMap.cpp
#	Minecraft.Client/Network/PlayerList.cpp
#	Minecraft.Client/Network/ServerChunkCache.cpp
#	Minecraft.Client/Platform/Common/Consoles_App.cpp
#	Minecraft.Client/Platform/Common/DLC/DLCManager.cpp
#	Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp
#	Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp
#	Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp
#	Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp
#	Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp
#	Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp
#	Minecraft.Client/Platform/Common/UI/UIController.cpp
#	Minecraft.Client/Platform/Common/UI/UIController.h
#	Minecraft.Client/Platform/Extrax64Stubs.cpp
#	Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h
#	Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h
#	Minecraft.Client/Player/EntityTracker.cpp
#	Minecraft.Client/Player/ServerPlayer.cpp
#	Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp
#	Minecraft.Client/Textures/Packs/DLCTexturePack.cpp
#	Minecraft.Client/Textures/Stitching/StitchedTexture.cpp
#	Minecraft.Client/Textures/Stitching/TextureMap.cpp
#	Minecraft.Client/Textures/Textures.cpp
#	Minecraft.World/Blocks/NotGateTile.cpp
#	Minecraft.World/Blocks/PressurePlateTile.cpp
#	Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp
#	Minecraft.World/Enchantments/EnchantmentHelper.cpp
#	Minecraft.World/Entities/HangingEntity.cpp
#	Minecraft.World/Entities/LeashFenceKnotEntity.cpp
#	Minecraft.World/Entities/LivingEntity.cpp
#	Minecraft.World/Entities/Mobs/Boat.cpp
#	Minecraft.World/Entities/Mobs/Minecart.cpp
#	Minecraft.World/Entities/Mobs/Witch.cpp
#	Minecraft.World/Entities/SyncedEntityData.cpp
#	Minecraft.World/Items/LeashItem.cpp
#	Minecraft.World/Items/PotionItem.cpp
#	Minecraft.World/Level/BaseMobSpawner.cpp
#	Minecraft.World/Level/CustomLevelSource.cpp
#	Minecraft.World/Level/Level.cpp
#	Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp
#	Minecraft.World/Level/Storage/McRegionLevelStorage.cpp
#	Minecraft.World/Level/Storage/RegionFileCache.cpp
#	Minecraft.World/Player/Player.cpp
#	Minecraft.World/WorldGen/Biomes/BiomeCache.cpp
#	Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp
#	Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
2026-03-30 16:28:40 +11:00

95 lines
3.9 KiB
C++

#include "../../Platform/stdafx.h"
#include "CaveFeature.h"
#include "../../Headers/net.minecraft.world.level.h"
#include "../../Headers/net.minecraft.world.level.tile.h"
bool CaveFeature::place(Level* level, Random* random, int x, int y, int z) {
float dir = random->nextFloat() * PI;
double rd = 8;
double x0 = x + 8 + Mth::sin(dir) * rd;
double x1 = x + 8 - Mth::sin(dir) * rd;
double z0 = z + 8 + Mth::cos(dir) * rd;
double z1 = z + 8 - Mth::cos(dir) * rd;
double y0 = y + random->nextInt(8) + 2;
double y1 = y + random->nextInt(8) + 2;
double radius = random->nextDouble() * 4 + 2;
double fuss = random->nextDouble() * 0.6;
int64_t seed = random->nextLong();
random->setSeed(seed);
std::vector<TilePos*> toRemove;
for (int d = 0; d <= 16; d++) {
double xx = x0 + (x1 - x0) * d / 16;
double yy = y0 + (y1 - y0) * d / 16;
double zz = z0 + (z1 - z0) * d / 16;
double ss = random->nextDouble();
double r = (Mth::sin(d / 16.0f * PI) * radius + 1) * ss + 1;
double hr = (Mth::sin(d / 16.0f * PI) * radius + 1) * ss + 1;
// 4J Stu Added to stop cave features generating areas previously place
// by game rule generation
if (app.getLevelGenerationOptions() != nullptr) {
LevelGenerationOptions* levelGenOptions =
app.getLevelGenerationOptions();
bool intersects = levelGenOptions->checkIntersects(
(xx - r / 2), (yy - hr / 2), (zz - r / 2), (xx + r / 2),
(yy + hr / 2), (zz + r / 2));
if (intersects) {
// app.DebugPrintf("Skipping cave feature generation as it
// overlaps a game rule structure\n");
return false;
}
}
for (int x2 = (int)(xx - r / 2); x2 <= (int)(xx + r / 2); x2++)
for (int y2 = (int)(yy - hr / 2); y2 <= (int)(yy + hr / 2); y2++)
for (int z2 = (int)(zz - r / 2); z2 <= (int)(zz + r / 2);
z2++) {
double xd = ((x2 + 0.5) - xx) / (r / 2);
double yd = ((y2 + 0.5) - yy) / (hr / 2);
double zd = ((z2 + 0.5) - zz) / (r / 2);
if (xd * xd + yd * yd + zd * zd <
random->nextDouble() * fuss + (1 - fuss)) {
if (!level->isEmptyTile(x2, y2, z2)) {
for (int x3 = (x2 - 2); x3 <= (x2 + 1); x3++)
for (int y3 = (y2 - 1); y3 <= (y2 + 1); y3++)
for (int z3 = (z2 - 1); z3 <= (z2 + 1);
z3++) {
if (x3 <= x || z3 <= z ||
x3 >= x + 16 - 1 ||
z3 >= z + 16 - 1)
return false;
if (level->getMaterial(x3, y3, z3)
->isLiquid())
return false;
}
toRemove.push_back(new TilePos(x2, y2, z2));
}
}
}
}
auto itEnd = toRemove.end();
for (auto it = toRemove.begin(); it != itEnd; it++) {
TilePos* p = *it; // toRemove[i];
level->setTileAndData(p->x, p->y, p->z, 0, 0, Tile::UPDATE_CLIENTS);
}
itEnd = toRemove.end();
for (auto it = toRemove.begin(); it != itEnd; it++) {
TilePos* p = *it; // toRemove[i];
if (level->getTile(p->x, p->y - 1, p->z) == Tile::dirt_Id &&
level->getDaytimeRawBrightness(p->x, p->y, p->z) > 8) {
level->setTileAndData(p->x, p->y - 1, p->z, Tile::grass_Id, 0,
Tile::UPDATE_CLIENTS);
}
delete p;
}
return true;
}