aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/ServerPlayerGameMode.cpp
diff options
context:
space:
mode:
authorqwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com>2026-03-16 21:44:26 -0500
committerGitHub <noreply@github.com>2026-03-16 21:44:26 -0500
commitce739f6045ec72127491286ea3f3f21e537c1b55 (patch)
treef33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /Minecraft.Client/ServerPlayerGameMode.cpp
parent255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff)
parent5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff)
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/ServerPlayerGameMode.cpp')
-rw-r--r--Minecraft.Client/ServerPlayerGameMode.cpp64
1 files changed, 31 insertions, 33 deletions
diff --git a/Minecraft.Client/ServerPlayerGameMode.cpp b/Minecraft.Client/ServerPlayerGameMode.cpp
index 2e6bca35..041487f5 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;
}
@@ -176,31 +176,29 @@ void ServerPlayerGameMode::stopDestroyBlock(int x, int y, int z)
{
if (x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock)
{
- // int ticksSpentDestroying = gameTicks - destroyProgressStart;
-
int t = level->getTile(x, y, z);
if (t != 0)
{
Tile *tile = Tile::tiles[t];
-
- // MGH - removed checking for the destroy progress here, it has already been checked on the client before it sent the packet.
- // fixes issues with this failing to destroy because of packets bunching up
- // float destroyProgress = tile->getDestroyProgress(player, player->level, x, y, z) * (ticksSpentDestroying + 1);
- // if (destroyProgress >= .7f || bIgnoreDestroyProgress)
+ // Anti-cheat: re-check destroy progress on the server for STOP_DESTROY.
+ int ticksSpentDestroying = gameTicks - destroyProgressStart;
+ float destroyProgress = tile->getDestroyProgress(player, player->level, x, y, z) * (ticksSpentDestroying + 1);
+ if (destroyProgress >= 1.0f)
{
isDestroyingBlock = false;
level->destroyTileProgress(player->entityId, x, y, z, -1);
destroyBlock(x, y, z);
}
- // else if (!hasDelayedDestroy)
- // {
- // isDestroyingBlock = false;
- // hasDelayedDestroy = true;
- // delayedDestroyX = x;
- // delayedDestroyY = y;
- // delayedDestroyZ = z;
- // delayedTickStart = destroyProgressStart;
- // }
+ else if (!hasDelayedDestroy)
+ {
+ // Keep server-authoritative mining while allowing legit latency to finish via delayed tick progression.
+ isDestroyingBlock = false;
+ hasDelayedDestroy = true;
+ delayedDestroyX = x;
+ delayedDestroyY = y;
+ delayedDestroyZ = z;
+ delayedTickStart = destroyProgressStart;
+ }
}
}
}
@@ -216,13 +214,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 +239,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 +284,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 +296,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 +320,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 +346,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 +358,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 +389,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
+}