From 0e0baa940a967b34806891c5d5e9d520b3a558db Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 30 Nov 2013 00:31:21 +0000 Subject: Properly fixed snow height, fixes #98 and #264 --- src/Blocks/BlockHandler.h | 27 +++++++++++++++++---------- src/Blocks/BlockSnow.h | 28 ++++++++++++++++++++++------ src/ClientHandle.cpp | 23 ++++++++++++++--------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 81d9f240c..126930dc1 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -97,7 +97,10 @@ public: */ virtual bool DoesIgnoreBuildCollision(void); - /// Does this block drop if it gets destroyed by an unsuitable situation? Default: true + /// Similar to DoesIgnoreBuildCollision(void), but is used for cases where block meta/player item-in-hand is needed to determine collision (thin snow) + virtual bool DoesIgnoreBuildCollision(cPlayer * a_Player, NIBBLETYPE a_Meta) { return DoesIgnoreBuildCollision(); } + + /// Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true virtual bool DoesDropOnUnsuitable(void); /** Called when one of the neighbors gets set; equivalent to MC block update. @@ -106,26 +109,30 @@ public: */ virtual void Check(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk); - /// Returns the meta for a block after rotating it counter-clockwise from the specified meta. Default: no change + /// Rotates a given block meta counter-clockwise. Default: no change + /// Block meta following rotation virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) { return a_Meta; } - /// Returns the meta for a block after rotating it clockwise from the specified meta. Default: no change + /// Rotates a given block meta clockwise. Default: no change + /// Block meta following rotation virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) { return a_Meta; } - /// Returns the meta for a block after mirroring it around the XY plane. Default: no change + /// Mirros a given block meta around the XY plane. Default: no change + /// Block meta following mirroring virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) { return a_Meta; } - /// Returns the meta for a block after mirroring it around the XZ plane. Default: no change + /// Mirros a given block meta around the XZ plane. Default: no change + /// Block meta following mirroring virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) { return a_Meta; } - /// Returns the meta for a block after mirroring it around the YZ plane. Default: no change + /// Mirros a given block meta around the YZ plane. Default: no change + /// Block meta following mirroring virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; } - - - /// Get the blockhandler for a specific block id + + /// Get the blockhandler for a specific block id static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockType); - /// Deletes all initialised block handlers + /// Deletes all initialised block handlers static void Deinit(); protected: diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index b8d48362c..dd4c49fb2 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -25,21 +25,37 @@ public: ) override { a_BlockType = m_BlockType; - NIBBLETYPE Meta = a_World->GetBlockMeta(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); - if ((Meta < 7) && (Meta != 0)) // Is height at maximum (7) or at mininum (0)? Don't do anything if so + BLOCKTYPE BlockBeforePlacement; + NIBBLETYPE MetaBeforePlacement; + a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockBeforePlacement, MetaBeforePlacement); + + if ((BlockBeforePlacement == E_BLOCK_SNOW) && (MetaBeforePlacement < 7)) { - Meta++; + // Only increment if: + // A snow block was already there (not first time placement) AND + // Height is smaller than 7, the maximum possible height + MetaBeforePlacement++; } - a_BlockMeta = Meta; + a_BlockMeta = MetaBeforePlacement; return true; } - virtual bool DoesIgnoreBuildCollision(void) override + virtual bool DoesIgnoreBuildCollision(cPlayer * a_Player, NIBBLETYPE a_Meta) override { - return true; + if ((a_Player->GetEquippedItem().m_ItemType == E_BLOCK_SNOW) && (a_Meta < 7)) + { + return true; // If a player is holding a (thin) snow block and it's size can be increased, return collision ignored + } + + if (a_Meta == 0) + { + return true; // If at normal snowfall height (lowest), we ignore collision + } + + return false; } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b3e12ce77..f9a48003e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -891,14 +891,14 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c else { // Check if the block ignores build collision (water, grass etc.): - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(ClickedBlock); - if (Handler->DoesIgnoreBuildCollision()) + if ( + BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision() || + BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(m_Player, ClickedBlockMeta) + ) { - Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); + BlockHandler(ClickedBlock)->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); } - - BLOCKTYPE PlaceBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision()) + else { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); @@ -908,7 +908,9 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c return; } - BLOCKTYPE PlaceBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE PlaceMeta; + BLOCKTYPE PlaceBlock; + World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, PlaceBlock, PlaceMeta); // Clicked on side of block, make sure that placement won't be cancelled if there is a slab able to be double slabbed. // No need to do combinability (dblslab) checks, client will do that here. @@ -918,10 +920,13 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c } else { - if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision()) + if ( + !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision() && + !BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision(m_Player, PlaceMeta) + ) { // Tried to place a block *into* another? - // Happens when you place a block aiming at side of block like torch or stem + // Happens when you place a block aiming at side of block with a torch on it or stem beside it return; } } -- cgit v1.2.3