From 221cc4ec5cb6301743e947eaabed3fecedba796f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 16 Oct 2019 10:06:34 +0200 Subject: Refactored block-to-pickup conversion. (#4417) --- src/Blocks/BlockLever.h | 55 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'src/Blocks/BlockLever.h') diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 6cb80222e..e4b181a24 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -2,21 +2,26 @@ #include "BlockHandler.h" #include "../Chunk.h" -#include "MetaRotator.h" +#include "Mixins.h" #include "BlockSlab.h" class cBlockLeverHandler : public cMetaRotator { - typedef cMetaRotator super; + using super = cMetaRotator; public: + cBlockLeverHandler(BLOCKTYPE a_BlockType) : super(a_BlockType) { } + + + + virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); @@ -29,17 +34,29 @@ public: return true; } - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + + + + + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override { - // Reset meta to 0 - a_Pickups.push_back(cItem(E_BLOCK_LEVER, 1, 0)); + // Reset meta to zero: + return cItem(E_BLOCK_LEVER, 1, 0); } + + + + virtual bool IsUseable(void) override { return true; } + + + + virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, @@ -52,6 +69,10 @@ public: return true; } + + + + inline static NIBBLETYPE LeverDirectionToMetaData(eBlockFace a_Dir) { // Determine lever direction: @@ -68,6 +89,10 @@ public: UNREACHABLE("Unsupported block face"); } + + + + inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) { switch (a_Meta & 0x7) @@ -88,6 +113,10 @@ public: } } + + + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); @@ -121,6 +150,10 @@ public: return false; } + + + + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override { switch (a_Meta) @@ -135,6 +168,10 @@ public: } } + + + + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override { switch (a_Meta) @@ -149,12 +186,20 @@ public: } } + + + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override { UNUSED(a_Meta); return 0; } + + + + /** Extracts the ON bit from metadata and returns if true if it is set */ static bool IsLeverOn(NIBBLETYPE a_BlockMeta) { -- cgit v1.2.3