aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/ServerLevel.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.Client/ServerLevel.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.Client/ServerLevel.cpp')
-rw-r--r--Minecraft.Client/ServerLevel.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/Minecraft.Client/ServerLevel.cpp b/Minecraft.Client/ServerLevel.cpp
index 74881a6f..d322d9b6 100644
--- a/Minecraft.Client/ServerLevel.cpp
+++ b/Minecraft.Client/ServerLevel.cpp
@@ -42,7 +42,7 @@
WeighedTreasureArray ServerLevel::RANDOM_BONUS_ITEMS;
-C4JThread* ServerLevel::m_updateThread = NULL;
+C4JThread* ServerLevel::m_updateThread = nullptr;
C4JThread::EventArray* ServerLevel::m_updateTrigger;
CRITICAL_SECTION ServerLevel::m_updateCS[3];
@@ -63,7 +63,7 @@ void ServerLevel::staticCtor()
InitializeCriticalSection(&m_updateCS[1]);
InitializeCriticalSection(&m_updateCS[2]);
- m_updateThread = new C4JThread(runUpdate, NULL, "Tile update");
+ m_updateThread = new C4JThread(runUpdate, nullptr, "Tile update");
m_updateThread->SetProcessor(CPU_CORE_TILE_UPDATE);
#ifdef __ORBIS__
m_updateThread->SetPriority(THREAD_PRIORITY_BELOW_NORMAL); // On Orbis, this core is also used for Matching 2, and that priority of that seems to be always at default no matter what we set it to. Prioritise this below Matching 2.
@@ -123,7 +123,7 @@ ServerLevel::ServerLevel(MinecraftServer *server, shared_ptr<LevelStorage>levelS
scoreboard = new ServerScoreboard(server);
//shared_ptr<ScoreboardSaveData> scoreboardSaveData = dynamic_pointer_cast<ScoreboardSaveData>( savedDataStorage->get(typeid(ScoreboardSaveData), ScoreboardSaveData::FILE_ID) );
- //if (scoreboardSaveData == NULL)
+ //if (scoreboardSaveData == nullptr)
//{
// scoreboardSaveData = shared_ptr<ScoreboardSaveData>( new ScoreboardSaveData() );
// savedDataStorage->set(ScoreboardSaveData::FILE_ID, scoreboardSaveData);
@@ -257,7 +257,7 @@ void ServerLevel::tick()
#endif
{
PIXBeginNamedEvent(0,"Incremental save");
- save(false, NULL);
+ save(false, nullptr);
PIXEndNamedEvent();
}
@@ -312,9 +312,9 @@ void ServerLevel::tick()
Biome::MobSpawnerData *ServerLevel::getRandomMobSpawnAt(MobCategory *mobCategory, int x, int y, int z)
{
vector<Biome::MobSpawnerData *> *mobList = getChunkSource()->getMobsAt(mobCategory, x, y, z);
- if (mobList == NULL || mobList->empty()) return NULL;
+ if (mobList == nullptr || mobList->empty()) return nullptr;
- return (Biome::MobSpawnerData *) WeighedRandom::getRandomItem(random, (vector<WeighedRandomItem *> *)mobList);
+ return static_cast<Biome::MobSpawnerData *>(WeighedRandom::getRandomItem(random, (vector<WeighedRandomItem *> *)mobList));
}
void ServerLevel::updateSleepingPlayerList()
@@ -432,7 +432,7 @@ void ServerLevel::tickTiles()
if( hasChunkAt(x,y,z) )
{
int id = getTile(x,y,z);
- if (Tile::tiles[id] != NULL && Tile::tiles[id]->isTicking())
+ if (Tile::tiles[id] != nullptr && Tile::tiles[id]->isTicking())
{
/*if(id == 2) ++grassTicks;
else if(id == 11) ++lavaTicks;
@@ -496,7 +496,7 @@ void ServerLevel::tickTiles()
if (isRainingAt(x, y, z))
{
- addGlobalEntity( shared_ptr<LightningBolt>( new LightningBolt(this, x, y, z) ) );
+ addGlobalEntity(std::make_shared<LightningBolt>(this, x, y, z));
}
}
@@ -639,8 +639,8 @@ void ServerLevel::resetEmptyTime()
bool ServerLevel::tickPendingTicks(bool force)
{
EnterCriticalSection(&m_tickNextTickCS);
- int count = (int)tickNextTickList.size();
- int count2 = (int)tickNextTickSet.size();
+ int count = static_cast<int>(tickNextTickList.size());
+ int count2 = static_cast<int>(tickNextTickSet.size());
if (count != tickNextTickSet.size())
{
// TODO 4J Stu - Add new exception types
@@ -684,8 +684,8 @@ bool ServerLevel::tickPendingTicks(bool force)
toBeTicked.clear();
- int count3 = (int)tickNextTickList.size();
- int count4 = (int)tickNextTickSet.size();
+ int count3 = static_cast<int>(tickNextTickList.size());
+ int count4 = static_cast<int>(tickNextTickSet.size());
bool retval = tickNextTickList.size() != 0;
LeaveCriticalSection(&m_tickNextTickCS);
@@ -775,7 +775,7 @@ void ServerLevel::tick(shared_ptr<Entity> e, bool actual)
{
e->remove();
}
- if (!server->isNpcsEnabled() && (dynamic_pointer_cast<Npc>(e) != NULL))
+ if (!server->isNpcsEnabled() && (dynamic_pointer_cast<Npc>(e) != nullptr))
{
e->remove();
}
@@ -859,7 +859,7 @@ void ServerLevel::setInitialSpawn(LevelSettings *levelSettings)
int minXZ = - (dimension->getXZSize() * 16 ) / 2;
int maxXZ = (dimension->getXZSize() * 16 ) / 2 - 1;
- if (findBiome != NULL)
+ if (findBiome != nullptr)
{
xSpawn = findBiome->x;
zSpawn = findBiome->z;
@@ -913,7 +913,7 @@ void ServerLevel::generateBonusItemsNearSpawn()
if( getTile( x, y, z ) == Tile::chest_Id )
{
shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(getTileEntity(x, y, z));
- if (chest != NULL)
+ if (chest != nullptr)
{
if( chest->isBonusChest )
{
@@ -959,7 +959,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
if(StorageManager.GetSaveDisabled()) return;
- if (progressListener != NULL)
+ if (progressListener != nullptr)
{
if(bAutosave)
{
@@ -975,7 +975,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
saveLevelData();
PIXEndNamedEvent();
- if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_CHUNKS);
+ if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_CHUNKS);
#if defined(_XBOX_ONE) || defined(__ORBIS__)
// Our autosave is a minimal save. All the chunks are saves by the constant save process
@@ -1008,7 +1008,7 @@ void ServerLevel::save(bool force, ProgressListener *progressListener, bool bAut
//if( force && !isClientSide )
//{
- // if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
+ // if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
// levelStorage->flushSaveFile();
//}
}
@@ -1023,7 +1023,7 @@ void ServerLevel::saveToDisc(ProgressListener *progressListener, bool autosave)
if(!Minecraft::GetInstance()->skins->isUsingDefaultSkin())
{
TexturePack *tPack = Minecraft::GetInstance()->skins->getSelected();
- DLCTexturePack *pDLCTexPack=(DLCTexturePack *)tPack;
+ DLCTexturePack *pDLCTexPack=static_cast<DLCTexturePack *>(tPack);
DLCPack * pDLCPack=pDLCTexPack->getDLCInfoParentPack();
@@ -1033,7 +1033,7 @@ void ServerLevel::saveToDisc(ProgressListener *progressListener, bool autosave)
}
}
- if (progressListener != NULL) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
+ if (progressListener != nullptr) progressListener->progressStage(IDS_PROGRESS_SAVING_TO_DISC);
levelStorage->flushSaveFile(autosave);
}
@@ -1084,7 +1084,7 @@ bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e)
{
if (Level::addGlobalEntity(e))
{
- server->getPlayers()->broadcast(e->x, e->y, e->z, 512, dimension->id, shared_ptr<AddGlobalEntityPacket>( new AddGlobalEntityPacket(e) ) );
+ server->getPlayers()->broadcast(e->x, e->y, e->z, 512, dimension->id, std::make_shared<AddGlobalEntityPacket>(e));
return true;
}
return false;
@@ -1092,7 +1092,7 @@ bool ServerLevel::addGlobalEntity(shared_ptr<Entity> e)
void ServerLevel::broadcastEntityEvent(shared_ptr<Entity> e, byte event)
{
- shared_ptr<Packet> p = shared_ptr<EntityEventPacket>( new EntityEventPacket(e->entityId, event) );
+ shared_ptr<Packet> p = std::make_shared<EntityEventPacket>(e->entityId, event);
server->getLevel(dimension->id)->getTracker()->broadcastAndSend(e, p);
}
@@ -1100,7 +1100,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
{
// instead of calling super, we run the same explosion code here except
// we don't generate any particles
- shared_ptr<Explosion> explosion = shared_ptr<Explosion>( new Explosion(this, source, x, y, z, r) );
+ shared_ptr<Explosion> explosion = std::make_shared<Explosion>(this, source, x, y, z, r);
explosion->fire = fire;
explosion->destroyBlocks = destroyBlocks;
explosion->explode();
@@ -1121,7 +1121,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
if( sentTo.size() )
{
INetworkPlayer *thisPlayer = player->connection->getNetworkPlayer();
- if( thisPlayer == NULL )
+ if( thisPlayer == nullptr )
{
continue;
}
@@ -1130,7 +1130,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
for(auto& player2 : sentTo)
{
INetworkPlayer *otherPlayer = player2->connection->getNetworkPlayer();
- if( otherPlayer != NULL && thisPlayer->IsSameSystem(otherPlayer) )
+ if( otherPlayer != nullptr && thisPlayer->IsSameSystem(otherPlayer) )
{
knockbackOnly = true;
}
@@ -1143,7 +1143,7 @@ shared_ptr<Explosion> ServerLevel::explode(shared_ptr<Entity> source, double x,
Vec3 *knockbackVec = explosion->getHitPlayerKnockback(player);
//app.DebugPrintf("Sending %s with knockback (%f,%f,%f)\n", knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z);
// If the player is not the primary on the system, then we only want to send info for the knockback
- player->connection->send( shared_ptr<ExplodePacket>( new ExplodePacket(x, y, z, r, &explosion->toBlow, knockbackVec, knockbackOnly)));
+ player->connection->send(std::make_shared<ExplodePacket>(x, y, z, r, &explosion->toBlow, knockbackVec, knockbackOnly));
sentTo.push_back( player );
}
}
@@ -1181,7 +1181,7 @@ void ServerLevel::runTileEvents()
if (doTileEvent(&it))
{
TileEventData te = it;
- server->getPlayers()->broadcast(te.getX(), te.getY(), te.getZ(), 64, dimension->id, shared_ptr<TileEventPacket>( new TileEventPacket(te.getX(), te.getY(), te.getZ(), te.getTile(), te.getParamA(), te.getParamB())));
+ server->getPlayers()->broadcast(te.getX(), te.getY(), te.getZ(), 64, dimension->id, std::make_shared<TileEventPacket>(te.getX(), te.getY(), te.getZ(), te.getTile(), te.getParamA(), te.getParamB()));
}
}
tileEvents[runList].clear();
@@ -1211,11 +1211,11 @@ void ServerLevel::tickWeather()
{
if (wasRaining)
{
- server->getPlayers()->broadcastAll( shared_ptr<GameEventPacket>( new GameEventPacket(GameEventPacket::STOP_RAINING, 0) ) );
+ server->getPlayers()->broadcastAll(std::make_shared<GameEventPacket>(GameEventPacket::STOP_RAINING, 0));
}
else
{
- server->getPlayers()->broadcastAll( shared_ptr<GameEventPacket>( new GameEventPacket(GameEventPacket::START_RAINING, 0) ) );
+ server->getPlayers()->broadcastAll(std::make_shared<GameEventPacket>(GameEventPacket::START_RAINING, 0));
}
}
@@ -1267,7 +1267,7 @@ void ServerLevel::sendParticles(const wstring &name, double x, double y, double
void ServerLevel::sendParticles(const wstring &name, double x, double y, double z, int count, double xDist, double yDist, double zDist, double speed)
{
- shared_ptr<Packet> packet = std::make_shared<LevelParticlesPacket>( name, (float) x, (float) y, (float) z, (float) xDist, (float) yDist, (float) zDist, (float) speed, count );
+ shared_ptr<Packet> packet = std::make_shared<LevelParticlesPacket>( name, static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(xDist), static_cast<float>(yDist), static_cast<float>(zDist), static_cast<float>(speed), count );
for(auto& it : players)
{
@@ -1577,7 +1577,7 @@ int ServerLevel::runUpdate(void* lpParam)
if( (id == Tile::grass_Id && grassTicks >= MAX_GRASS_TICKS) || (id == Tile::calmLava_Id && lavaTicks >= MAX_LAVA_TICKS) ) continue;
// 4J Stu - Added shouldTileTick as some tiles won't even do anything if they are set to tick and use up one of our updates
- if (Tile::tiles[id] != NULL && Tile::tiles[id]->isTicking() && Tile::tiles[id]->shouldTileTick(m_level[iLev],x + (cx * 16), y, z + (cz * 16) ) )
+ if (Tile::tiles[id] != nullptr && Tile::tiles[id]->isTicking() && Tile::tiles[id]->shouldTileTick(m_level[iLev],x + (cx * 16), y, z + (cz * 16) ) )
{
if(id == Tile::grass_Id) ++grassTicks;
else if(id == Tile::calmLava_Id) ++lavaTicks;