From e2d88106a9558d26d3cb8b05ac6ade6aca088737 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Mon, 2 Nov 2015 22:12:58 +0100 Subject: Added the CanPushBlock method for the piston push check. This allows the recursive check for blocks to push, which is needed to implement the slime blocks into the piston system. --- src/Blocks/BlockPiston.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 56f7f9951..41ef79aa6 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -3,6 +3,8 @@ #include "BlockHandler.h" +#include + class cWorld; @@ -152,8 +154,11 @@ private: return CanPush(a_BlockType, a_BlockMeta); } - /** Returns how many blocks the piston has to push (where the first free space is); < 0 when unpushable */ - static int FirstPassthroughBlock(int a_PistonX, int a_PistonY, int a_PistonZ, NIBBLETYPE a_PistonMeta, cWorld * a_World); + /** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */ + static bool CanPushBlock( + int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, + std::unordered_set> & a_BlocksPushed, NIBBLETYPE a_PistonMeta + ); } ; -- cgit v1.2.3 From f35060e8b518cac8521528a7398be7a095ccc108 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 14:50:43 +0100 Subject: Replaced the usage of pistonMeta with a direction vector to allow better meta value abstraction --- src/Blocks/BlockPiston.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 41ef79aa6..b08ca5fee 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -81,6 +81,8 @@ public: } } + static Vector3i GetDirectionVec(int a_PistonMeta); + static void ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); static void RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); @@ -157,7 +159,7 @@ private: /** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */ static bool CanPushBlock( int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, - std::unordered_set> & a_BlocksPushed, NIBBLETYPE a_PistonMeta + std::unordered_set> & a_BlocksPushed, const Vector3i & a_PushDir ); } ; -- cgit v1.2.3 From 558991a7256afb2d110579346006cafec73bc275 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 18:49:15 +0100 Subject: Extracted block moving code into a seperate method --- src/Blocks/BlockPiston.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index b08ca5fee..f05e73f38 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -161,6 +161,10 @@ private: int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, std::unordered_set> & a_BlocksPushed, const Vector3i & a_PushDir ); + + static void PushBlocks(const std::unordered_set> & a_BlocksToPush, + cWorld * a_World, const Vector3i & a_PushDir + ); } ; -- cgit v1.2.3 From 5fa077f869919325f82395161795ece9abbda280 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 18:56:06 +0100 Subject: Removed unused CanPull method --- src/Blocks/BlockPiston.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index f05e73f38..af9e3d3bc 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -145,17 +145,6 @@ private: return true; } - /** Returns true if the specified block can be pulled by a sticky piston */ - static inline bool CanPull(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) - { - if (cBlockInfo::IsPistonBreakable(a_BlockType)) - { - return false; // CanBreakPush returns true, but we need false to prevent pulling - } - - return CanPush(a_BlockType, a_BlockMeta); - } - /** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */ static bool CanPushBlock( int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, -- cgit v1.2.3 From 64012bf46fb00f792b3f48fb396f17fc9f6be677 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 20:13:58 +0100 Subject: Fixed the style problems and added some comments --- src/Blocks/BlockPiston.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index af9e3d3bc..f8851e091 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -151,6 +151,7 @@ private: std::unordered_set> & a_BlocksPushed, const Vector3i & a_PushDir ); + /** Moves a list of blocks in a specific direction */ static void PushBlocks(const std::unordered_set> & a_BlocksToPush, cWorld * a_World, const Vector3i & a_PushDir ); -- cgit v1.2.3 From f8c28cc373b1942f19f1b343f301e16d25463ac5 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 21:39:37 +0100 Subject: Commented the GetDirectionVec method --- src/Blocks/BlockPiston.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index f8851e091..0001a5787 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -81,6 +81,9 @@ public: } } + /** This method converts the magic piston metadata into a direction vector. + This vector has a length of 1 and points into the direction, in which the piston will extend. + */ static Vector3i GetDirectionVec(int a_PistonMeta); static void ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); -- cgit v1.2.3 From 0447af8bcba4394387c339945f020fb023b6eb5e Mon Sep 17 00:00:00 2001 From: bibo38 Date: Thu, 5 Nov 2015 21:57:30 +0100 Subject: Renamed GetDirectionVec into VectorFromMetaData to improve code readability. --- src/Blocks/BlockPiston.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 0001a5787..418af6d27 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -84,7 +84,7 @@ public: /** This method converts the magic piston metadata into a direction vector. This vector has a length of 1 and points into the direction, in which the piston will extend. */ - static Vector3i GetDirectionVec(int a_PistonMeta); + static Vector3i VectorFromMetaData(int a_PistonMeta); static void ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); static void RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); -- cgit v1.2.3 From 429f6153901c1b178eff3e3c2b642331b052475b Mon Sep 17 00:00:00 2001 From: bibo38 Date: Fri, 6 Nov 2015 17:11:54 +0100 Subject: Added some code improvements --- src/Blocks/BlockPiston.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 418af6d27..82f079954 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -81,10 +81,8 @@ public: } } - /** This method converts the magic piston metadata into a direction vector. - This vector has a length of 1 and points into the direction, in which the piston will extend. - */ - static Vector3i VectorFromMetaData(int a_PistonMeta); + /** Converts piston block's metadata into a unit vector representing the direction in which the piston will extend. */ + static Vector3i MetadataToOffset(NIBBLETYPE a_PistonMeta); static void ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); static void RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); @@ -96,6 +94,8 @@ public: } private: + + typedef std::unordered_set> Vector3iSet; /** Returns true if the piston (specified by blocktype) is a sticky piston */ static inline bool IsSticky(BLOCKTYPE a_BlockType) { return (a_BlockType == E_BLOCK_STICKY_PISTON); } @@ -151,11 +151,11 @@ private: /** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */ static bool CanPushBlock( int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, - std::unordered_set> & a_BlocksPushed, const Vector3i & a_PushDir + Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir ); /** Moves a list of blocks in a specific direction */ - static void PushBlocks(const std::unordered_set> & a_BlocksToPush, + static void PushBlocks(const Vector3iSet & a_BlocksToPush, cWorld * a_World, const Vector3i & a_PushDir ); } ; -- cgit v1.2.3 From ea55e756724d5b68a2f25b073323f7289db30a98 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Sat, 7 Nov 2015 17:22:53 +0100 Subject: Refactored code to use vectors in the cPistonHandler class --- src/Blocks/BlockPiston.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 82f079954..e0066e8ab 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -84,8 +84,8 @@ public: /** Converts piston block's metadata into a unit vector representing the direction in which the piston will extend. */ static Vector3i MetadataToOffset(NIBBLETYPE a_PistonMeta); - static void ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - static void RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + static void ExtendPiston(Vector3i a_BlockPos, cWorld * a_World); + static void RetractPiston(Vector3i a_BlockPos, cWorld * a_World); virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override { @@ -150,7 +150,7 @@ private: /** Tries to push a block and increases the pushed blocks variable. Returns true if the block is pushable */ static bool CanPushBlock( - int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, bool a_RequirePushable, + const Vector3i & a_BlockPos, cWorld * a_World, bool a_RequirePushable, Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir ); -- cgit v1.2.3