Moved cFireworkEntity out of ProjectileEntity.h
This commit is contained in:
parent
cb93a57963
commit
e3c3795aa4
|
@ -19,6 +19,7 @@
|
||||||
#include "ProjectileExpBottle.h"
|
#include "ProjectileExpBottle.h"
|
||||||
#include "ProjectileSnowball.h"
|
#include "ProjectileSnowball.h"
|
||||||
#include "ProjectileFireCharge.h"
|
#include "ProjectileFireCharge.h"
|
||||||
|
#include "ProjectileFirework.h"
|
||||||
#include "ProjectileGhastFireball.h"
|
#include "ProjectileGhastFireball.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,75 +409,4 @@ void cProjectileEntity::CollectedBy(cPlayer * a_Dest)
|
||||||
{
|
{
|
||||||
// Overriden in arrow
|
// Overriden in arrow
|
||||||
UNUSED(a_Dest);
|
UNUSED(a_Dest);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// cFireworkEntity :
|
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
}
|
|
@ -94,47 +94,4 @@ protected:
|
||||||
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
||||||
virtual void SpawnOn(cClientHandle & a_Client) override;
|
virtual void SpawnOn(cClientHandle & a_Client) override;
|
||||||
|
|
||||||
// tolua_begin
|
} ;
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cFireworkEntity :
|
|
||||||
public cProjectileEntity
|
|
||||||
{
|
|
||||||
typedef cProjectileEntity super;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// tolua_end
|
|
||||||
|
|
||||||
CLASS_PROTODEF(cFireworkEntity);
|
|
||||||
|
|
||||||
cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item);
|
|
||||||
const cItem & GetItem(void) const { return m_FireworkItem; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// cProjectileEntity overrides:
|
|
||||||
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
|
||||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int m_ExplodeTimer;
|
|
||||||
cItem m_FireworkItem;
|
|
||||||
|
|
||||||
// tolua_begin
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// tolua_end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
73
src/Entities/ProjectileFirework.cpp
Normal file
73
src/Entities/ProjectileFirework.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
|
#include "ProjectileFirework.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++;
|
||||||
|
}
|
40
src/Entities/ProjectileFirework.h
Normal file
40
src/Entities/ProjectileFirework.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// ProjectileFirework.h
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ProjectileEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cFireworkEntity :
|
||||||
|
public cProjectileEntity
|
||||||
|
{
|
||||||
|
typedef cProjectileEntity super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// tolua_end
|
||||||
|
|
||||||
|
CLASS_PROTODEF(cFireworkEntity);
|
||||||
|
|
||||||
|
cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item);
|
||||||
|
const cItem & GetItem(void) const { return m_FireworkItem; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// cProjectileEntity overrides:
|
||||||
|
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
||||||
|
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_ExplodeTimer;
|
||||||
|
cItem m_FireworkItem;
|
||||||
|
|
||||||
|
// tolua_begin
|
||||||
|
|
||||||
|
};
|
|
@ -32,6 +32,7 @@ Implements the 1.7.x protocol classes:
|
||||||
#include "../BlockEntities/FlowerPotEntity.h"
|
#include "../BlockEntities/FlowerPotEntity.h"
|
||||||
#include "../CompositeChat.h"
|
#include "../CompositeChat.h"
|
||||||
#include "../Entities/ProjectileArrow.h"
|
#include "../Entities/ProjectileArrow.h"
|
||||||
|
#include "../Entities/ProjectileFirework.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user