From cdc452916e3ec7e61f4a1ad822666192593b4b08 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Thu, 2 Apr 2020 12:42:15 +0000 Subject: Replace buckets to the selected hotbar slot, rather than the first available. (#4580) * Replace buckets to the selected hotbar slot, rather than the first available. Replicates vanilla behaviour, as well as being more logical. * Refactor cInventory::AddItem. Behaviour is now documented * Add new cInventory::ReplaceOneEquippedItem and ::SetEquippedItem methods * Return empty potion to the same slot after drinking * Replace buckets correctly in other situations, not simply water and lava Uses the new ReplaceOneEquippedItem method * Correct collecting water from source block with bottle * Add cPlayer::ReplaceOneEquippedItemTossRest method * Handle stacked filled buckets (in theory) Use new cPlayer::ReplaceOneEquippedItemTossRest method --- src/Inventory.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Inventory.h') diff --git a/src/Inventory.h b/src/Inventory.h index b91b16c8b..7436d7528 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -71,6 +71,7 @@ public: /** Adds as many items out of a_ItemStack as can fit. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. + Fills existing stacks first and fills the hotbar before the main inventory. Returns the number of items that fit. */ int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true); @@ -90,6 +91,13 @@ public: /** Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed */ bool RemoveOneEquippedItem(void); + /** Removes one item from the the current equipped item stack, and attempts to add the specified item stack + back to the same slot. If it is not possible to place the item in the same slot, optionally (default true) tries to + place the specified item elsewhere in the inventory. Returns the number of items successfully added. If the + currently equipped slot is empty, its contents are simply set to the given Item. + */ + int ReplaceOneEquippedItem(const cItem & a_Item, bool a_TryOtherSlots = true); + /** Returns the number of items of type a_Item that are stored */ int HowManyItems(const cItem & a_Item); @@ -143,6 +151,8 @@ public: void SetHotbarSlot(int a_HotBarSlotNum, const cItem & a_Item); /** Sets current item in shield slot */ void SetShieldSlot(const cItem & a_Item); + /** Sets current item in the equipped hotbar slot */ + void SetEquippedItem(const cItem & a_Item); /** Sets equiped item to the a_SlotNum slot number */ void SetEquippedSlotNum(int a_SlotNum); /** Returns slot number of equiped item */ -- cgit v1.2.3