diff options
| author | ModMaker101 <119018978+ModMaker101@users.noreply.github.com> | 2026-03-08 19:08:36 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-08 18:08:36 -0500 |
| commit | 28614b922fb77149a54da1a87bebfbc98736f296 (patch) | |
| tree | 7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.Client/MultiPlayerLocalPlayer.cpp | |
| parent | 88798b501d0cf6287b6f87acb2592676e3cec58d (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/MultiPlayerLocalPlayer.cpp')
| -rw-r--r-- | Minecraft.Client/MultiPlayerLocalPlayer.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/Minecraft.Client/MultiPlayerLocalPlayer.cpp b/Minecraft.Client/MultiPlayerLocalPlayer.cpp index 25bf06bf..aef7898f 100644 --- a/Minecraft.Client/MultiPlayerLocalPlayer.cpp +++ b/Minecraft.Client/MultiPlayerLocalPlayer.cpp @@ -76,8 +76,8 @@ void MultiplayerLocalPlayer::tick() { if (isRiding()) { - connection->send(shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Rot(yRot, xRot, onGround, abilities.flying))); - connection->send(shared_ptr<PlayerInputPacket>(new PlayerInputPacket(xxa, yya, input->jumping, input->sneaking))); + connection->send(std::make_shared<MovePlayerPacket::Rot>(yRot, xRot, onGround, abilities.flying)); + connection->send(std::make_shared<PlayerInputPacket>(xxa, yya, input->jumping, input->sneaking)); } else { @@ -96,8 +96,8 @@ void MultiplayerLocalPlayer::sendPosition() bool sprinting = isSprinting(); if (sprinting != lastSprinting) { - if (sprinting) connection->send(shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::START_SPRINTING))); - else connection->send(shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::STOP_SPRINTING))); + if (sprinting) connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::START_SPRINTING)); + else connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::STOP_SPRINTING)); lastSprinting = sprinting; } @@ -105,8 +105,8 @@ void MultiplayerLocalPlayer::sendPosition() bool sneaking = isSneaking(); if (sneaking != lastSneaked) { - if (sneaking) connection->send( shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::START_SNEAKING) ) ); - else connection->send( shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::STOP_SNEAKING) ) ); + if (sneaking) connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::START_SNEAKING)); + else connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::STOP_SNEAKING)); lastSneaked = sneaking; } @@ -114,8 +114,8 @@ void MultiplayerLocalPlayer::sendPosition() bool idle = isIdle(); if (idle != lastIdle) { - if (idle) connection->send( shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::START_IDLEANIM) ) ); - else connection->send( shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::STOP_IDLEANIM) ) ); + if (idle) connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::START_IDLEANIM)); + else connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::STOP_IDLEANIM)); lastIdle = idle; } @@ -129,28 +129,28 @@ void MultiplayerLocalPlayer::sendPosition() bool move = (xdd * xdd + ydd1 * ydd1 + zdd * zdd) > 0.03 * 0.03 || positionReminder >= POSITION_REMINDER_INTERVAL; bool rot = rydd != 0 || rxdd != 0; - if (riding != NULL) + if (riding != nullptr) { - connection->send( shared_ptr<MovePlayerPacket>( new MovePlayerPacket::PosRot(xd, -999, -999, zd, yRot, xRot, onGround, abilities.flying) ) ); + connection->send(std::make_shared<MovePlayerPacket::PosRot>(xd, -999, -999, zd, yRot, xRot, onGround, abilities.flying)); move = false; } else { if (move && rot) { - connection->send( shared_ptr<MovePlayerPacket>( new MovePlayerPacket::PosRot(x, bb->y0, y, z, yRot, xRot, onGround, abilities.flying) ) ); + connection->send(std::make_shared<MovePlayerPacket::PosRot>(x, bb->y0, y, z, yRot, xRot, onGround, abilities.flying)); } else if (move) { - connection->send( shared_ptr<MovePlayerPacket>( new MovePlayerPacket::Pos(x, bb->y0, y, z, onGround, abilities.flying) ) ); + connection->send(std::make_shared<MovePlayerPacket::Pos>(x, bb->y0, y, z, onGround, abilities.flying)); } else if (rot) { - connection->send( shared_ptr<MovePlayerPacket>( new MovePlayerPacket::Rot(yRot, xRot, onGround, abilities.flying) ) ); + connection->send(std::make_shared<MovePlayerPacket::Rot>(yRot, xRot, onGround, abilities.flying)); } else { - connection->send( shared_ptr<MovePlayerPacket>( new MovePlayerPacket(onGround, abilities.flying) ) ); + connection->send(std::make_shared<MovePlayerPacket>(onGround, abilities.flying)); } } @@ -175,7 +175,7 @@ void MultiplayerLocalPlayer::sendPosition() shared_ptr<ItemEntity> MultiplayerLocalPlayer::drop() { - connection->send( shared_ptr<PlayerActionPacket>( new PlayerActionPacket(PlayerActionPacket::DROP_ITEM, 0, 0, 0, 0) ) ); + connection->send(std::make_shared<PlayerActionPacket>(PlayerActionPacket::DROP_ITEM, 0, 0, 0, 0)); return nullptr; } @@ -185,19 +185,19 @@ void MultiplayerLocalPlayer::reallyDrop(shared_ptr<ItemEntity> itemEntity) void MultiplayerLocalPlayer::chat(const wstring& message) { - connection->send( shared_ptr<ChatPacket>( new ChatPacket(message) ) ); + connection->send(std::make_shared<ChatPacket>(message)); } void MultiplayerLocalPlayer::swing() { LocalPlayer::swing(); - connection->send( shared_ptr<AnimatePacket>( new AnimatePacket(shared_from_this(), AnimatePacket::SWING) ) ); + connection->send(std::make_shared<AnimatePacket>(shared_from_this(), AnimatePacket::SWING)); } void MultiplayerLocalPlayer::respawn() { - connection->send( shared_ptr<ClientCommandPacket>( new ClientCommandPacket(ClientCommandPacket::PERFORM_RESPAWN))); + connection->send(std::make_shared<ClientCommandPacket>(ClientCommandPacket::PERFORM_RESPAWN)); } @@ -211,9 +211,9 @@ void MultiplayerLocalPlayer::actuallyHurt(DamageSource *source, float dmg) void MultiplayerLocalPlayer::completeUsingItem() { Minecraft *pMinecraft = Minecraft::GetInstance(); - if(useItem != NULL && pMinecraft->localgameModes[m_iPad] != NULL ) + if(useItem != nullptr && pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; + TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]); Tutorial *tutorial = gameMode->getTutorial(); tutorial->completeUsingItem(useItem); } @@ -223,9 +223,9 @@ void MultiplayerLocalPlayer::completeUsingItem() void MultiplayerLocalPlayer::onEffectAdded(MobEffectInstance *effect) { Minecraft *pMinecraft = Minecraft::GetInstance(); - if(pMinecraft->localgameModes[m_iPad] != NULL ) + if(pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; + TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]); Tutorial *tutorial = gameMode->getTutorial(); tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); } @@ -236,9 +236,9 @@ void MultiplayerLocalPlayer::onEffectAdded(MobEffectInstance *effect) void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance *effect, bool doRefreshAttributes) { Minecraft *pMinecraft = Minecraft::GetInstance(); - if(pMinecraft->localgameModes[m_iPad] != NULL ) + if(pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; + TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]); Tutorial *tutorial = gameMode->getTutorial(); tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); } @@ -249,9 +249,9 @@ void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance *effect, bool doR void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance *effect) { Minecraft *pMinecraft = Minecraft::GetInstance(); - if(pMinecraft->localgameModes[m_iPad] != NULL ) + if(pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; + TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]); Tutorial *tutorial = gameMode->getTutorial(); tutorial->onEffectChanged(MobEffect::effects[effect->getId()],true); } @@ -260,7 +260,7 @@ void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance *effect) void MultiplayerLocalPlayer::closeContainer() { - connection->send( shared_ptr<ContainerClosePacket>( new ContainerClosePacket(containerMenu->containerId) ) ); + connection->send(std::make_shared<ContainerClosePacket>(containerMenu->containerId)); clientSideCloseContainer(); } @@ -286,7 +286,7 @@ void MultiplayerLocalPlayer::hurtTo(float newHealth, ETelemetryChallenges damage void MultiplayerLocalPlayer::awardStat(Stat *stat, byteArray param) { - if (stat == NULL) + if (stat == nullptr) { delete [] param.data; return; @@ -305,7 +305,7 @@ void MultiplayerLocalPlayer::awardStat(Stat *stat, byteArray param) void MultiplayerLocalPlayer::awardStatFromServer(Stat *stat, byteArray param) { - if ( stat != NULL && !stat->awardLocallyOnly ) + if ( stat != nullptr && !stat->awardLocallyOnly ) { LocalPlayer::awardStat(stat, param); } @@ -314,7 +314,7 @@ void MultiplayerLocalPlayer::awardStatFromServer(Stat *stat, byteArray param) void MultiplayerLocalPlayer::onUpdateAbilities() { - connection->send(shared_ptr<PlayerAbilitiesPacket>(new PlayerAbilitiesPacket(&abilities))); + connection->send(std::make_shared<PlayerAbilitiesPacket>(&abilities)); } bool MultiplayerLocalPlayer::isLocalPlayer() @@ -324,19 +324,19 @@ bool MultiplayerLocalPlayer::isLocalPlayer() void MultiplayerLocalPlayer::sendRidingJump() { - connection->send(shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::RIDING_JUMP, (int) (getJumpRidingScale() * 100.0f)))); + connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::RIDING_JUMP, static_cast<int>(getJumpRidingScale() * 100.0f))); } void MultiplayerLocalPlayer::sendOpenInventory() { - connection->send(shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::OPEN_INVENTORY))); + connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::OPEN_INVENTORY)); } void MultiplayerLocalPlayer::ride(shared_ptr<Entity> e) { - bool wasRiding = riding != NULL; + bool wasRiding = riding != nullptr; LocalPlayer::ride(e); - bool isRiding = riding != NULL; + bool isRiding = riding != nullptr; // 4J Added if(wasRiding && !isRiding) @@ -348,7 +348,7 @@ void MultiplayerLocalPlayer::ride(shared_ptr<Entity> e) if( isRiding ) { ETelemetryChallenges eventType = eTelemetryChallenges_Unknown; - if( this->riding != NULL ) + if( this->riding != nullptr ) { switch(riding->GetType()) { @@ -370,9 +370,9 @@ void MultiplayerLocalPlayer::ride(shared_ptr<Entity> e) Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[m_iPad] != NULL ) + if( pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; + TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]); if(wasRiding && !isRiding) { gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Gameplay); @@ -386,7 +386,7 @@ void MultiplayerLocalPlayer::ride(shared_ptr<Entity> e) void MultiplayerLocalPlayer::StopSleeping() { - connection->send( shared_ptr<PlayerCommandPacket>( new PlayerCommandPacket(shared_from_this(), PlayerCommandPacket::STOP_SLEEPING) ) ); + connection->send(std::make_shared<PlayerCommandPacket>(shared_from_this(), PlayerCommandPacket::STOP_SLEEPING)); } // 4J Added @@ -397,7 +397,7 @@ void MultiplayerLocalPlayer::setAndBroadcastCustomSkin(DWORD skinId) #ifndef _CONTENT_PACKAGE wprintf(L"Skin for local player %ls has changed to %ls (%d)\n", name.c_str(), customTextureUrl.c_str(), getPlayerDefaultSkin() ); #endif - if(getCustomSkin() != oldSkinIndex) connection->send( shared_ptr<TextureAndGeometryChangePacket>( new TextureAndGeometryChangePacket( shared_from_this(), app.GetPlayerSkinName(GetXboxPad()) ) ) ); + if(getCustomSkin() != oldSkinIndex) connection->send(std::make_shared<TextureAndGeometryChangePacket>(shared_from_this(), app.GetPlayerSkinName(GetXboxPad()))); } void MultiplayerLocalPlayer::setAndBroadcastCustomCape(DWORD capeId) @@ -407,7 +407,7 @@ void MultiplayerLocalPlayer::setAndBroadcastCustomCape(DWORD capeId) #ifndef _CONTENT_PACKAGE wprintf(L"Cape for local player %ls has changed to %ls\n", name.c_str(), customTextureUrl2.c_str()); #endif - if(getCustomCape() != oldCapeIndex) connection->send( shared_ptr<TextureChangePacket>( new TextureChangePacket( shared_from_this(), TextureChangePacket::e_TextureChange_Cape, app.GetPlayerCapeName(GetXboxPad()) ) ) ); + if(getCustomCape() != oldCapeIndex) connection->send(std::make_shared<TextureChangePacket>(shared_from_this(), TextureChangePacket::e_TextureChange_Cape, app.GetPlayerCapeName(GetXboxPad()))); } // 4J added for testing. This moves the player in a repeated sequence of 2 modes: |
