diff options
| author | ModMaker101 <119018978+ModMaker101@users.noreply.github.com> | 2026-03-07 21:56:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-08 09:56:03 +0700 |
| commit | a9be52c41a02d207233199e98898fe7483d7e817 (patch) | |
| tree | 71dfaec3a86b05e9ca409b97d8eb9d7f993bfdd0 /Minecraft.World/ChestTileEntity.cpp | |
| parent | 1be5faaea781402e7de06b263eeca4c688b7712c (diff) | |
Project modernization (#630)
* 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
Diffstat (limited to 'Minecraft.World/ChestTileEntity.cpp')
| -rw-r--r-- | Minecraft.World/ChestTileEntity.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/Minecraft.World/ChestTileEntity.cpp b/Minecraft.World/ChestTileEntity.cpp index b8f323f4..ba277e24 100644 --- a/Minecraft.World/ChestTileEntity.cpp +++ b/Minecraft.World/ChestTileEntity.cpp @@ -65,7 +65,7 @@ shared_ptr<ItemInstance> ChestTileEntity::getItem(unsigned int slot) shared_ptr<ItemInstance> ChestTileEntity::removeItem(unsigned int slot, int count) { - if (items->data[slot] != NULL) + if (items->data[slot] != nullptr) { if (items->data[slot]->count <= count) { @@ -91,7 +91,7 @@ shared_ptr<ItemInstance> ChestTileEntity::removeItem(unsigned int slot, int coun shared_ptr<ItemInstance> ChestTileEntity::removeItemNoUpdate(int slot) { - if (items->data[slot] != NULL) + if (items->data[slot] != nullptr) { shared_ptr<ItemInstance> item = items->data[slot]; items->data[slot] = nullptr; @@ -103,7 +103,7 @@ shared_ptr<ItemInstance> ChestTileEntity::removeItemNoUpdate(int slot) void ChestTileEntity::setItem(unsigned int slot, shared_ptr<ItemInstance> item) { items->data[slot] = item; - if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); + if (item != nullptr && item->count > getMaxStackSize()) item->count = getMaxStackSize(); this->setChanged(); } @@ -154,10 +154,10 @@ void ChestTileEntity::save(CompoundTag *base) for (unsigned int i = 0; i < items->length; i++) { - if (items->data[i] != NULL) + if (items->data[i] != nullptr) { CompoundTag *tag = new CompoundTag(); - tag->putByte(L"Slot", (byte) i); + tag->putByte(L"Slot", static_cast<byte>(i)); items->data[i]->save(tag); listTag->add(tag); } @@ -244,17 +244,17 @@ void ChestTileEntity::checkNeighbors() } shared_ptr<ChestTileEntity> cteThis = dynamic_pointer_cast<ChestTileEntity>(shared_from_this()); - if (n.lock() != NULL) n.lock()->heyImYourNeighbor(cteThis, Direction::SOUTH); - if (s.lock() != NULL) s.lock()->heyImYourNeighbor(cteThis, Direction::NORTH); - if (e.lock() != NULL) e.lock()->heyImYourNeighbor(cteThis, Direction::WEST); - if (w.lock() != NULL) w.lock()->heyImYourNeighbor(cteThis, Direction::EAST); + if (n.lock() != nullptr) n.lock()->heyImYourNeighbor(cteThis, Direction::SOUTH); + if (s.lock() != nullptr) s.lock()->heyImYourNeighbor(cteThis, Direction::NORTH); + if (e.lock() != nullptr) e.lock()->heyImYourNeighbor(cteThis, Direction::WEST); + if (w.lock() != nullptr) w.lock()->heyImYourNeighbor(cteThis, Direction::EAST); } bool ChestTileEntity::isSameChest(int x, int y, int z) { Tile *tile = Tile::tiles[level->getTile(x, y, z)]; - if (tile == NULL || !(dynamic_cast<ChestTile *>(tile) != NULL)) return false; - return ((ChestTile *) tile)->type == getType(); + if (tile == nullptr || !(dynamic_cast<ChestTile *>(tile) != nullptr)) return false; + return static_cast<ChestTile *>(tile)->type == getType(); } void ChestTileEntity::tick() @@ -283,7 +283,7 @@ void ChestTileEntity::tick() shared_ptr<Container> container = containerMenu->getContainer(); shared_ptr<Container> thisContainer = dynamic_pointer_cast<Container>(shared_from_this()); shared_ptr<CompoundContainer> compoundContainer = dynamic_pointer_cast<CompoundContainer>(container); - if ((container == thisContainer) || (compoundContainer != NULL && compoundContainer->contains(thisContainer))) + if ((container == thisContainer) || (compoundContainer != nullptr && compoundContainer->contains(thisContainer))) { openCount++; } @@ -298,12 +298,12 @@ void ChestTileEntity::tick() float speed = 0.10f; if (openCount > 0 && openness == 0) { - if (n.lock() == NULL && w.lock() == NULL) + if (n.lock() == nullptr && w.lock() == nullptr) { double xc = x + 0.5; double zc = z + 0.5; - if (s.lock() != NULL) zc += 0.5; - if (e.lock() != NULL) xc += 0.5; + if (s.lock() != nullptr) zc += 0.5; + if (e.lock() != nullptr) xc += 0.5; // 4J-PB - Seems the chest open volume is much louder than other sounds from user reports. We'll tone it down a bit level->playSound(xc, y + 0.5, zc, eSoundType_RANDOM_CHEST_OPEN, 0.2f, level->random->nextFloat() * 0.1f + 0.9f); @@ -323,12 +323,12 @@ void ChestTileEntity::tick() { // Fix for #64546 - Customer Encountered: TU7: Chests placed by the Player are closing too fast. //openness = 0; - if (n.lock() == NULL && w.lock() == NULL) + if (n.lock() == nullptr && w.lock() == nullptr) { double xc = x + 0.5; double zc = z + 0.5; - if (s.lock() != NULL) zc += 0.5; - if (e.lock() != NULL) xc += 0.5; + if (s.lock() != nullptr) zc += 0.5; + if (e.lock() != nullptr) xc += 0.5; // 4J-PB - Seems the chest open volume is much louder than other sounds from user reports. We'll tone it down a bit level->playSound(xc, y + 0.5, zc, eSoundType_RANDOM_CHEST_CLOSE, 0.2f, level->random->nextFloat() * 0.1f + 0.9f); @@ -366,7 +366,7 @@ void ChestTileEntity::startOpen() void ChestTileEntity::stopOpen() { - if (getTile() == NULL || !( dynamic_cast<ChestTile *>( getTile() ) != NULL)) return; + if (getTile() == nullptr || !( dynamic_cast<ChestTile *>( getTile() ) != nullptr)) return; openCount--; level->tileEvent(x, y, z, getTile()->id, ChestTile::EVENT_SET_OPEN_COUNT, openCount); level->updateNeighborsAt(x, y, z, getTile()->id); @@ -389,9 +389,9 @@ int ChestTileEntity::getType() { if (type == -1) { - if (level != NULL && dynamic_cast<ChestTile *>( getTile() ) != NULL) + if (level != nullptr && dynamic_cast<ChestTile *>( getTile() ) != nullptr) { - type = ((ChestTile *) getTile())->type; + type = static_cast<ChestTile *>(getTile())->type; } else { @@ -405,12 +405,12 @@ int ChestTileEntity::getType() // 4J Added shared_ptr<TileEntity> ChestTileEntity::clone() { - shared_ptr<ChestTileEntity> result = shared_ptr<ChestTileEntity>( new ChestTileEntity() ); + shared_ptr<ChestTileEntity> result = std::make_shared<ChestTileEntity>(); TileEntity::clone(result); for (unsigned int i = 0; i < items->length; i++) { - if (items->data[i] != NULL) + if (items->data[i] != nullptr) { result->items->data[i] = ItemInstance::clone(items->data[i]); } |
