summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.h2
-rw-r--r--src/Entities/ItemFrame.cpp109
-rw-r--r--src/Entities/ItemFrame.h42
3 files changed, 153 insertions, 0 deletions
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b2edfc2b4..79150ee51 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -81,6 +81,7 @@ public:
etProjectile,
etExpOrb,
etFloater,
+ etItemFrame,
// Common variations
etMob = etMonster, // DEPRECATED, use etMonster instead!
@@ -139,6 +140,7 @@ public:
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
bool IsFloater (void) const { return (m_EntityType == etFloater); }
+ bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
new file mode 100644
index 000000000..e4e50bd8d
--- /dev/null
+++ b/src/Entities/ItemFrame.cpp
@@ -0,0 +1,109 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "ItemFrame.h"
+#include "ClientHandle.h"
+#include "Player.h"
+
+
+
+
+
+cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z)
+ : cEntity(etItemFrame, a_X, a_Y, a_Z, 0.8, 0.8),
+ m_BlockFace(a_BlockFace),
+ m_Item(E_BLOCK_AIR),
+ m_Rotation(0)
+{
+ SetMaxHealth(1);
+ SetHealth(1);
+
+ if ((a_BlockFace == 0) || (a_BlockFace == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180
+ {
+ SetYaw((a_BlockFace * 90) - 180);
+ }
+ else
+ {
+ SetYaw(a_BlockFace * 90);
+ }
+}
+
+
+
+
+
+void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle)
+{
+ a_ClientHandle.SendSpawnObject(*this, 71, m_BlockFace, (Byte)GetYaw(), (Byte)GetPitch());
+}
+
+
+
+
+
+void cItemFrame::OnRightClicked(cPlayer & a_Player)
+{
+ if (!m_Item.IsEmpty())
+ {
+ // Item not empty, rotate, clipping values to zero to three inclusive
+ m_Rotation++;
+ if (m_Rotation >= 4)
+ m_Rotation = 0;
+ }
+ 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();
+ }
+ }
+
+ GetWorld()->BroadcastEntityMetadata(*this); // Update clients
+}
+
+
+
+
+
+
+void cItemFrame::KilledBy(cEntity * a_Killer)
+{
+ if (m_Item.IsEmpty())
+ {
+ super::KilledBy(a_Killer);
+ Destroy();
+ return;
+ }
+
+ if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
+ {
+ cItems Item;
+ Item.push_back(m_Item);
+
+ GetWorld()->SpawnItemPickups(Item, GetPosX(), GetPosY(), GetPosZ());
+ }
+
+ SetHealth(GetMaxHealth());
+ m_Item.Clear();
+ GetWorld()->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
+void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer)
+{
+ if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
+ {
+ a_Items.push_back(cItem(E_ITEM_ITEM_FRAME));
+ }
+}
+
+
+
+
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
new file mode 100644
index 000000000..15a03e54a
--- /dev/null
+++ b/src/Entities/ItemFrame.h
@@ -0,0 +1,42 @@
+
+#pragma once
+
+#include "Entity.h"
+
+
+
+
+
+// tolua_begin
+class cItemFrame :
+ public cEntity
+{
+ // tolua_end
+ typedef cEntity super;
+
+public:
+
+ CLASS_PROTODEF(cItemFrame);
+
+ cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z);
+
+ const cItem & GetItem(void) { return m_Item; }
+ Byte GetRotation(void) const { return m_Rotation; }
+
+private:
+
+ virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
+ virtual void OnRightClicked(cPlayer & a_Player) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override {};
+ virtual void KilledBy(cEntity * a_Killer) override;
+ virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
+
+ int m_BlockFace;
+ cItem m_Item;
+ Byte m_Rotation;
+
+}; // tolua_export
+
+
+
+