From b1628846d9a47df35b107fbd9979a5f3c1a91656 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Sun, 2 Jul 2017 07:40:59 +0200 Subject: Fix horse taming (#3820) * Horses rear when untamed and right-clicked with an item --- src/Mobs/Horse.cpp | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index acf79d3b1..b51e7843e 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -4,6 +4,7 @@ #include "../World.h" #include "../EffectID.h" #include "../Entities/Player.h" +#include "Broadcaster.h" @@ -24,7 +25,7 @@ cHorse::cHorse(int Type, int Color, int Style, int TameTimes) : m_TimesToTame(TameTimes), m_TameAttemptTimes(0), m_RearTickCount(0), - m_MaxSpeed(20.0) + m_MaxSpeed(14.0) { } @@ -75,7 +76,7 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } else { - // TODO: emit hearts here + m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast(GetPosition()), Vector3f{}, 0, 5); m_bIsTame = true; } } @@ -104,26 +105,31 @@ void cHorse::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); - if (!m_bIsSaddled && m_bIsTame) + if (m_bIsTame) { - if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE) + if (!m_bIsSaddled) { - // Saddle the horse: - if (!a_Player.IsGameModeCreative()) + if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE) { - a_Player.GetInventory().RemoveOneEquippedItem(); + // Saddle the horse: + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + m_bIsSaddled = true; + m_World->BroadcastEntityMetadata(*this); + } + else + { + a_Player.AttachTo(this); } - m_bIsSaddled = true; - m_World->BroadcastEntityMetadata(*this); } - else if (!a_Player.GetEquippedItem().IsEmpty()) + else { - // The horse doesn't like being hit, make it rear: - m_bIsRearing = true; - m_RearTickCount = 0; + a_Player.AttachTo(this); } } - else + else if (a_Player.GetEquippedItem().IsEmpty()) { if (m_Attachee != nullptr) { @@ -144,6 +150,12 @@ void cHorse::OnRightClicked(cPlayer & a_Player) m_TameAttemptTimes++; a_Player.AttachTo(this); } + else + { + m_bIsRearing = true; + m_RearTickCount = 0; + m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f); + } } -- cgit v1.2.3