From 28614b922fb77149a54da1a87bebfbc98736f296 Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Sun, 8 Mar 2026 19:08:36 -0400 Subject: 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 --- Minecraft.World/ChestTileEntity.cpp | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'Minecraft.World/ChestTileEntity.cpp') 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 ChestTileEntity::getItem(unsigned int slot) shared_ptr 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 ChestTileEntity::removeItem(unsigned int slot, int coun shared_ptr ChestTileEntity::removeItemNoUpdate(int slot) { - if (items->data[slot] != NULL) + if (items->data[slot] != nullptr) { shared_ptr item = items->data[slot]; items->data[slot] = nullptr; @@ -103,7 +103,7 @@ shared_ptr ChestTileEntity::removeItemNoUpdate(int slot) void ChestTileEntity::setItem(unsigned int slot, shared_ptr 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(i)); items->data[i]->save(tag); listTag->add(tag); } @@ -244,17 +244,17 @@ void ChestTileEntity::checkNeighbors() } shared_ptr cteThis = dynamic_pointer_cast(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(tile) != NULL)) return false; - return ((ChestTile *) tile)->type == getType(); + if (tile == nullptr || !(dynamic_cast(tile) != nullptr)) return false; + return static_cast(tile)->type == getType(); } void ChestTileEntity::tick() @@ -283,7 +283,7 @@ void ChestTileEntity::tick() shared_ptr container = containerMenu->getContainer(); shared_ptr thisContainer = dynamic_pointer_cast(shared_from_this()); shared_ptr compoundContainer = dynamic_pointer_cast(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( getTile() ) != NULL)) return; + if (getTile() == nullptr || !( dynamic_cast( 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( getTile() ) != NULL) + if (level != nullptr && dynamic_cast( getTile() ) != nullptr) { - type = ((ChestTile *) getTile())->type; + type = static_cast(getTile())->type; } else { @@ -405,12 +405,12 @@ int ChestTileEntity::getType() // 4J Added shared_ptr ChestTileEntity::clone() { - shared_ptr result = shared_ptr( new ChestTileEntity() ); + shared_ptr result = std::make_shared(); 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]); } -- cgit v1.2.3