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

@@ -29,12 +29,12 @@ ServerPlayerGameMode::ServerPlayerGameMode(Level *level)
this->level = level;
// 4J Added
m_gameRules = NULL;
m_gameRules = nullptr;
}
ServerPlayerGameMode::~ServerPlayerGameMode()
{
if(m_gameRules!=NULL) delete m_gameRules;
if(m_gameRules!=nullptr) delete m_gameRules;
}
void ServerPlayerGameMode::setGameModeForPlayer(GameType *gameModeForPlayer)
@@ -86,7 +86,7 @@ void ServerPlayerGameMode::tick()
{
Tile *tile = Tile::tiles[t];
float destroyProgress = tile->getDestroyProgress(player, player->level, delayedDestroyX, delayedDestroyY, delayedDestroyZ) * (ticksSpentDestroying + 1);
int state = (int) (destroyProgress * 10);
int state = static_cast<int>(destroyProgress * 10);
if (state != lastSentState)
{
@@ -105,7 +105,7 @@ void ServerPlayerGameMode::tick()
int t = level->getTile(xDestroyBlock, yDestroyBlock, zDestroyBlock);
Tile *tile = Tile::tiles[t];
if (tile == NULL)
if (tile == nullptr)
{
level->destroyTileProgress(player->entityId, xDestroyBlock, yDestroyBlock, zDestroyBlock, -1);
lastSentState = -1;
@@ -115,7 +115,7 @@ void ServerPlayerGameMode::tick()
{
int ticksSpentDestroying = gameTicks - destroyProgressStart;
float destroyProgress = tile->getDestroyProgress(player, player->level, xDestroyBlock, yDestroyBlock, zDestroyBlock) * (ticksSpentDestroying + 1);
int state = (int) (destroyProgress * 10);
int state = static_cast<int>(destroyProgress * 10);
if (state != lastSentState)
{
@@ -166,7 +166,7 @@ void ServerPlayerGameMode::startDestroyBlock(int x, int y, int z, int face)
xDestroyBlock = x;
yDestroyBlock = y;
zDestroyBlock = z;
int state = (int) (progress * 10);
int state = static_cast<int>(progress * 10);
level->destroyTileProgress(player->entityId, x, y, z, state);
lastSentState = state;
}
@@ -216,13 +216,13 @@ bool ServerPlayerGameMode::superDestroyBlock(int x, int y, int z)
Tile *oldTile = Tile::tiles[level->getTile(x, y, z)];
int data = level->getData(x, y, z);
if (oldTile != NULL)
if (oldTile != nullptr)
{
oldTile->playerWillDestroy(level, x, y, z, data, player);
}
bool changed = level->removeTile(x, y, z);
if (oldTile != NULL && changed)
if (oldTile != nullptr && changed)
{
oldTile->destroy(level, x, y, z, data);
}
@@ -241,7 +241,7 @@ bool ServerPlayerGameMode::destroyBlock(int x, int y, int z)
if (gameModeForPlayer->isCreative())
{
if (player->getCarriedItem() != NULL && dynamic_cast<WeaponItem *>(player->getCarriedItem()->getItem()) != NULL)
if (player->getCarriedItem() != nullptr && dynamic_cast<WeaponItem *>(player->getCarriedItem()->getItem()) != nullptr)
{
return false;
}
@@ -286,7 +286,7 @@ bool ServerPlayerGameMode::destroyBlock(int x, int y, int z)
if (isCreative())
{
shared_ptr<TileUpdatePacket> tup = shared_ptr<TileUpdatePacket>( new TileUpdatePacket(x, y, z, level) );
shared_ptr<TileUpdatePacket> tup = std::make_shared<TileUpdatePacket>(x, y, z, level);
// 4J - a bit of a hack here, but if we want to tell the client that it needs to inform the renderer of a block being destroyed, then send a block 255 instead of a 0. This is handled in ClientConnection::handleTileUpdate
if( tup->block == 0 )
{
@@ -298,7 +298,7 @@ bool ServerPlayerGameMode::destroyBlock(int x, int y, int z)
{
shared_ptr<ItemInstance> item = player->getSelectedItem();
bool canDestroy = player->canDestroy(Tile::tiles[t]);
if (item != NULL)
if (item != nullptr)
{
item->mineBlock(level, t, x, y, z, player);
if (item->count == 0)
@@ -322,7 +322,7 @@ bool ServerPlayerGameMode::useItem(shared_ptr<Player> player, Level *level, shar
int oldCount = item->count;
int oldAux = item->getAuxValue();
shared_ptr<ItemInstance> itemInstance = item->use(level, player);
if (itemInstance != item || (itemInstance != NULL && (itemInstance->count != oldCount || itemInstance->getUseDuration() > 0 || itemInstance->getAuxValue() != oldAux)))
if (itemInstance != item || (itemInstance != nullptr && (itemInstance->count != oldCount || itemInstance->getUseDuration() > 0 || itemInstance->getAuxValue() != oldAux)))
{
player->inventory->items[player->inventory->selected] = itemInstance;
if (isCreative())
@@ -348,7 +348,7 @@ bool ServerPlayerGameMode::useItemOn(shared_ptr<Player> player, Level *level, sh
{
// 4J-PB - Adding a test only version to allow tooltips to be displayed
int t = level->getTile(x, y, z);
if (!player->isSneaking() || player->getCarriedItem() == NULL)
if (!player->isSneaking() || player->getCarriedItem() == nullptr)
{
if (t > 0 && player->isAllowedToUse(Tile::tiles[t]))
{
@@ -360,14 +360,14 @@ bool ServerPlayerGameMode::useItemOn(shared_ptr<Player> player, Level *level, sh
{
if (Tile::tiles[t]->use(level, x, y, z, player, face, clickX, clickY, clickZ))
{
if(m_gameRules != NULL) m_gameRules->onUseTile(t,x,y,z);
if(m_gameRules != nullptr) m_gameRules->onUseTile(t,x,y,z);
return true;
}
}
}
}
if (item == NULL || !player->isAllowedToUse(item)) return false;
if (item == nullptr || !player->isAllowedToUse(item)) return false;
if (isCreative())
{
int aux = item->getAuxValue();
@@ -391,6 +391,6 @@ void ServerPlayerGameMode::setLevel(ServerLevel *newLevel)
// 4J Added
void ServerPlayerGameMode::setGameRules(GameRulesInstance *rules)
{
if(m_gameRules != NULL) delete m_gameRules;
if(m_gameRules != nullptr) delete m_gameRules;
m_gameRules = rules;
}