summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordaniel0916 <theschokolps@gmail.com>2014-04-19 20:56:29 +0200
committerdaniel0916 <theschokolps@gmail.com>2014-04-19 20:56:29 +0200
commitcb90029f720d867ba6398569c1b1dac2ee76e205 (patch)
treed16ea187d087b1e91c5136d349b66aafad02d7d6 /src
parentFixed Code (2) (diff)
parentAPIDump: Added a ChunkStay article. (diff)
downloadcuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar.gz
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar.bz2
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar.lz
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar.xz
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.tar.zst
cuberite-cb90029f720d867ba6398569c1b1dac2ee76e205.zip
Diffstat (limited to 'src')
-rw-r--r--src/BlockEntities/BeaconEntity.cpp116
-rw-r--r--src/BlockEntities/BeaconEntity.h44
-rw-r--r--src/BlockEntities/BlockEntity.cpp2
-rw-r--r--src/Chunk.cpp2
-rw-r--r--src/Entities/Entity.cpp10
-rw-r--r--src/Mobs/Monster.cpp5
-rw-r--r--src/World.cpp5
7 files changed, 182 insertions, 2 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
new file mode 100644
index 000000000..0914353eb
--- /dev/null
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -0,0 +1,116 @@
+
+#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(void)
+{
+ 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)
+{
+}
+
+
+
+
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
new file mode 100644
index 000000000..b1df68bc4
--- /dev/null
+++ b/src/BlockEntities/BeaconEntity.h
@@ -0,0 +1,44 @@
+
+#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, a golden block, an iron block or an emerald block. */
+ static 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;
+} ;
+
+
+
+
diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp
index b42318c2f..430f04551 100644
--- a/src/BlockEntities/BlockEntity.cpp
+++ b/src/BlockEntities/BlockEntity.cpp
@@ -4,6 +4,7 @@
// Implements the cBlockEntity class that is the common ancestor for all block entities
#include "Globals.h"
+#include "BeaconEntity.h"
#include "BlockEntity.h"
#include "ChestEntity.h"
#include "CommandBlockEntity.h"
@@ -26,6 +27,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
{
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_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);
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index fe9cd9b31..4366111ef 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -1299,6 +1299,7 @@ void cChunk::CreateBlockEntities(void)
BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z);
switch (BlockType)
{
+ case E_BLOCK_BEACON:
case E_BLOCK_CHEST:
case E_BLOCK_COMMAND_BLOCK:
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:
switch (a_BlockType)
{
+ case E_BLOCK_BEACON:
case E_BLOCK_CHEST:
case E_BLOCK_COMMAND_BLOCK:
case E_BLOCK_DISPENSER:
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 86aee4c6f..56ef36ef8 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -771,6 +771,16 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
// Remember the current burning state:
bool HasBeenBurning = (m_TicksLeftBurning > 0);
+
+ if (GetWorld()->GetWeather() == eWeather_Rain)
+ {
+ if (HasBeenBurning)
+ {
+ m_TicksLeftBurning = 0;
+ OnFinishedBurning();
+ }
+ return;
+ }
// Do the burning damage:
if (m_TicksLeftBurning > 0)
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index d63758b3d..248e88f5d 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -540,7 +540,7 @@ void cMonster::KilledBy(cEntity * a_Killer)
break;
}
}
- if (a_Killer != NULL)
+ if ((a_Killer != NULL) && (!IsBaby()))
{
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
}
@@ -1003,7 +1003,8 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
(a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
(a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
(GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime
- !IsOnFire() // Not already burning
+ !IsOnFire() && // Not already burning
+ (GetWorld()->GetWeather() != eWeather_Rain) // Not raining
)
{
// Burn for 100 ticks, then decide again
diff --git a/src/World.cpp b/src/World.cpp
index c23e255f8..800bdde0e 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1691,6 +1691,11 @@ int cWorld::SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NI
int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward)
{
+ if (a_Reward < 1)
+ {
+ return -1;
+ }
+
cExpOrb * ExpOrb = new cExpOrb(a_X, a_Y, a_Z, a_Reward);
ExpOrb->Initialize(this);
return ExpOrb->GetUniqueID();