From 875c2557c30aa5254c2ec3f4062ec463418c7d09 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 12 Apr 2014 00:01:15 +0200 Subject: Implemented the skeleton code for the beacon. There is no handling for the GUI. It can now check how big the pyramid is under the beacon. --- src/BlockEntities/BeaconEntity.cpp | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/BlockEntities/BeaconEntity.cpp (limited to 'src/BlockEntities/BeaconEntity.cpp') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp new file mode 100644 index 000000000..e5e890dbc --- /dev/null +++ b/src/BlockEntities/BeaconEntity.cpp @@ -0,0 +1,111 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BeaconEntity.h" +#include "../BlockArea.h" + + + + + +cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, a_World) +{ +} + + + + + +int cBeaconEntity::GetPyramidLevel() +{ + cBlockArea Area; + Area.Read( + m_World, + GetPosX() - 4, + GetPosX() + 4, + GetPosY() - 5, + GetPosY() - 1, + GetPosZ() - 4, + GetPosZ() + 4 + ); + + int Layer = 1; + int MiddleXZ = 4; + + for (int Y = Area.GetSizeY() - 1; Y > 0; Y--) + { + bool FullLayer = true; + for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++) + { + for (int Z = MiddleXZ - Layer; Z <= (MiddleXZ + Layer); Z++) + { + if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z))) + { + FullLayer = false; + } + } + } + if (!FullLayer) + { + break; + } + else + { + Layer++; + } + } + + return Layer; +} + + + + + +bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) +{ + switch(a_BlockType) + { + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_EMERALD_BLOCK: + { + return true; + } + } + return false; +} + + + + + +bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + return false; +} + + + + + +void cBeaconEntity::SaveToJson(Json::Value& a_Value) +{ +} + + + + +void cBeaconEntity::SendTo(cClientHandle & a_Client) +{ +} + + + + + +void cBeaconEntity::UsedBy(cPlayer * a_Player) +{ +} \ No newline at end of file -- cgit v1.2.3 From e19556ebf6a3a452a31b4e327f6018637418100a Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 12 Apr 2014 00:13:16 +0200 Subject: Simplefied GetPyramidLevel --- src/BlockEntities/BeaconEntity.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/BlockEntities/BeaconEntity.cpp') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index e5e890dbc..b5a503192 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -35,25 +35,17 @@ int cBeaconEntity::GetPyramidLevel() for (int Y = Area.GetSizeY() - 1; Y > 0; Y--) { - bool FullLayer = true; for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++) { for (int Z = MiddleXZ - Layer; Z <= (MiddleXZ + Layer); Z++) { if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z))) { - FullLayer = false; + return Layer; } } } - if (!FullLayer) - { - break; - } - else - { - Layer++; - } + Layer++; } return Layer; @@ -84,6 +76,7 @@ bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk) { + std::cout << GetPyramidLevel() << "\n"; return false; } -- cgit v1.2.3 From eb4dd23775fa6de25d14bd485dcb96451a2b2989 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 12 Apr 2014 00:21:37 +0200 Subject: Removed debug message. --- src/BlockEntities/BeaconEntity.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/BlockEntities/BeaconEntity.cpp') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index b5a503192..65fda827c 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -76,7 +76,6 @@ bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk) { - std::cout << GetPyramidLevel() << "\n"; return false; } -- cgit v1.2.3 From 433bd530f38b78bb7e276acafef40fec47d43267 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 12 Apr 2014 00:35:13 +0200 Subject: Some tweaks GetPyramidLevel returns 0 when no layers were found, 1 for one layer etc. Auto adjust the minY and/or maxY to 0 if the beacon is low. --- src/BlockEntities/BeaconEntity.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/BlockEntities/BeaconEntity.cpp') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 65fda827c..dd340f24f 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -20,14 +20,26 @@ cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * int cBeaconEntity::GetPyramidLevel() { cBlockArea Area; + int MinY = GetPosY() - 4; + if (MinY < 0) + { + MinY = 0; + } + int MaxY = GetPosY() - 1; + if (MaxY < 0) + { + MaxY = 0; + } + Area.Read( m_World, GetPosX() - 4, GetPosX() + 4, - GetPosY() - 5, - GetPosY() - 1, + MinY, + MaxY, GetPosZ() - 4, - GetPosZ() + 4 + GetPosZ() + 4, + cBlockArea::baTypes ); int Layer = 1; @@ -41,14 +53,14 @@ int cBeaconEntity::GetPyramidLevel() { if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z))) { - return Layer; + return Layer - 1; } } } Layer++; } - return Layer; + return Layer - 1; } -- cgit v1.2.3 From 6eac5867945044eda62312f9657ff0c808ac2080 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 19 Apr 2014 13:05:58 +0200 Subject: Fixed formatting, made function static. --- src/BlockEntities/BeaconEntity.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/BlockEntities/BeaconEntity.cpp') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index dd340f24f..0914353eb 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -17,7 +17,7 @@ cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * -int cBeaconEntity::GetPyramidLevel() +int cBeaconEntity::GetPyramidLevel(void) { cBlockArea Area; int MinY = GetPosY() - 4; @@ -33,12 +33,9 @@ int cBeaconEntity::GetPyramidLevel() Area.Read( m_World, - GetPosX() - 4, - GetPosX() + 4, - MinY, - MaxY, - GetPosZ() - 4, - GetPosZ() + 4, + GetPosX() - 4, GetPosX() + 4, + MinY, MaxY, + GetPosZ() - 4, GetPosZ() + 4, cBlockArea::baTypes ); @@ -112,4 +109,8 @@ void cBeaconEntity::SendTo(cClientHandle & a_Client) void cBeaconEntity::UsedBy(cPlayer * a_Player) { -} \ No newline at end of file +} + + + + -- cgit v1.2.3