2014-02-17 18:00:03 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "ItemFrame.h"
|
|
|
|
#include "ClientHandle.h"
|
|
|
|
#include "Player.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-21 16:02:30 -04:00
|
|
|
cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) :
|
|
|
|
cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z),
|
|
|
|
m_Item(E_BLOCK_AIR),
|
|
|
|
m_ItemRotation(0)
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cItemFrame::OnRightClicked(cPlayer & a_Player)
|
|
|
|
{
|
2014-09-01 15:05:45 -04:00
|
|
|
super::OnRightClicked(a_Player);
|
|
|
|
|
2014-02-17 18:00:03 -05:00
|
|
|
if (!m_Item.IsEmpty())
|
|
|
|
{
|
|
|
|
// Item not empty, rotate, clipping values to zero to three inclusive
|
2014-10-21 16:02:30 -04:00
|
|
|
m_ItemRotation++;
|
|
|
|
if (m_ItemRotation >= 8)
|
2014-02-18 06:44:09 -05:00
|
|
|
{
|
2014-10-21 16:02:30 -04:00
|
|
|
m_ItemRotation = 0;
|
2014-02-18 06:44:09 -05:00
|
|
|
}
|
2014-02-17 18:00:03 -05:00
|
|
|
}
|
|
|
|
else if (!a_Player.GetEquippedItem().IsEmpty())
|
|
|
|
{
|
|
|
|
// Item empty, and player held item not empty - add this item to self
|
|
|
|
m_Item = a_Player.GetEquippedItem();
|
|
|
|
m_Item.m_ItemCount = 1;
|
|
|
|
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
GetWorld()->BroadcastEntityMetadata(*this); // Update clients
|
2014-02-17 18:00:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-04 05:55:09 -04:00
|
|
|
void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
|
|
|
if (m_Item.IsEmpty())
|
|
|
|
{
|
2014-07-04 05:55:09 -04:00
|
|
|
super::KilledBy(a_TDI);
|
2014-02-17 18:00:03 -05:00
|
|
|
Destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative())
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
|
|
|
cItems Item;
|
|
|
|
Item.push_back(m_Item);
|
|
|
|
|
|
|
|
GetWorld()->SpawnItemPickups(Item, GetPosX(), GetPosY(), GetPosZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
SetHealth(GetMaxHealth());
|
2014-06-04 09:16:30 -04:00
|
|
|
m_Item.Empty();
|
2014-10-21 16:02:30 -04:00
|
|
|
m_ItemRotation = 0;
|
2014-06-04 09:16:30 -04:00
|
|
|
SetInvulnerableTicks(0);
|
2014-02-17 18:00:03 -05:00
|
|
|
GetWorld()->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
|
|
|
a_Items.push_back(cItem(E_ITEM_ITEM_FRAME));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|