Merge remote-tracking branch 'origin/Beacons'
This commit is contained in:
commit
5f3df1445f
115
src/BlockEntities/BeaconEntity.cpp
Normal file
115
src/BlockEntities/BeaconEntity.cpp
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
|
||||||
|
#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;
|
||||||
|
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,
|
||||||
|
MinY,
|
||||||
|
MaxY,
|
||||||
|
GetPosZ() - 4,
|
||||||
|
GetPosZ() + 4,
|
||||||
|
cBlockArea::baTypes
|
||||||
|
);
|
||||||
|
|
||||||
|
int Layer = 1;
|
||||||
|
int MiddleXZ = 4;
|
||||||
|
|
||||||
|
for (int Y = Area.GetSizeY() - 1; Y > 0; Y--)
|
||||||
|
{
|
||||||
|
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)))
|
||||||
|
{
|
||||||
|
return Layer - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Layer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Layer - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
40
src/BlockEntities/BeaconEntity.h
Normal file
40
src/BlockEntities/BeaconEntity.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Json
|
||||||
|
{
|
||||||
|
class Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBeaconEntity :
|
||||||
|
public cBlockEntity
|
||||||
|
{
|
||||||
|
typedef cBlockEntity super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// The initial constructor
|
||||||
|
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
|
||||||
|
|
||||||
|
// Returns the amount of layers the pyramid below the beacon has.
|
||||||
|
int GetPyramidLevel(void);
|
||||||
|
|
||||||
|
// Returns true if the block is a diamond block, an golden block, an iron block or an emerald block.
|
||||||
|
bool IsMineralBlock(BLOCKTYPE a_BlockType);
|
||||||
|
|
||||||
|
// cBlockEntity overrides:
|
||||||
|
virtual void SaveToJson(Json::Value& a_Value ) override;
|
||||||
|
virtual void SendTo(cClientHandle & a_Client) override;
|
||||||
|
virtual void UsedBy(cPlayer * a_Player) override;
|
||||||
|
virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) override;
|
||||||
|
} ;
|
@ -4,6 +4,7 @@
|
|||||||
// Implements the cBlockEntity class that is the common ancestor for all block entities
|
// Implements the cBlockEntity class that is the common ancestor for all block entities
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
#include "BeaconEntity.h"
|
||||||
#include "BlockEntity.h"
|
#include "BlockEntity.h"
|
||||||
#include "ChestEntity.h"
|
#include "ChestEntity.h"
|
||||||
#include "CommandBlockEntity.h"
|
#include "CommandBlockEntity.h"
|
||||||
@ -26,6 +27,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
|
|||||||
{
|
{
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
{
|
{
|
||||||
|
case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
|
||||||
case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
|
case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
|
||||||
case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World);
|
case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World);
|
||||||
case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
|
case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
|
||||||
|
@ -1299,6 +1299,7 @@ void cChunk::CreateBlockEntities(void)
|
|||||||
BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z);
|
BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z);
|
||||||
switch (BlockType)
|
switch (BlockType)
|
||||||
{
|
{
|
||||||
|
case E_BLOCK_BEACON:
|
||||||
case E_BLOCK_CHEST:
|
case E_BLOCK_CHEST:
|
||||||
case E_BLOCK_COMMAND_BLOCK:
|
case E_BLOCK_COMMAND_BLOCK:
|
||||||
case E_BLOCK_DISPENSER:
|
case E_BLOCK_DISPENSER:
|
||||||
@ -1429,6 +1430,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType,
|
|||||||
// If the new block is a block entity, create the entity object:
|
// If the new block is a block entity, create the entity object:
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
{
|
{
|
||||||
|
case E_BLOCK_BEACON:
|
||||||
case E_BLOCK_CHEST:
|
case E_BLOCK_CHEST:
|
||||||
case E_BLOCK_COMMAND_BLOCK:
|
case E_BLOCK_COMMAND_BLOCK:
|
||||||
case E_BLOCK_DISPENSER:
|
case E_BLOCK_DISPENSER:
|
||||||
|
Loading…
Reference in New Issue
Block a user