summaryrefslogtreecommitdiffstats
path: root/src/Entities/FireworkEntity.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-04-28 12:32:02 +0200
committerMattes D <github@xoft.cz>2014-04-28 12:32:02 +0200
commitc0630516459ec59139b60173e0582900115a5614 (patch)
tree46a3beef2f57ea2ff59bd487f98e82d18f406935 /src/Entities/FireworkEntity.cpp
parentFixed warnings. (diff)
parentFixed projectile source filenames, indentations (diff)
downloadcuberite-c0630516459ec59139b60173e0582900115a5614.tar
cuberite-c0630516459ec59139b60173e0582900115a5614.tar.gz
cuberite-c0630516459ec59139b60173e0582900115a5614.tar.bz2
cuberite-c0630516459ec59139b60173e0582900115a5614.tar.lz
cuberite-c0630516459ec59139b60173e0582900115a5614.tar.xz
cuberite-c0630516459ec59139b60173e0582900115a5614.tar.zst
cuberite-c0630516459ec59139b60173e0582900115a5614.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/FireworkEntity.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp
new file mode 100644
index 000000000..403a53c84
--- /dev/null
+++ b/src/Entities/FireworkEntity.cpp
@@ -0,0 +1,73 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "FireworkEntity.h"
+#include "../World.h"
+#include "../Chunk.h"
+
+
+
+
+
+cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) :
+ super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
+ m_ExplodeTimer(0),
+ m_FireworkItem(a_Item)
+{
+}
+
+
+
+
+
+void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
+{
+ int RelX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
+ int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
+ int PosY = POSY_TOINT;
+
+ if ((PosY < 0) || (PosY >= cChunkDef::Height))
+ {
+ goto setspeed;
+ }
+
+ if (m_IsInGround)
+ {
+ if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) == E_BLOCK_AIR)
+ {
+ m_IsInGround = false;
+ }
+ else
+ {
+ return;
+ }
+ }
+ else
+ {
+ if (a_Chunk.GetBlock(RelX, POSY_TOINT + 1, RelZ) != E_BLOCK_AIR)
+ {
+ OnHitSolidBlock(GetPosition(), BLOCK_FACE_YM);
+ return;
+ }
+ }
+
+setspeed:
+ AddSpeedY(1);
+ AddPosition(GetSpeed() * (a_Dt / 1000));
+}
+
+
+
+
+
+void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+
+ if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks)
+ {
+ m_World->BroadcastEntityStatus(*this, esFireworkExploding);
+ Destroy();
+ }
+
+ m_ExplodeTimer++;
+}