Project modernization (#630)

* 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
This commit is contained in:
ModMaker101
2026-03-07 21:56:03 -05:00
committed by GitHub
parent 1be5faaea7
commit a9be52c41a
1373 changed files with 19903 additions and 19449 deletions

View File

@@ -123,7 +123,7 @@ void LevelChunk::init(Level *level, int x, int z)
#ifdef _LARGE_WORLDS
m_bUnloaded = false; // 4J Added
m_unloadedEntitiesTag = NULL;
m_unloadedEntitiesTag = nullptr;
#endif
}
@@ -132,10 +132,10 @@ LevelChunk::LevelChunk(Level *level, int x, int z)
{
init(level, x, z);
lowerBlocks = new CompressedTileStorage();
lowerData = NULL;
lowerSkyLight = NULL;
lowerBlockLight = NULL;
serverTerrainPopulated = NULL;
lowerData = nullptr;
lowerSkyLight = nullptr;
lowerBlockLight = nullptr;
serverTerrainPopulated = nullptr;
if(Level::maxBuildHeight > Level::COMPRESSED_CHUNK_SECTION_HEIGHT)
{
@@ -147,10 +147,10 @@ LevelChunk::LevelChunk(Level *level, int x, int z)
}
else
{
upperBlocks = NULL;
upperData = NULL;
upperSkyLight = NULL;
upperBlockLight = NULL;
upperBlocks = nullptr;
upperData = nullptr;
upperSkyLight = nullptr;
upperBlockLight = nullptr;
}
#ifdef SHARING_ENABLED
@@ -167,7 +167,7 @@ LevelChunk::LevelChunk(Level *level, byteArray blocks, int x, int z)
// We'll be creating this as "empty" when this ctor is called on the client, as a result of a chunk becoming visible (but we don't have the data yet for it).
// In this case, we want to keep memory usage down and so create all data as empty/compressed as possible. On the client we get the full data for the chunk as a single
// update in a block region update packet, and so there is a single point where it is good to compress the data.
bool createEmpty = ( blocks.data == NULL );
bool createEmpty = ( blocks.data == nullptr );
if( createEmpty )
{
@@ -199,13 +199,13 @@ LevelChunk::LevelChunk(Level *level, byteArray blocks, int x, int z)
}
else
{
upperBlocks = NULL;
upperData = NULL;
upperSkyLight = NULL;
upperBlockLight = NULL;
upperBlocks = nullptr;
upperData = nullptr;
upperSkyLight = nullptr;
upperBlockLight = nullptr;
}
serverTerrainPopulated = NULL;
serverTerrainPopulated = nullptr;
#ifdef SHARING_ENABLED
sharingTilesAndData = false;
#endif
@@ -237,7 +237,7 @@ LevelChunk::LevelChunk(Level *level, int x, int z, LevelChunk *lc)
this->data = new SparseDataStorage(lc->data);
this->skyLight = new SparseLightStorage(lc->skyLight);
this->blockLight = new SparseLightStorage(lc->blockLight);
serverTerrainPopulated = NULL;
serverTerrainPopulated = nullptr;
#endif
}
@@ -296,8 +296,8 @@ void LevelChunk::stopSharingTilesAndData()
}
else
{
upperBlocks = NULL;
upperData = NULL;
upperBlocks = nullptr;
upperData = nullptr;
}
/*
@@ -531,7 +531,7 @@ void LevelChunk::recalcHeightmapOnly()
blocks = (y-1) >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT?upperBlocks : lowerBlocks;
}
#endif
heightmap[z << 4 | x] = (byte) y;
heightmap[z << 4 | x] = static_cast<byte>(y);
if (y < min) min = y;
}
@@ -588,7 +588,7 @@ void LevelChunk::recalcHeightmap()
blocks = (y-1) >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT?upperBlocks : lowerBlocks;
}
#endif
heightmap[z << 4 | x] = (byte) y;
heightmap[z << 4 | x] = static_cast<byte>(y);
if (y < min) min = y;
if (y < lowestHeightmap) lowestHeightmap = y;
@@ -811,7 +811,7 @@ void LevelChunk::recalcHeight(int x, int yStart, int z)
if (y == yOld) return;
// level->lightColumnChanged(x, z, y, yOld); // 4J - this call moved below & corrected - see comment further down
heightmap[z << 4 | x] = (byte) y;
heightmap[z << 4 | x] = static_cast<byte>(y);
if (y < minHeight)
{
@@ -919,12 +919,12 @@ int LevelChunk::getTile(int x, int y, int z)
bool LevelChunk::setTileAndData(int x, int y, int z, int _tile, int _data)
{
byte tile = (byte) _tile;
byte tile = static_cast<byte>(_tile);
// Optimisation brought forward from 1.8.2, change from int to unsigned char & this special value changed from -999 to 255
int slot = z << 4 | x;
if (y >= ((int)rainHeights[slot]) - 1)
if (y >= static_cast<int>(rainHeights[slot]) - 1)
{
rainHeights[slot] = 255;
}
@@ -939,7 +939,7 @@ bool LevelChunk::setTileAndData(int x, int y, int z, int _tile, int _data)
{
// 4J Stu - Need to do this here otherwise double chests don't always work correctly
shared_ptr<TileEntity> te = getTileEntity(x, y, z);
if (te != NULL)
if (te != nullptr)
{
te->clearCache();
}
@@ -1032,17 +1032,17 @@ bool LevelChunk::setTileAndData(int x, int y, int z, int _tile, int _data)
}
}
// AP - changed the method of EntityTile detection cos it's well slow on Vita mate
// if (_tile > 0 && dynamic_cast<EntityTile *>(Tile::tiles[_tile]) != NULL)
if (_tile > 0 && Tile::tiles[_tile] != NULL && Tile::tiles[_tile]->isEntityTile())
// if (_tile > 0 && dynamic_cast<EntityTile *>(Tile::tiles[_tile]) != nullptr)
if (_tile > 0 && Tile::tiles[_tile] != nullptr && Tile::tiles[_tile]->isEntityTile())
{
shared_ptr<TileEntity> te = getTileEntity(x, y, z);
if (te == NULL)
if (te == nullptr)
{
te = dynamic_cast<EntityTile *>(Tile::tiles[_tile])->newTileEntity(level);
//app.DebugPrintf("%s: Setting tile id %d, created tileEntity type %d\n", level->isClientSide?"Client":"Server", _tile, te->GetType());
level->setTileEntity(xOffs, y, zOffs, te);
}
if (te != NULL)
if (te != nullptr)
{
//app.DebugPrintf("%s: Setting tile id %d, found tileEntity type %d\n", level->isClientSide?"Client":"Server", _tile, te->GetType());
te->clearCache();
@@ -1050,11 +1050,11 @@ bool LevelChunk::setTileAndData(int x, int y, int z, int _tile, int _data)
}
}
// AP - changed the method of EntityTile detection cos it's well slow on Vita mate
// else if (old > 0 && dynamic_cast<EntityTile *>(Tile::tiles[old]) != NULL)
else if (old > 0 && Tile::tiles[_tile] != NULL && Tile::tiles[_tile]->isEntityTile())
// else if (old > 0 && dynamic_cast<EntityTile *>(Tile::tiles[old]) != nullptr)
else if (old > 0 && Tile::tiles[_tile] != nullptr && Tile::tiles[_tile]->isEntityTile())
{
shared_ptr<TileEntity> te = getTileEntity(x, y, z);
if (te != NULL)
if (te != nullptr)
{
te->clearCache();
}
@@ -1091,10 +1091,10 @@ bool LevelChunk::setData(int x, int y, int z, int val, int mask, bool *maskedBit
data->set(x, y % Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z, val);
int _tile = getTile(x, y, z);
if (_tile > 0 && dynamic_cast<EntityTile *>( Tile::tiles[_tile] ) != NULL)
if (_tile > 0 && dynamic_cast<EntityTile *>( Tile::tiles[_tile] ) != nullptr)
{
shared_ptr<TileEntity> te = getTileEntity(x, y, z);
if (te != NULL)
if (te != nullptr)
{
te->clearCache();
te->data = val;
@@ -1310,7 +1310,7 @@ shared_ptr<TileEntity> LevelChunk::getTileEntity(int x, int y, int z)
//EntityTile *et = (EntityTile *) Tile::tiles[t];
//et->onPlace(level, this->x * 16 + x, y, this->z * 16 + z);
//if (tileEntity == NULL)
//if (tileEntity == nullptr)
//{
tileEntity = dynamic_cast<EntityTile *>(Tile::tiles[t])->newTileEntity(level);
level->setTileEntity(this->x * 16 + x, y, this->z * 16 + z, tileEntity);
@@ -1332,7 +1332,7 @@ shared_ptr<TileEntity> LevelChunk::getTileEntity(int x, int y, int z)
tileEntity = it->second;
LeaveCriticalSection(&m_csTileEntities);
}
if (tileEntity != NULL && tileEntity->isRemoved())
if (tileEntity != nullptr && tileEntity->isRemoved())
{
EnterCriticalSection(&m_csTileEntities);
tileEntities.erase(pos);
@@ -1398,7 +1398,7 @@ void LevelChunk::removeTileEntity(int x, int y, int z)
{
shared_ptr<TileEntity> te = tileEntities[pos];
tileEntities.erase(pos);
if( te != NULL )
if( te != nullptr )
{
if(level->isClientSide)
{
@@ -1421,13 +1421,13 @@ void LevelChunk::load()
if(m_bUnloaded && m_unloadedEntitiesTag)
{
ListTag<CompoundTag> *entityTags = (ListTag<CompoundTag> *) m_unloadedEntitiesTag->getList(L"Entities");
if (entityTags != NULL)
if (entityTags != nullptr)
{
for (int i = 0; i < entityTags->size(); i++)
{
CompoundTag *teTag = entityTags->get(i);
shared_ptr<Entity> ent = EntityIO::loadStatic(teTag, level);
if (ent != NULL)
if (ent != nullptr)
{
ent->onLoadedFromSave();
addEntity(ent);
@@ -1436,20 +1436,20 @@ void LevelChunk::load()
}
ListTag<CompoundTag> *tileEntityTags = (ListTag<CompoundTag> *) m_unloadedEntitiesTag->getList(L"TileEntities");
if (tileEntityTags != NULL)
if (tileEntityTags != nullptr)
{
for (int i = 0; i < tileEntityTags->size(); i++)
{
CompoundTag *teTag = tileEntityTags->get(i);
shared_ptr<TileEntity> te = TileEntity::loadStatic(teTag);
if (te != NULL)
if (te != nullptr)
{
addTileEntity(te);
}
}
}
delete m_unloadedEntitiesTag;
m_unloadedEntitiesTag = NULL;
m_unloadedEntitiesTag = nullptr;
m_bUnloaded = false;
}
#endif
@@ -1628,16 +1628,16 @@ void LevelChunk::getEntities(shared_ptr<Entity> except, AABB *bb, vector<shared_
for (auto& e : *entities)
{
if ( e && e != except && e->bb->intersects(bb) && (selector == NULL || selector->matches(e)))
if ( e && e != except && e->bb->intersects(bb) && (selector == nullptr || selector->matches(e)))
{
es.push_back(e);
vector<shared_ptr<Entity> > *subs = e->getSubEntities();
if (subs != NULL)
if (subs != nullptr)
{
for (const auto& sub : *subs)
{
e = sub;
if ( e && e != except && e->bb->intersects(bb) && (selector == NULL || selector->matches(e)))
if ( e && e != except && e->bb->intersects(bb) && (selector == nullptr || selector->matches(e)))
{
es.push_back(e);
}
@@ -1693,10 +1693,10 @@ void LevelChunk::getEntitiesOfClass(const type_info& ec, AABB *bb, vector<shared
else if ( ec==typeid(Minecart) ) isAssignableFrom = e->instanceof(eTYPE_MINECART);
else if ( ec==typeid(Monster) ) isAssignableFrom = e->instanceof(eTYPE_MONSTER);
else if ( ec==typeid(Zombie) ) isAssignableFrom = e->instanceof(eTYPE_ZOMBIE);
else if(e != NULL && ec == typeid(*(e.get())) ) isAssignableFrom = true;
else if(e != nullptr && ec == typeid(*(e.get())) ) isAssignableFrom = true;
if (isAssignableFrom && e->bb->intersects(bb))
{
if (selector == NULL || selector->matches(e))
if (selector == nullptr || selector->matches(e))
{
es.push_back(e);
}
@@ -1719,7 +1719,7 @@ int LevelChunk::countEntities()
#endif
for (int yc = 0; yc < ENTITY_BLOCKS_LENGTH; yc++)
{
entityCount += (int)entityBlocks[yc]->size();
entityCount += static_cast<int>(entityBlocks[yc]->size());
}
#ifdef _ENTITIES_RW_SECTION
LeaveCriticalRWSection(&m_csEntities, false);
@@ -1813,7 +1813,7 @@ bool LevelChunk::testSetBlocksAndData(byteArray data, int x0, int y0, int z0, in
void LevelChunk::tileUpdatedCallback(int x, int y, int z, void *param, int yparam)
{
LevelChunk *lc = (LevelChunk *)param;
LevelChunk *lc = static_cast<LevelChunk *>(param);
int xx = lc->x * 16 + x;
int yy = y + yparam;
int zz = lc->z * 16 + z;
@@ -1849,8 +1849,8 @@ int LevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1,
int compressedHeight = Level::COMPRESSED_CHUNK_SECTION_HEIGHT;
// 4J - replaced block storage as now uses CompressedTileStorage
if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += lowerBlocks->setDataRegion( data, x0, y0, z0, x1, min(compressedHeight, y1), z1, p, includeLighting ? NULL : tileUpdatedCallback, this, 0 );
if(y1 > Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += upperBlocks->setDataRegion( data, x0, max(y0-compressedHeight,0), z0, x1, y1-Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p, includeLighting ? NULL : tileUpdatedCallback, this, Level::COMPRESSED_CHUNK_SECTION_HEIGHT );
if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += lowerBlocks->setDataRegion( data, x0, y0, z0, x1, min(compressedHeight, y1), z1, p, includeLighting ? nullptr : tileUpdatedCallback, this, 0 );
if(y1 > Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += upperBlocks->setDataRegion( data, x0, max(y0-compressedHeight,0), z0, x1, y1-Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p, includeLighting ? nullptr : tileUpdatedCallback, this, Level::COMPRESSED_CHUNK_SECTION_HEIGHT );
/*
for (int x = x0; x < x1; x++)
for (int z = z0; z < z1; z++)
@@ -1864,8 +1864,8 @@ int LevelChunk::setBlocksAndData(byteArray data, int x0, int y0, int z0, int x1,
recalcHeightmapOnly();
// 4J - replaced data storage as now uses SparseDataStorage
if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += lowerData->setDataRegion( data, x0, y0, z0, x1, min(compressedHeight, y1), z1, p, includeLighting ? NULL : tileUpdatedCallback, this, 0 );
if(y1 > Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += upperData->setDataRegion( data, x0, max(y0-compressedHeight,0), z0, x1, y1-Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p, includeLighting ? NULL : tileUpdatedCallback, this, Level::COMPRESSED_CHUNK_SECTION_HEIGHT );
if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += lowerData->setDataRegion( data, x0, y0, z0, x1, min(compressedHeight, y1), z1, p, includeLighting ? nullptr : tileUpdatedCallback, this, 0 );
if(y1 > Level::COMPRESSED_CHUNK_SECTION_HEIGHT) p += upperData->setDataRegion( data, x0, max(y0-compressedHeight,0), z0, x1, y1-Level::COMPRESSED_CHUNK_SECTION_HEIGHT, z1, p, includeLighting ? nullptr : tileUpdatedCallback, this, Level::COMPRESSED_CHUNK_SECTION_HEIGHT );
if( includeLighting )
{
@@ -2000,7 +2000,7 @@ void LevelChunk::checkChests(ChunkSource *source, int x, int z )
{
int xOffs = x * 16 + xx;
int zOffs = z * 16 + zz;
ChestTile *tile = (ChestTile *)Tile::tiles[Tile::chest_Id];
ChestTile *tile = static_cast<ChestTile *>(Tile::tiles[Tile::chest_Id]);
tile->recalcLockDir( level, xOffs, yy, zOffs );
level->checkLight(xOffs, yy, zOffs, true);
}
@@ -2047,7 +2047,7 @@ void LevelChunk::reloadBiomes()
for(unsigned int z = 0; z < 16; ++z)
{
Biome *biome = biomeSource->getBiome((this->x << 4) + x, (this->z << 4) + z);
biomes[(z << 4) | x] = (byte) ( (biome->id) & 0xff);
biomes[(z << 4) | x] = static_cast<byte>((biome->id) & 0xff);
}
}
}
@@ -2059,9 +2059,9 @@ Biome *LevelChunk::getBiome(int x, int z, BiomeSource *biomeSource)
{
Biome *biome = biomeSource->getBiome((this->x << 4) + x, (this->z << 4) + z);
value = biome->id;
biomes[(z << 4) | x] = (byte) (value & 0xff);
biomes[(z << 4) | x] = static_cast<byte>(value & 0xff);
}
if (Biome::biomes[value] == NULL)
if (Biome::biomes[value] == nullptr)
{
return Biome::plains;
}
@@ -2075,7 +2075,7 @@ byteArray LevelChunk::getBiomes()
void LevelChunk::setBiomes(byteArray biomes)
{
if(this->biomes.data != NULL) delete[] this->biomes.data;
if(this->biomes.data != nullptr) delete[] this->biomes.data;
this->biomes = biomes;
}
@@ -2156,8 +2156,8 @@ void LevelChunk::getDataData(byteArray data)
// Set data to data passed in input byte array of length 16384. This data must be in original (java version) order if originalOrder set.
void LevelChunk::setDataData(byteArray data)
{
if( lowerData == NULL ) lowerData = new SparseDataStorage();
if( upperData == NULL ) upperData = new SparseDataStorage(true);
if( lowerData == nullptr ) lowerData = new SparseDataStorage();
if( upperData == nullptr ) upperData = new SparseDataStorage(true);
lowerData->setData(data,0);
if(data.length > Level::COMPRESSED_CHUNK_SECTION_TILES/2) upperData->setData(data,Level::COMPRESSED_CHUNK_SECTION_TILES/2);
}
@@ -2179,8 +2179,8 @@ void LevelChunk::getBlockLightData(byteArray data)
// Set sky light data to data passed in input byte array of length 16384. This data must be in original (java version) order if originalOrder set.
void LevelChunk::setSkyLightData(byteArray data)
{
if( lowerSkyLight == NULL ) lowerSkyLight = new SparseLightStorage(true);
if( upperSkyLight == NULL ) upperSkyLight = new SparseLightStorage(true,true);
if( lowerSkyLight == nullptr ) lowerSkyLight = new SparseLightStorage(true);
if( upperSkyLight == nullptr ) upperSkyLight = new SparseLightStorage(true,true);
lowerSkyLight->setData(data,0);
if(data.length > Level::COMPRESSED_CHUNK_SECTION_TILES/2) upperSkyLight->setData(data,Level::COMPRESSED_CHUNK_SECTION_TILES/2);
}
@@ -2188,8 +2188,8 @@ void LevelChunk::setSkyLightData(byteArray data)
// Set block light data to data passed in input byte array of length 16384. This data must be in original (java version) order if originalOrder set.
void LevelChunk::setBlockLightData(byteArray data)
{
if( lowerBlockLight == NULL ) lowerBlockLight = new SparseLightStorage(false);
if( upperBlockLight == NULL ) upperBlockLight = new SparseLightStorage(false, true);
if( lowerBlockLight == nullptr ) lowerBlockLight = new SparseLightStorage(false);
if( upperBlockLight == nullptr ) upperBlockLight = new SparseLightStorage(false, true);
lowerBlockLight->setData(data,0);
if(data.length > Level::COMPRESSED_CHUNK_SECTION_TILES/2) upperBlockLight->setData(data,Level::COMPRESSED_CHUNK_SECTION_TILES/2);
}
@@ -2215,8 +2215,8 @@ void LevelChunk::compressLighting()
void LevelChunk::compressBlocks()
{
#ifdef SHARING_ENABLED
CompressedTileStorage *blocksToCompressLower = NULL;
CompressedTileStorage *blocksToCompressUpper = NULL;
CompressedTileStorage *blocksToCompressLower = nullptr;
CompressedTileStorage *blocksToCompressUpper = nullptr;
// If we're the host machine, and this is the client level, then we only want to do this if we are sharing data. This means that we will be compressing the data that is shared from the server.
// No point trying to compress the local client copy of the data if the data is unshared, since we'll be throwing this data away again anyway once we share with the server again.
@@ -2293,24 +2293,24 @@ void LevelChunk::readCompressedBlockData(DataInputStream *dis)
void LevelChunk::readCompressedDataData(DataInputStream *dis)
{
if( lowerData == NULL ) lowerData = new SparseDataStorage();
if( upperData == NULL ) upperData = new SparseDataStorage(true);
if( lowerData == nullptr ) lowerData = new SparseDataStorage();
if( upperData == nullptr ) upperData = new SparseDataStorage(true);
lowerData->read(dis);
upperData->read(dis);
}
void LevelChunk::readCompressedSkyLightData(DataInputStream *dis)
{
if( lowerSkyLight == NULL ) lowerSkyLight = new SparseLightStorage(true);
if( upperSkyLight == NULL ) upperSkyLight = new SparseLightStorage(true,true);
if( lowerSkyLight == nullptr ) lowerSkyLight = new SparseLightStorage(true);
if( upperSkyLight == nullptr ) upperSkyLight = new SparseLightStorage(true,true);
lowerSkyLight->read(dis);
upperSkyLight->read(dis);
}
void LevelChunk::readCompressedBlockLightData(DataInputStream *dis)
{
if( lowerBlockLight == NULL ) lowerBlockLight = new SparseLightStorage(false);
if( upperBlockLight == NULL ) upperBlockLight = new SparseLightStorage(false, true);
if( lowerBlockLight == nullptr ) lowerBlockLight = new SparseLightStorage(false);
if( upperBlockLight == nullptr ) upperBlockLight = new SparseLightStorage(false, true);
lowerBlockLight->read(dis);
upperBlockLight->read(dis);
}
@@ -2319,8 +2319,8 @@ void LevelChunk::readCompressedBlockLightData(DataInputStream *dis)
void LevelChunk::compressData()
{
#ifdef SHARING_ENABLED
SparseDataStorage *dataToCompressLower = NULL;
SparseDataStorage *dataToCompressUpper = NULL;
SparseDataStorage *dataToCompressLower = nullptr;
SparseDataStorage *dataToCompressUpper = nullptr;
// If we're the host machine, and this is the client level, then we only want to do this if we are sharing data. This means that we will be compressing the data that is shared from the server.
// No point trying to compress the local client copy of the data if the data is unshared, since we'll be throwing this data away again anyway once we share with the server again.