aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/ServerPlayerGameMode.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/ServerPlayerGameMode.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/ServerPlayerGameMode.cpp')
-rw-r--r--Minecraft.Client/ServerPlayerGameMode.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/Minecraft.Client/ServerPlayerGameMode.cpp b/Minecraft.Client/ServerPlayerGameMode.cpp
index 2e6bca35..d2dcaaf6 100644
--- a/Minecraft.Client/ServerPlayerGameMode.cpp
+++ b/Minecraft.Client/ServerPlayerGameMode.cpp
@@ -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;
} \ No newline at end of file