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/DispenserTileEntity.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/DispenserTileEntity.cpp')
| -rw-r--r-- | Minecraft.World/DispenserTileEntity.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Minecraft.World/DispenserTileEntity.cpp b/Minecraft.World/DispenserTileEntity.cpp index 3e743e22..b1d8ecde 100644 --- a/Minecraft.World/DispenserTileEntity.cpp +++ b/Minecraft.World/DispenserTileEntity.cpp @@ -35,7 +35,7 @@ shared_ptr<ItemInstance> DispenserTileEntity::getItem(unsigned int slot) shared_ptr<ItemInstance> DispenserTileEntity::removeItem(unsigned int slot, int count) { - if (items[slot] != NULL) + if (items[slot] != nullptr) { if (items[slot]->count <= count) { @@ -61,7 +61,7 @@ shared_ptr<ItemInstance> DispenserTileEntity::removeItem(unsigned int slot, int shared_ptr<ItemInstance> DispenserTileEntity::removeItemNoUpdate(int slot) { - if (items[slot] != NULL) + if (items[slot] != nullptr) { shared_ptr<ItemInstance> item = items[slot]; items[slot] = nullptr; @@ -73,7 +73,7 @@ shared_ptr<ItemInstance> DispenserTileEntity::removeItemNoUpdate(int slot) // 4J-PB added for spawn eggs not being useable due to limits, so add them in again void DispenserTileEntity::AddItemBack(shared_ptr<ItemInstance>item, unsigned int slot) { - if (items[slot] != NULL) + if (items[slot] != nullptr) { // just increment the count of the items if(item->id==items[slot]->id) @@ -85,7 +85,7 @@ void DispenserTileEntity::AddItemBack(shared_ptr<ItemInstance>item, unsigned int else { items[slot] = item; - if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); + if (item != nullptr && item->count > getMaxStackSize()) item->count = getMaxStackSize(); setChanged(); } } @@ -99,10 +99,10 @@ bool DispenserTileEntity::removeProjectile(int itemId) { for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL && items[i]->id == itemId) + if (items[i] != nullptr && items[i]->id == itemId) { shared_ptr<ItemInstance> removedItem = removeItem(i, 1); - return removedItem != NULL; + return removedItem != nullptr; } } return false; @@ -114,7 +114,7 @@ int DispenserTileEntity::getRandomSlot() int replaceOdds = 1; for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL && random->nextInt(replaceOdds++) == 0) + if (items[i] != nullptr && random->nextInt(replaceOdds++) == 0) { replaceSlot = i; } @@ -126,7 +126,7 @@ int DispenserTileEntity::getRandomSlot() void DispenserTileEntity::setItem(unsigned int slot, shared_ptr<ItemInstance> item) { items[slot] = item; - if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); + if (item != nullptr && item->count > getMaxStackSize()) item->count = getMaxStackSize(); setChanged(); } @@ -134,7 +134,7 @@ int DispenserTileEntity::addItem(shared_ptr<ItemInstance> item) { for (int i = 0; i < items.length; i++) { - if (items[i] == NULL || items[i]->id == 0) + if (items[i] == nullptr || items[i]->id == 0) { setItem(i, item); return i; @@ -186,10 +186,10 @@ void DispenserTileEntity::save(CompoundTag *base) for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL) + if (items[i] != nullptr) { CompoundTag *tag = new CompoundTag(); - tag->putByte(L"Slot", (byte) i); + tag->putByte(L"Slot", static_cast<byte>(i)); items[i]->save(tag); listTag->add(tag); } @@ -231,12 +231,12 @@ bool DispenserTileEntity::canPlaceItem(int slot, shared_ptr<ItemInstance> item) // 4J Added shared_ptr<TileEntity> DispenserTileEntity::clone() { - shared_ptr<DispenserTileEntity> result = shared_ptr<DispenserTileEntity>( new DispenserTileEntity() ); + shared_ptr<DispenserTileEntity> result = std::make_shared<DispenserTileEntity>(); TileEntity::clone(result); for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL) + if (items[i] != nullptr) { result->items[i] = ItemInstance::clone(items[i]); } |
