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/Items/ItemHandler.cpp | 3 +++ src/Items/ItemItemFrame.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/Items/ItemItemFrame.h (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..da1cd768d 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -21,6 +21,7 @@ #include "ItemFishingRod.h" #include "ItemFlowerPot.h" #include "ItemFood.h" +#include "ItemItemFrame.h" #include "ItemHoe.h" #include "ItemLeaves.h" #include "ItemLighter.h" @@ -105,6 +106,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); + case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); @@ -342,6 +344,7 @@ char cItemHandler::GetMaxStackSize(void) case E_ITEM_GUNPOWDER: return 64; case E_ITEM_HEAD: return 64; case E_ITEM_IRON: return 64; + case E_ITEM_ITEM_FRAME: return 64; case E_ITEM_LEATHER: return 64; case E_ITEM_MAGMA_CREAM: return 64; case E_ITEM_MAP: return 64; diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h new file mode 100644 index 000000000..39be48b54 --- /dev/null +++ b/src/Items/ItemItemFrame.h @@ -0,0 +1,62 @@ + +#pragma once + +#include "ItemHandler.h" +#include "Entities/ItemFrame.h" +#include "../Entities/Player.h" + + + + + +class cItemItemFrameHandler : + public cItemHandler +{ +public: + cItemItemFrameHandler(int a_ItemType) + : cItemHandler(a_ItemType) + { + + } + + virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + if (a_Dir == BLOCK_FACE_NONE) + { + return false; + } + + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + + if (Block == E_BLOCK_AIR) + { + int Dir = 0; + switch (a_Dir) + { + case BLOCK_FACE_SOUTH: break; + case BLOCK_FACE_NORTH: Dir = 2; break; + case BLOCK_FACE_WEST: Dir = 1; break; + case BLOCK_FACE_EAST: Dir = 3; break; + default: return false; + } + + cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); + ItemFrame->Initialize(a_World); + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + + return true; + + } + return false; + } +}; + + + + -- cgit v1.2.3 From 7c0d11fbb28730a328d0cb422760cb252eb8d73f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 17 Feb 2014 23:38:25 +0000 Subject: Used new BLOCK_FACE constants Also added more comments --- src/Items/ItemItemFrame.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 39be48b54..a403778ad 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -23,23 +23,24 @@ public: { if (a_Dir == BLOCK_FACE_NONE) { + // Client sends this if clicked on top or bottom face return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir); // Make sure block that will be occupied is free BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir, true); // We want the clicked block, so go back again if (Block == E_BLOCK_AIR) { int Dir = 0; switch (a_Dir) { - case BLOCK_FACE_SOUTH: break; - case BLOCK_FACE_NORTH: Dir = 2; break; - case BLOCK_FACE_WEST: Dir = 1; break; - case BLOCK_FACE_EAST: Dir = 3; break; - default: return false; + 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 spawn item frame!"); return false; } cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); -- cgit v1.2.3 From 7a23e27fc532bdfed0038804b0060a6f7f5c0f54 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 00:29:10 +0000 Subject: Added an explanatory comment --- src/Items/ItemItemFrame.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Items') diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index a403778ad..f286fffd0 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -34,6 +34,8 @@ public: if (Block == E_BLOCK_AIR) { int Dir = 0; + + // The client uses different values for painting directions and block faces. Our constants are for the block faces, so we convert them here to painting faces switch (a_Dir) { case BLOCK_FACE_ZP: break; // Initialised to zero -- 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/Items/ItemItemFrame.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index f286fffd0..4875e09dc 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -33,19 +33,7 @@ public: if (Block == E_BLOCK_AIR) { - int Dir = 0; - - // The client uses different values for painting directions and block faces. Our constants are for the block faces, so we convert them here to painting faces - switch (a_Dir) - { - 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 spawn item frame!"); return false; - } - - cItemFrame * ItemFrame = new cItemFrame(Dir, a_BlockX, a_BlockY, a_BlockZ); + cItemFrame * ItemFrame = new cItemFrame(a_Dir, a_BlockX, a_BlockY, a_BlockZ); ItemFrame->Initialize(a_World); if (!a_Player->IsGameModeCreative()) -- cgit v1.2.3 From 5b961453d12d78a8901910d2f419093b82feb533 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 18 Feb 2014 21:54:53 +0000 Subject: Fixed possible ASSERT failure --- src/Items/ItemItemFrame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h index 4875e09dc..74e987445 100644 --- a/src/Items/ItemItemFrame.h +++ b/src/Items/ItemItemFrame.h @@ -21,7 +21,7 @@ public: virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - if (a_Dir == BLOCK_FACE_NONE) + if ((a_Dir == BLOCK_FACE_NONE) || (a_Dir == BLOCK_FACE_YP) || (a_Dir == BLOCK_FACE_YM)) { // Client sends this if clicked on top or bottom face return false; -- cgit v1.2.3