From 464ec47eb7bf61ca1e9c2af6559ad2225038d06e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 17 Feb 2014 23:00:03 +0000 Subject: Implemented item frames, a part of #689 + Implemented Item Frames * Fixed Pitch and Yaw being wrongly flipped in the protocol (XOFT!) --- src/Entities/ItemFrame.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/Entities/ItemFrame.cpp (limited to 'src/Entities/ItemFrame.cpp') 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)); + } +} + + + + -- cgit v1.2.3 From d5ee899d0e3039ace71077b5fe3d7e4a5c3601ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 11:44:09 +0000 Subject: Added a brace ==== { } { __ } { | | } ==== REMOVE ALL THE BRACES!! --- src/Entities/ItemFrame.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Entities/ItemFrame.cpp') diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index e4e50bd8d..65b0edb25 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -48,7 +48,9 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player) // 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()) { -- cgit v1.2.3 From 05789f9e66abd9ad211fb27fb36bb45915c6d19e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 21:33:33 +0000 Subject: Changed BlockFace type to eBlockFace --- src/Entities/ItemFrame.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/Entities/ItemFrame.cpp') diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 65b0edb25..8cfa5e18d 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -9,7 +9,7 @@ -cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) +cItemFrame::cItemFrame(eBlockFace 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), @@ -17,15 +17,6 @@ cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) { 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); - } } @@ -34,7 +25,28 @@ cItemFrame::cItemFrame(int a_BlockFace, double a_X, double a_Y, double a_Z) void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) { - a_ClientHandle.SendSpawnObject(*this, 71, m_BlockFace, (Byte)GetYaw(), (Byte)GetPitch()); + int Dir = 0; + + // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces + switch (m_BlockFace) + { + case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZM: Dir = 2; break; + case BLOCK_FACE_XM: Dir = 1; break; + case BLOCK_FACE_XP: Dir = 3; break; + default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; + } + + if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 + { + SetYaw((Dir * 90) - 180); + } + else + { + SetYaw(Dir * 90); + } + + a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch()); } @@ -91,6 +103,7 @@ void cItemFrame::KilledBy(cEntity * a_Killer) SetHealth(GetMaxHealth()); m_Item.Clear(); + m_Rotation = 0; GetWorld()->BroadcastEntityMetadata(*this); } -- cgit v1.2.3 From 7ac7304c913f9cf82a906589904068a3e7f09d43 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 02:45:25 +0100 Subject: Add item frame saving. --- src/Entities/ItemFrame.cpp | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'src/Entities/ItemFrame.cpp') diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 8cfa5e18d..9dd909880 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -10,43 +10,10 @@ cItemFrame::cItemFrame(eBlockFace 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) + : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z) + , m_Item(E_BLOCK_AIR) + , m_Rotation(0) { - SetMaxHealth(1); - SetHealth(1); -} - - - - - -void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) -{ - int Dir = 0; - - // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces - switch (m_BlockFace) - { - case BLOCK_FACE_ZP: break; // Initialised to zero - case BLOCK_FACE_ZM: Dir = 2; break; - case BLOCK_FACE_XM: Dir = 1; break; - case BLOCK_FACE_XP: Dir = 3; break; - default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; - } - - if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 - { - SetYaw((Dir * 90) - 180); - } - else - { - SetYaw(Dir * 90); - } - - a_ClientHandle.SendSpawnObject(*this, 71, Dir, (Byte)GetYaw(), (Byte)GetPitch()); } -- cgit v1.2.3