From 0bacda32692729e4b9743f91d92cd329e198d73a Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Sat, 21 Oct 2017 17:56:09 +0100 Subject: Implement horse inventory (#4053) * Implement horse inventory * Fix sign conversions * Add API doc for ItemCategory::IsHorseArmor * Improve HandleOpenHorseInventory comment and style fixes. --- src/Entities/Player.cpp | 30 ++++++++++++++++++++++++++++++ src/Entities/Player.h | 4 ++++ 2 files changed, 34 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 0769499b1..22f0655f2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -5,6 +5,7 @@ #include "Player.h" #include "Mobs/Wolf.h" +#include "Mobs/Horse.h" #include "../BoundingBox.h" #include "../ChatColor.h" #include "../Server.h" @@ -2202,6 +2203,35 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) +void cPlayer::OpenHorseInventory() +{ + if ( + (m_AttachedTo == nullptr) || + !m_AttachedTo->IsMob() + ) + { + return; + } + + auto & Mob = static_cast(*m_AttachedTo); + + if (Mob.GetMobType() != mtHorse) + { + return; + } + + auto & Horse = static_cast(Mob); + // The client sends requests for untame horses as well but shouldn't actually open + if (Horse.IsTame()) + { + Horse.PlayerOpenWindow(*this); + } +} + + + + + bool cPlayer::SaveToDisk() { cFile::CreateFolder(FILE_IO_PREFIX + AString("players/")); // Create the "players" folder, if it doesn't exist yet (#1268) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 2685622ad..f56841613 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -409,6 +409,10 @@ public: const AString & GetLoadedWorldName() { return m_LoadedWorldName; } + /** Opens the inventory of any tame horse the player is riding. + If the player is not riding a horse or if the horse is untamed, does nothing. */ + void OpenHorseInventory(); + void UseEquippedItem(int a_Amount = 1); void SendHealth(void); -- cgit v1.2.3