diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/Inventory.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/Inventory.cpp')
| -rw-r--r-- | Minecraft.World/Inventory.cpp | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/Minecraft.World/Inventory.cpp b/Minecraft.World/Inventory.cpp index 8ef3f085..f6a136c9 100644 --- a/Minecraft.World/Inventory.cpp +++ b/Minecraft.World/Inventory.cpp @@ -154,35 +154,63 @@ void Inventory::swapPaint(int wheel) selected -= 9; } -void Inventory::clearInventory() +int Inventory::clearInventory(int id, int data) { - for (unsigned int i = 0; i < items.length; i++) + int count = 0; + for (int i = 0; i < items.length; i++) { + shared_ptr<ItemInstance> item = items[i]; + if (item == NULL) continue; + if (id > -1 && item->id != id) continue; + if (data > -1 && item->getAuxValue() != data) continue; + + count += item->count; items[i] = nullptr; } - for (unsigned int i = 0; i < armor.length; i++) + for (int i = 0; i < armor.length; i++) { + shared_ptr<ItemInstance> item = armor[i]; + if (item == NULL) continue; + if (id > -1 && item->id != id) continue; + if (data > -1 && item->getAuxValue() != data) continue; + + count += item->count; armor[i] = nullptr; } + + if (carried != NULL) + { + if (id > -1 && carried->id != id) return count; + if (data > -1 && carried->getAuxValue() != data) return count; + + count += carried->count; + setCarried(nullptr); + } + + return count; } void Inventory::replaceSlot(Item *item, int data) { if (item != NULL) { + // It's too easy to accidentally pick block and lose enchanted items. + if (heldItem != NULL && heldItem->isEnchantable() && getSlot(heldItem->id, heldItem->getDamageValue()) == selected) + { + return; + } + int oldSlot = getSlot(item->id, data); if (oldSlot >= 0) { + int oldSlotCount = items[oldSlot]->count; items[oldSlot] = items[selected]; + items[selected] = shared_ptr<ItemInstance>( new ItemInstance(Item::items[item->id], oldSlotCount, data) ); } - - // It's too easy to accidentally pick block and lose enchanted - // items. - if (heldItem != NULL && heldItem->isEnchantable() && getSlot(heldItem->id, heldItem->getDamageValue()) == selected) + else { - return; + items[selected] = shared_ptr<ItemInstance>(new ItemInstance(Item::items[item->id], 1, data)); } - items[selected] = shared_ptr<ItemInstance>(new ItemInstance(Item::items[item->id], 1, data)); } } @@ -324,8 +352,8 @@ void Inventory::swapSlots(int from, int to) bool Inventory::add(shared_ptr<ItemInstance> item) { - // 4J Stu - Fix for duplication glitch - if(item->count <= 0) return true; + if (item == NULL) return false; + if (item->count == 0) return false; if (!item->isDamaged()) { @@ -364,7 +392,7 @@ bool Inventory::add(shared_ptr<ItemInstance> item) GenericStats::param_itemsCollected(item->id, item->getAuxValue(), item->GetCount())); items[slot] = ItemInstance::clone(item); - items[slot]->popTime = Inventory::POP_TIME_DURATION; + items[slot]->popTime = POP_TIME_DURATION; item->count = 0; return true; } @@ -549,21 +577,24 @@ shared_ptr<ItemInstance> Inventory::getItem(unsigned int slot) */ } -int Inventory::getName() +wstring Inventory::getName() { - return IDS_INVENTORY; + return app.GetString(IDS_INVENTORY); } -int Inventory::getMaxStackSize() +wstring Inventory::getCustomName() { - return MAX_INVENTORY_STACK_SIZE; + return L""; } -int Inventory::getAttackDamage(shared_ptr<Entity> entity) +bool Inventory::hasCustomName() { - shared_ptr<ItemInstance> item = getItem(selected); - if (item != NULL) return item->getAttackDamage(entity); - return 1; + return false; +} + +int Inventory::getMaxStackSize() +{ + return MAX_INVENTORY_STACK_SIZE; } bool Inventory::canDestroy(Tile *tile) @@ -595,7 +626,7 @@ int Inventory::getArmorValue() return val; } -void Inventory::hurtArmor(int dmg) +void Inventory::hurtArmor(float dmg) { dmg = dmg / 4; if (dmg < 1) @@ -606,7 +637,7 @@ void Inventory::hurtArmor(int dmg) { if (armor[i] != NULL && dynamic_cast<ArmorItem *>( armor[i]->getItem() ) != NULL ) { - armor[i]->hurt(dmg, dynamic_pointer_cast<Mob>( player->shared_from_this() ) ); + armor[i]->hurtAndBreak( (int) dmg, dynamic_pointer_cast<LivingEntity>( player->shared_from_this() ) ); if (armor[i]->count == 0) { armor[i] = nullptr; @@ -699,11 +730,11 @@ bool Inventory::contains(shared_ptr<ItemInstance> itemInstance) { for (unsigned int i = 0; i < armor.length; i++) { - if (armor[i] != NULL && armor[i]->equals(itemInstance)) return true; + if (armor[i] != NULL && armor[i]->sameItem(itemInstance)) return true; } for (unsigned int i = 0; i < items.length; i++) { - if (items[i] != NULL && items[i]->equals(itemInstance)) return true; + if (items[i] != NULL && items[i]->sameItem(itemInstance)) return true; } return false; } @@ -718,6 +749,11 @@ void Inventory::stopOpen() // TODO Auto-generated method stub } +bool Inventory::canPlaceItem(int slot, shared_ptr<ItemInstance> item) +{ + return true; +} + void Inventory::replaceWith(shared_ptr<Inventory> other) { for (int i = 0; i < items.length; i++) @@ -728,6 +764,8 @@ void Inventory::replaceWith(shared_ptr<Inventory> other) { armor[i] = ItemInstance::clone(other->armor[i]); } + + selected = other->selected; } int Inventory::countMatches(shared_ptr<ItemInstance> itemInstance) |
