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.World/Throwable.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.World/Throwable.cpp')
| -rw-r--r-- | Minecraft.World/Throwable.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/Minecraft.World/Throwable.cpp b/Minecraft.World/Throwable.cpp index 7d30b898..08e40aa6 100644 --- a/Minecraft.World/Throwable.cpp +++ b/Minecraft.World/Throwable.cpp @@ -106,10 +106,10 @@ void Throwable::shoot(double xd, double yd, double zd, float pow, float uncertai this->yd = yd; this->zd = zd; - float sd = (float) sqrt(xd * xd + zd * zd); + float sd = static_cast<float>(sqrt(xd * xd + zd * zd)); - yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI); - xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI); + yRotO = yRot = static_cast<float>(atan2(xd, zd) * 180 / PI); + xRotO = xRot = static_cast<float>(atan2(yd, (double)sd) * 180 / PI); life = 0; } @@ -120,9 +120,9 @@ void Throwable::lerpMotion(double xd, double yd, double zd) this->zd = zd; if (xRotO == 0 && yRotO == 0) { - float sd = (float) sqrt(xd * xd + zd * zd); - yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI); - xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI); + float sd = static_cast<float>(sqrt(xd * xd + zd * zd)); + yRotO = yRot = static_cast<float>(atan2(xd, zd) * 180 / PI); + xRotO = xRot = static_cast<float>(atan2(yd, (double)sd) * 180 / PI); } } @@ -166,7 +166,7 @@ void Throwable::tick() from = Vec3::newTemp(x, y, z); to = Vec3::newTemp(x + xd, y + yd, z + zd); - if (res != NULL) + if (res != nullptr) { to = Vec3::newTemp(res->pos->x, res->pos->y, res->pos->z); } @@ -185,7 +185,7 @@ void Throwable::tick() float rr = 0.3f; AABB *bb = e->bb->grow(rr, rr, rr); HitResult *p = bb->clip(from, to); - if (p != NULL) + if (p != nullptr) { double dd = from->distanceTo(p->pos); delete p; @@ -197,14 +197,14 @@ void Throwable::tick() } } - if (hitEntity != NULL) + if (hitEntity != nullptr) { - if(res != NULL) delete res; + if(res != nullptr) delete res; res = new HitResult(hitEntity); } } - if (res != NULL) + if (res != nullptr) { if ( (res->type == HitResult::TILE) && (level->getTile(res->x, res->y, res->z) == Tile::portalTile_Id) ) { @@ -220,9 +220,9 @@ void Throwable::tick() y += yd; z += zd; - float sd = (float) sqrt(xd * xd + zd * zd); - yRot = (float) (atan2(xd, zd) * 180 / PI); - xRot = (float) (atan2(yd, (double)sd) * 180 / PI); + float sd = static_cast<float>(sqrt(xd * xd + zd * zd)); + yRot = static_cast<float>(atan2(xd, zd) * 180 / PI); + xRot = static_cast<float>(atan2(yd, (double)sd) * 180 / PI); while (xRot - xRotO < -180) xRotO -= 360; @@ -267,14 +267,14 @@ float Throwable::getGravity() void Throwable::addAdditonalSaveData(CompoundTag *tag) { - tag->putShort(L"xTile", (short) xTile); - tag->putShort(L"yTile", (short) yTile); - tag->putShort(L"zTile", (short) zTile); - tag->putByte(L"inTile", (byte) lastTile); - tag->putByte(L"shake", (byte) shakeTime); - tag->putByte(L"inGround", (byte) (inGround ? 1 : 0)); - - if (ownerName.empty() && (owner != NULL) && owner->instanceof(eTYPE_PLAYER) ) + tag->putShort(L"xTile", static_cast<short>(xTile)); + tag->putShort(L"yTile", static_cast<short>(yTile)); + tag->putShort(L"zTile", static_cast<short>(zTile)); + tag->putByte(L"inTile", static_cast<byte>(lastTile)); + tag->putByte(L"shake", static_cast<byte>(shakeTime)); + tag->putByte(L"inGround", static_cast<byte>(inGround ? 1 : 0)); + + if (ownerName.empty() && (owner != nullptr) && owner->instanceof(eTYPE_PLAYER) ) { ownerName = owner->getAName(); } @@ -301,7 +301,7 @@ float Throwable::getShadowHeightOffs() shared_ptr<LivingEntity> Throwable::getOwner() { - if (owner == NULL && !ownerName.empty() ) + if (owner == nullptr && !ownerName.empty() ) { owner = level->getPlayerByName(ownerName); } |
