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/Mobs/Cow.cpp | 4 ++-- src/Mobs/Mooshroom.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Mobs') diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index a7fb0d476..559b6caea 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -44,10 +44,10 @@ void cCow::OnRightClicked(cPlayer & a_Player) short HeldItem = a_Player.GetEquippedItem().m_ItemType; if (HeldItem == E_ITEM_BUCKET) { + // Milk the cow. if (!a_Player.IsGameModeCreative()) { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(cItem(E_ITEM_MILK)); + a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MILK)); } } } diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 31a1b8978..135a8ba90 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -43,18 +43,18 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player) { case E_ITEM_BUCKET: { + // Milk the cow. if (!a_Player.IsGameModeCreative()) { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(cItem(E_ITEM_MILK)); + a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MILK)); } } break; case E_ITEM_BOWL: { + // Soup the cow. if (!a_Player.IsGameModeCreative()) { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(cItem(E_ITEM_MUSHROOM_SOUP)); + a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MUSHROOM_SOUP)); } } break; case E_ITEM_SHEARS: -- cgit v1.2.3