diff options
| author | void_17 <heroerror3@gmail.com> | 2026-03-02 17:37:16 +0700 |
|---|---|---|
| committer | void_17 <heroerror3@gmail.com> | 2026-03-02 17:37:16 +0700 |
| commit | 119bff351450ea16ffda550b6e0f67379b29f708 (patch) | |
| tree | d9f28714afd516bc2450f33b0a77c5e05ff4de90 /Minecraft.World/Inventory.cpp | |
| parent | 8a2a62ea1d47364f802cf9aae97668bc4a7007b5 (diff) | |
Revert "shared_ptr -> std::shared_ptr"
This reverts commit 7074f35e4ba831e358117842b99ee35b87f85ae5.
Diffstat (limited to 'Minecraft.World/Inventory.cpp')
| -rw-r--r-- | Minecraft.World/Inventory.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/Minecraft.World/Inventory.cpp b/Minecraft.World/Inventory.cpp index 7218e14c..8ef3f085 100644 --- a/Minecraft.World/Inventory.cpp +++ b/Minecraft.World/Inventory.cpp @@ -14,7 +14,7 @@ const int Inventory::INVENTORY_SIZE = 4 * 9; const int Inventory::SELECTION_SIZE = 9; // 4J Stu - The Pllayer is managed by shared_ptrs elsewhere, but it owns us so we don't want to also -// keep a std::shared_ptr of it. If we pass it on we should use shared_from_this() though +// keep a shared_ptr of it. If we pass it on we should use shared_from_this() though Inventory::Inventory(Player *player) { items = ItemInstanceArray( INVENTORY_SIZE ); @@ -35,7 +35,7 @@ Inventory::~Inventory() delete [] armor.data; } -std::shared_ptr<ItemInstance> Inventory::getSelected() +shared_ptr<ItemInstance> Inventory::getSelected() { // sanity checking to prevent exploits if (selected < SELECTION_SIZE && selected >= 0) @@ -83,11 +83,11 @@ int Inventory::getSlot(int tileId, int data) return -1; } -int Inventory::getSlotWithRemainingSpace(std::shared_ptr<ItemInstance> item) +int Inventory::getSlotWithRemainingSpace(shared_ptr<ItemInstance> item) { for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL && items[i]->id == item->id && items[i]->isStackable() + if (items[i] != NULL && items[i]->id == item->id && items[i]->isStackable() && items[i]->count < items[i]->getMaxStackSize() && items[i]->count < getMaxStackSize() && (!items[i]->isStackedByData() || items[i]->getAuxValue() == item->getAuxValue()) && ItemInstance::tagMatches(items[i], item)) @@ -182,12 +182,12 @@ void Inventory::replaceSlot(Item *item, int data) { return; } - items[selected] = std::shared_ptr<ItemInstance>(new ItemInstance(Item::items[item->id], 1, data)); + items[selected] = shared_ptr<ItemInstance>(new ItemInstance(Item::items[item->id], 1, data)); } } -int Inventory::addResource(std::shared_ptr<ItemInstance> itemInstance) +int Inventory::addResource(shared_ptr<ItemInstance> itemInstance) { int type = itemInstance->id; @@ -200,7 +200,7 @@ int Inventory::addResource(std::shared_ptr<ItemInstance> itemInstance) if (slot < 0) return count; if (items[slot] == NULL) { - items[slot] = ItemInstance::clone(itemInstance); + items[slot] = ItemInstance::clone(itemInstance); player->handleCollectItem(itemInstance); } return 0; @@ -211,7 +211,7 @@ int Inventory::addResource(std::shared_ptr<ItemInstance> itemInstance) if (slot < 0) return count; if (items[slot] == NULL) { - items[slot] = std::shared_ptr<ItemInstance>( new ItemInstance(type, 0, itemInstance->getAuxValue()) ); + items[slot] = shared_ptr<ItemInstance>( new ItemInstance(type, 0, itemInstance->getAuxValue()) ); // 4J Stu - Brought forward from 1.2 if (itemInstance->hasTag()) { @@ -269,16 +269,16 @@ bool Inventory::removeResource(int type,int iAuxVal) return true; } -void Inventory::removeResources(std::shared_ptr<ItemInstance> item) +void Inventory::removeResources(shared_ptr<ItemInstance> item) { - if(item == NULL) return; + if(item == NULL) return; int countToRemove = item->count; for (unsigned int i = 0; i < items.length; i++) { if (items[i] != NULL && items[i]->sameItemWithTags(item)) { - int slotCount = items[i]->count; + int slotCount = items[i]->count; items[i]->count -= countToRemove; if(slotCount < countToRemove) { @@ -293,14 +293,14 @@ void Inventory::removeResources(std::shared_ptr<ItemInstance> item) } } -std::shared_ptr<ItemInstance> Inventory::getResourceItem(int type) +shared_ptr<ItemInstance> Inventory::getResourceItem(int type) { int slot = getSlot(type); if (slot < 0) return nullptr; return getItem( slot ); } -std::shared_ptr<ItemInstance> Inventory::getResourceItem(int type,int iAuxVal) +shared_ptr<ItemInstance> Inventory::getResourceItem(int type,int iAuxVal) { int slot = getSlot(type,iAuxVal); if (slot < 0) return nullptr; @@ -317,12 +317,12 @@ bool Inventory::hasResource(int type) void Inventory::swapSlots(int from, int to) { - std::shared_ptr<ItemInstance> tmp = items[to]; + shared_ptr<ItemInstance> tmp = items[to]; items[to] = items[from]; items[from] = tmp; } -bool Inventory::add(std::shared_ptr<ItemInstance> item) +bool Inventory::add(shared_ptr<ItemInstance> item) { // 4J Stu - Fix for duplication glitch if(item->count <= 0) return true; @@ -359,7 +359,7 @@ bool Inventory::add(std::shared_ptr<ItemInstance> item) { player->handleCollectItem(item); - player->awardStat( + player->awardStat( GenericStats::itemsCollected(item->id, item->getAuxValue()), GenericStats::param_itemsCollected(item->id, item->getAuxValue(), item->GetCount())); @@ -377,7 +377,7 @@ bool Inventory::add(std::shared_ptr<ItemInstance> item) return false; } -std::shared_ptr<ItemInstance> Inventory::removeItem(unsigned int slot, int count) +shared_ptr<ItemInstance> Inventory::removeItem(unsigned int slot, int count) { ItemInstanceArray pile = items; @@ -391,13 +391,13 @@ std::shared_ptr<ItemInstance> Inventory::removeItem(unsigned int slot, int count { if (pile[slot]->count <= count) { - std::shared_ptr<ItemInstance> item = pile[slot]; + shared_ptr<ItemInstance> item = pile[slot]; pile[slot] = nullptr; return item; } else { - std::shared_ptr<ItemInstance> i = pile[slot]->remove(count); + shared_ptr<ItemInstance> i = pile[slot]->remove(count); if (pile[slot]->count == 0) pile[slot] = nullptr; return i; } @@ -405,7 +405,7 @@ std::shared_ptr<ItemInstance> Inventory::removeItem(unsigned int slot, int count return nullptr; } -std::shared_ptr<ItemInstance> Inventory::removeItemNoUpdate(int slot) +shared_ptr<ItemInstance> Inventory::removeItemNoUpdate(int slot) { ItemInstanceArray pile = items; if (slot >= items.length) @@ -416,14 +416,14 @@ std::shared_ptr<ItemInstance> Inventory::removeItemNoUpdate(int slot) if (pile[slot] != NULL) { - std::shared_ptr<ItemInstance> item = pile[slot]; + shared_ptr<ItemInstance> item = pile[slot]; pile[slot] = nullptr; return item; } return nullptr; } -void Inventory::setItem(unsigned int slot, std::shared_ptr<ItemInstance> item) +void Inventory::setItem(unsigned int slot, shared_ptr<ItemInstance> item) { #ifdef _DEBUG if(item!=NULL) @@ -447,7 +447,7 @@ void Inventory::setItem(unsigned int slot, std::shared_ptr<ItemInstance> item) else { items[slot] = item; - } + } player->handleCollectItem(item); /* ItemInstanceArray& pile = items; @@ -512,7 +512,7 @@ void Inventory::load(ListTag<CompoundTag> *inventoryList) { CompoundTag *tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; - std::shared_ptr<ItemInstance> item = std::shared_ptr<ItemInstance>( ItemInstance::fromTag(tag) ); + shared_ptr<ItemInstance> item = shared_ptr<ItemInstance>( ItemInstance::fromTag(tag) ); if (item != NULL) { if (slot >= 0 && slot < items.length) items[slot] = item; @@ -526,7 +526,7 @@ unsigned int Inventory::getContainerSize() return items.length + 4; } -std::shared_ptr<ItemInstance> Inventory::getItem(unsigned int slot) +shared_ptr<ItemInstance> Inventory::getItem(unsigned int slot) { // 4J Stu - Changed this a little from the Java so it's less funny if( slot >= items.length ) @@ -559,9 +559,9 @@ int Inventory::getMaxStackSize() return MAX_INVENTORY_STACK_SIZE; } -int Inventory::getAttackDamage(std::shared_ptr<Entity> entity) +int Inventory::getAttackDamage(shared_ptr<Entity> entity) { - std::shared_ptr<ItemInstance> item = getItem(selected); + shared_ptr<ItemInstance> item = getItem(selected); if (item != NULL) return item->getAttackDamage(entity); return 1; } @@ -570,12 +570,12 @@ bool Inventory::canDestroy(Tile *tile) { if (tile->material->isAlwaysDestroyable()) return true; - std::shared_ptr<ItemInstance> item = getItem(selected); + shared_ptr<ItemInstance> item = getItem(selected); if (item != NULL) return item->canDestroySpecial(tile); return false; } -std::shared_ptr<ItemInstance> Inventory::getArmor(int layer) +shared_ptr<ItemInstance> Inventory::getArmor(int layer) { return armor[layer]; } @@ -640,7 +640,7 @@ void Inventory::setChanged() changed = true; } -bool Inventory::isSame(std::shared_ptr<Inventory> copy) +bool Inventory::isSame(shared_ptr<Inventory> copy) { for (unsigned int i = 0; i < items.length; i++) { @@ -654,7 +654,7 @@ bool Inventory::isSame(std::shared_ptr<Inventory> copy) } -bool Inventory::isSame(std::shared_ptr<ItemInstance> a, std::shared_ptr<ItemInstance> b) +bool Inventory::isSame(shared_ptr<ItemInstance> a, shared_ptr<ItemInstance> b) { if (a == NULL && b == NULL) return true; if (a == NULL || b == NULL) return false; @@ -663,9 +663,9 @@ bool Inventory::isSame(std::shared_ptr<ItemInstance> a, std::shared_ptr<ItemInst } -std::shared_ptr<Inventory> Inventory::copy() +shared_ptr<Inventory> Inventory::copy() { - std::shared_ptr<Inventory> copy = std::shared_ptr<Inventory>( new Inventory(NULL) ); + shared_ptr<Inventory> copy = shared_ptr<Inventory>( new Inventory(NULL) ); for (unsigned int i = 0; i < items.length; i++) { copy->items[i] = items[i] != NULL ? items[i]->copy() : nullptr; @@ -677,25 +677,25 @@ std::shared_ptr<Inventory> Inventory::copy() return copy; } -void Inventory::setCarried(std::shared_ptr<ItemInstance> carried) +void Inventory::setCarried(shared_ptr<ItemInstance> carried) { this->carried = carried; player->handleCollectItem(carried); } -std::shared_ptr<ItemInstance> Inventory::getCarried() +shared_ptr<ItemInstance> Inventory::getCarried() { return carried; } -bool Inventory::stillValid(std::shared_ptr<Player> player) +bool Inventory::stillValid(shared_ptr<Player> player) { if (this->player->removed) return false; if (player->distanceToSqr(this->player->shared_from_this()) > 8 * 8) return false; return true; } -bool Inventory::contains(std::shared_ptr<ItemInstance> itemInstance) +bool Inventory::contains(shared_ptr<ItemInstance> itemInstance) { for (unsigned int i = 0; i < armor.length; i++) { @@ -718,7 +718,7 @@ void Inventory::stopOpen() // TODO Auto-generated method stub } -void Inventory::replaceWith(std::shared_ptr<Inventory> other) +void Inventory::replaceWith(shared_ptr<Inventory> other) { for (int i = 0; i < items.length; i++) { @@ -730,7 +730,7 @@ void Inventory::replaceWith(std::shared_ptr<Inventory> other) } } -int Inventory::countMatches(std::shared_ptr<ItemInstance> itemInstance) +int Inventory::countMatches(shared_ptr<ItemInstance> itemInstance) { if(itemInstance == NULL) return 0; int count = 0; |
