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/ItemEntity.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/ItemEntity.cpp')
| -rw-r--r-- | Minecraft.World/ItemEntity.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Minecraft.World/ItemEntity.cpp b/Minecraft.World/ItemEntity.cpp index 66d271f7..5dc1db6e 100644 --- a/Minecraft.World/ItemEntity.cpp +++ b/Minecraft.World/ItemEntity.cpp @@ -20,7 +20,7 @@ void ItemEntity::_init() age = 0; throwTime = 0; health = 5; - bobOffs = (float) (Math::random() * PI * 2); + bobOffs = static_cast<float>(Math::random() * PI * 2); // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that // the derived version of the function is called @@ -36,11 +36,11 @@ void ItemEntity::_init(Level *level, double x, double y, double z) setPos(x, y, z); - yRot = (float) (Math::random() * 360); + yRot = static_cast<float>(Math::random() * 360); - xd = (float) (Math::random() * 0.2f - 0.1f); + xd = static_cast<float>(Math::random() * 0.2f - 0.1f); yd = +0.2f; - zd = (float) (Math::random() * 0.2f - 0.1f); + zd = static_cast<float>(Math::random() * 0.2f - 0.1f); } ItemEntity::ItemEntity(Level *level, double x, double y, double z) : Entity(level) @@ -66,7 +66,7 @@ ItemEntity::ItemEntity(Level *level) : Entity( level ) void ItemEntity::defineSynchedData() { - getEntityData()->defineNULL(DATA_ITEM, NULL); + getEntityData()->defineNULL(DATA_ITEM, nullptr); } void ItemEntity::tick() @@ -84,7 +84,7 @@ void ItemEntity::tick() // 4J - added parameter here so that these don't care about colliding with other entities move(xd, yd, zd, true); - bool moved = (int) xo != (int) x || (int) yo != (int) y || (int) zo != (int) z; + bool moved = static_cast<int>(xo) != static_cast<int>(x) || static_cast<int>(yo) != static_cast<int>(y) || static_cast<int>(zo) != static_cast<int>(z); if (moved || tickCount % 25 == 0) { @@ -192,7 +192,7 @@ bool ItemEntity::hurt(DamageSource *source, float damage) if (level->isClientSide ) return false; if (isInvulnerable()) return false; - if (getItem() != NULL && getItem()->id == Item::netherStar_Id && source->isExplosion()) return false; + if (getItem() != nullptr && getItem()->id == Item::netherStar_Id && source->isExplosion()) return false; markHurt(); health -= damage; if (health <= 0) @@ -204,9 +204,9 @@ bool ItemEntity::hurt(DamageSource *source, float damage) void ItemEntity::addAdditonalSaveData(CompoundTag *entityTag) { - entityTag->putShort(L"Health", (byte) health); - entityTag->putShort(L"Age", (short) age); - if (getItem() != NULL) entityTag->putCompound(L"Item", getItem()->save(new CompoundTag())); + entityTag->putShort(L"Health", static_cast<byte>(health)); + entityTag->putShort(L"Age", static_cast<short>(age)); + if (getItem() != nullptr) entityTag->putCompound(L"Item", getItem()->save(new CompoundTag())); } void ItemEntity::readAdditionalSaveData(CompoundTag *tag) @@ -215,7 +215,7 @@ void ItemEntity::readAdditionalSaveData(CompoundTag *tag) age = tag->getShort(L"Age"); CompoundTag *itemTag = tag->getCompound(L"Item"); setItem(ItemInstance::fromTag(itemTag)); - if (getItem() == NULL) remove(); + if (getItem() == nullptr) remove(); } void ItemEntity::playerTouch(shared_ptr<Player> player) @@ -280,14 +280,14 @@ shared_ptr<ItemInstance> ItemEntity::getItem() { shared_ptr<ItemInstance> result = getEntityData()->getItemInstance(DATA_ITEM); - if (result == NULL) + if (result == nullptr) { - if (level != NULL) + if (level != nullptr) { app.DebugPrintf("Item entity %d has no item?!\n", entityId); //level.getLogger().severe("Item entity " + entityId + " has no item?!"); } - return shared_ptr<ItemInstance>(new ItemInstance(Tile::stone)); + return std::make_shared<ItemInstance>(Tile::stone); } return result; |
