aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/CustomLevelSource.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-08 19:08:36 -0400
committerGitHub <noreply@github.com>2026-03-08 18:08:36 -0500
commit28614b922fb77149a54da1a87bebfbc98736f296 (patch)
tree7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.World/CustomLevelSource.cpp
parent88798b501d0cf6287b6f87acb2592676e3cec58d (diff)
Modernize project codebase (#906)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides * Add safety checks and fix a issue with vector going OOR
Diffstat (limited to 'Minecraft.World/CustomLevelSource.cpp')
-rw-r--r--Minecraft.World/CustomLevelSource.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/Minecraft.World/CustomLevelSource.cpp b/Minecraft.World/CustomLevelSource.cpp
index 0f4c6479..7281d298 100644
--- a/Minecraft.World/CustomLevelSource.cpp
+++ b/Minecraft.World/CustomLevelSource.cpp
@@ -30,7 +30,7 @@ CustomLevelSource::CustomLevelSource(Level *level, int64_t seed, bool generateSt
string path = "GAME:\\GameRules\\heightmap.bin";
#endif
#endif
- HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if( file == INVALID_HANDLE_VALUE )
{
app.FatalLoadError();
@@ -44,14 +44,14 @@ CustomLevelSource::CustomLevelSource(Level *level, int64_t seed, bool generateSt
__debugbreak(); // TODO
DWORD bytesRead,dwFileSize = 0;
#else
- DWORD bytesRead,dwFileSize = GetFileSize(file,NULL);
+ DWORD bytesRead,dwFileSize = GetFileSize(file,nullptr);
#endif
if(dwFileSize > m_heightmapOverride.length)
{
app.DebugPrintf("Heightmap binary is too large!!\n");
__debugbreak();
}
- BOOL bSuccess = ReadFile(file,m_heightmapOverride.data,dwFileSize,&bytesRead,NULL);
+ BOOL bSuccess = ReadFile(file,m_heightmapOverride.data,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
@@ -72,7 +72,7 @@ CustomLevelSource::CustomLevelSource(Level *level, int64_t seed, bool generateSt
string waterHeightPath = "GAME:\\GameRules\\waterheight.bin";
#endif
#endif
- file = CreateFile(waterHeightPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ file = CreateFile(waterHeightPath.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if( file == INVALID_HANDLE_VALUE )
{
DWORD error = GetLastError();
@@ -86,14 +86,14 @@ CustomLevelSource::CustomLevelSource(Level *level, int64_t seed, bool generateSt
__debugbreak(); // TODO
DWORD bytesRead,dwFileSize = 0;
#else
- DWORD bytesRead,dwFileSize = GetFileSize(file,NULL);
+ DWORD bytesRead,dwFileSize = GetFileSize(file,nullptr);
#endif
if(dwFileSize > m_waterheightOverride.length)
{
app.DebugPrintf("waterheight binary is too large!!\n");
__debugbreak();
}
- BOOL bSuccess = ReadFile(file,m_waterheightOverride.data,dwFileSize,&bytesRead,NULL);
+ BOOL bSuccess = ReadFile(file,m_waterheightOverride.data,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
@@ -196,7 +196,7 @@ void CustomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks)
if( emin < falloffStart )
{
int falloff = falloffStart - emin;
- comp = ((float)falloff / (float)falloffStart ) * falloffMax;
+ comp = (static_cast<float>(falloff) / static_cast<float>(falloffStart) ) * falloffMax;
}
// 4J - end of extra code
///////////////////////////////////////////////////////////////////
@@ -204,11 +204,11 @@ void CustomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks)
// 4J - this comparison used to just be with 0.0f but is now varied by block above
if (yc * CHUNK_HEIGHT + y < mapHeight)
{
- tileId = (byte) Tile::stone_Id;
+ tileId = static_cast<byte>(Tile::stone_Id);
}
else if (yc * CHUNK_HEIGHT + y < waterHeight)
{
- tileId = (byte) Tile::calmWater_Id;
+ tileId = static_cast<byte>(Tile::calmWater_Id);
}
// 4J - more extra code to make sure that the column at the edge of the world is just water & rock, to match the infinite sea that
@@ -262,7 +262,7 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
Biome *b = biomes[z + x * 16];
float temp = b->getTemperature();
- int runDepth = (int) (depthBuffer[x + z * 16] / 3 + 3 + random->nextDouble() * 0.25);
+ int runDepth = static_cast<int>(depthBuffer[x + z * 16] / 3 + 3 + random->nextDouble() * 0.25);
int run = -1;
@@ -270,7 +270,7 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
byte material = b->material;
LevelGenerationOptions *lgo = app.getLevelGenerationOptions();
- if(lgo != NULL)
+ if(lgo != nullptr)
{
lgo->getBiomeOverride(b->id,material,top);
}
@@ -290,7 +290,7 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
if (y <= 1 + random->nextInt(2)) // 4J - changed to make the bedrock not have bits you can get stuck in
// if (y <= 0 + random->nextInt(5))
{
- blocks[offs] = (byte) Tile::unbreakable_Id;
+ blocks[offs] = static_cast<byte>(Tile::unbreakable_Id);
}
else
{
@@ -307,13 +307,13 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
if (runDepth <= 0)
{
top = 0;
- material = (byte) Tile::stone_Id;
+ material = static_cast<byte>(Tile::stone_Id);
}
else if (y >= waterHeight - 4 && y <= waterHeight + 1)
{
top = b->topMaterial;
material = b->material;
- if(lgo != NULL)
+ if(lgo != nullptr)
{
lgo->getBiomeOverride(b->id,material,top);
}
@@ -321,8 +321,8 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
if (y < waterHeight && top == 0)
{
- if (temp < 0.15f) top = (byte) Tile::ice_Id;
- else top = (byte) Tile::calmWater_Id;
+ if (temp < 0.15f) top = static_cast<byte>(Tile::ice_Id);
+ else top = static_cast<byte>(Tile::calmWater_Id);
}
run = runDepth;
@@ -339,7 +339,7 @@ void CustomLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks, Bi
if (run == 0 && material == Tile::sand_Id)
{
run = random->nextInt(4);
- material = (byte) Tile::sandStone_Id;
+ material = static_cast<byte>(Tile::sandStone_Id);
}
}
}
@@ -357,7 +357,7 @@ LevelChunk *CustomLevelSource::create(int x, int z)
#ifdef _OVERRIDE_HEIGHTMAP
return getChunk(x,z);
#else
- return NULL;
+ return nullptr;
#endif
}
@@ -368,7 +368,7 @@ LevelChunk *CustomLevelSource::getChunk(int xOffs, int zOffs)
// 4J - now allocating this with a physical alloc & bypassing general memory management so that it will get cleanly freed
int blocksSize = Level::maxBuildHeight * 16 * 16;
- byte *tileData = (byte *)XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE);
+ byte *tileData = static_cast<byte *>(XPhysicalAlloc(blocksSize, MAXULONG_PTR, 4096, PAGE_READWRITE));
XMemSet128(tileData,0,blocksSize);
byteArray blocks = byteArray(tileData,blocksSize);
// byteArray blocks = byteArray(16 * level->depth * 16);
@@ -411,7 +411,7 @@ LevelChunk *CustomLevelSource::getChunk(int xOffs, int zOffs)
return levelChunk;
#else
- return NULL;
+ return nullptr;
#endif
}
@@ -622,9 +622,9 @@ vector<Biome::MobSpawnerData *> *CustomLevelSource::getMobsAt(MobCategory *mobCa
{
#ifdef _OVERRIDE_HEIGHTMAP
Biome *biome = level->getBiome(x, z);
- if (biome == NULL)
+ if (biome == nullptr)
{
- return NULL;
+ return nullptr;
}
if (mobCategory == MobCategory::monster && scatteredFeature->isSwamphut(x, y, z))
{
@@ -632,19 +632,19 @@ vector<Biome::MobSpawnerData *> *CustomLevelSource::getMobsAt(MobCategory *mobCa
}
return biome->getMobs(mobCategory);
#else
- return NULL;
+ return nullptr;
#endif
}
TilePos *CustomLevelSource::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z)
{
#ifdef _OVERRIDE_HEIGHTMAP
- if (LargeFeature::STRONGHOLD == featureName && strongholdFeature != NULL)
+ if (LargeFeature::STRONGHOLD == featureName && strongholdFeature != nullptr)
{
return strongholdFeature->getNearestGeneratedFeature(level, x, y, z);
}
#endif
- return NULL;
+ return nullptr;
}
void CustomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ)
@@ -652,10 +652,10 @@ void CustomLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ)
if (generateStructures)
{
#ifdef _OVERRIDE_HEIGHTMAP
- mineShaftFeature->apply(this, level, chunkX, chunkZ, NULL);
- villageFeature->apply(this, level, chunkX, chunkZ, NULL);
- strongholdFeature->apply(this, level, chunkX, chunkZ, NULL);
- scatteredFeature->apply(this, level, chunkX, chunkZ, NULL);
+ mineShaftFeature->apply(this, level, chunkX, chunkZ, byteArray());
+ villageFeature->apply(this, level, chunkX, chunkZ, byteArray());
+ strongholdFeature->apply(this, level, chunkX, chunkZ, byteArray());
+ scatteredFeature->apply(this, level, chunkX, chunkZ, byteArray());
#endif
}
} \ No newline at end of file