Created MobSpawnerEntity class.
This commit is contained in:
parent
96f45a48d4
commit
3d94a7ea56
@ -87,7 +87,7 @@ public:
|
|||||||
virtual void SendTo(cClientHandle & a_Client) = 0;
|
virtual void SendTo(cClientHandle & a_Client) = 0;
|
||||||
|
|
||||||
/// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing.
|
/// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing.
|
||||||
virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */)
|
virtual bool Tick(float a_Dt, cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
UNUSED(a_Dt);
|
UNUSED(a_Dt);
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,6 +18,7 @@ SET (SRCS
|
|||||||
HopperEntity.cpp
|
HopperEntity.cpp
|
||||||
JukeboxEntity.cpp
|
JukeboxEntity.cpp
|
||||||
MobHeadEntity.cpp
|
MobHeadEntity.cpp
|
||||||
|
MobSpawnerEntity.cpp
|
||||||
NoteEntity.cpp
|
NoteEntity.cpp
|
||||||
SignEntity.cpp)
|
SignEntity.cpp)
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ SET (HDRS
|
|||||||
HopperEntity.h
|
HopperEntity.h
|
||||||
JukeboxEntity.h
|
JukeboxEntity.h
|
||||||
MobHeadEntity.h
|
MobHeadEntity.h
|
||||||
|
MobSpawnerEntity.h
|
||||||
NoteEntity.h
|
NoteEntity.h
|
||||||
SignEntity.h)
|
SignEntity.h)
|
||||||
|
|
||||||
|
92
src/BlockEntities/MobSpawnerEntity.cpp
Normal file
92
src/BlockEntities/MobSpawnerEntity.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||||
|
|
||||||
|
#include "MobSpawnerEntity.h"
|
||||||
|
#include "../World.h"
|
||||||
|
#include "json/json.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cMobSpawnerEntity::cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World)
|
||||||
|
: super(E_BLOCK_MOB_SPAWNER, a_BlockX, a_BlockY, a_BlockZ, a_World)
|
||||||
|
, m_EntityName("Pig")
|
||||||
|
, m_SpawnDelay(20)
|
||||||
|
, m_MinSpawnDelay(200)
|
||||||
|
, m_MaxSpawnDelay(800)
|
||||||
|
, m_MaxNearbyEntities(6)
|
||||||
|
, m_ActivatingRange(16)
|
||||||
|
, m_SpawnRange(4)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cMobSpawnerEntity::~cMobSpawnerEntity()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cMobSpawnerEntity::Tick(float a_Dt, cChunk & a_Chunk)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
|
||||||
|
{
|
||||||
|
if (IsPlayingRecord())
|
||||||
|
{
|
||||||
|
EjectRecord();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const cItem & HeldItem = a_Player->GetEquippedItem();
|
||||||
|
if (PlayRecord(HeldItem.m_ItemType))
|
||||||
|
{
|
||||||
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cMobSpawnerEntity::LoadFromJson(const Json::Value & a_Value)
|
||||||
|
{
|
||||||
|
m_PosX = a_Value.get("x", 0).asInt();
|
||||||
|
m_PosY = a_Value.get("y", 0).asInt();
|
||||||
|
m_PosZ = a_Value.get("z", 0).asInt();
|
||||||
|
|
||||||
|
m_Record = a_Value.get("Record", 0).asInt();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cMobSpawnerEntity::SaveToJson(Json::Value & a_Value)
|
||||||
|
{
|
||||||
|
a_Value["x"] = m_PosX;
|
||||||
|
a_Value["y"] = m_PosY;
|
||||||
|
a_Value["z"] = m_PosZ;
|
||||||
|
|
||||||
|
a_Value["Record"] = m_Record;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
70
src/BlockEntities/MobSpawnerEntity.h
Normal file
70
src/BlockEntities/MobSpawnerEntity.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockEntity.h"
|
||||||
|
#include "../Entities/Player.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Json
|
||||||
|
{
|
||||||
|
class Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// tolua_begin
|
||||||
|
|
||||||
|
class cMobSpawnerEntity :
|
||||||
|
public cBlockEntity
|
||||||
|
{
|
||||||
|
typedef cBlockEntity super;
|
||||||
|
public:
|
||||||
|
|
||||||
|
// tolua_end
|
||||||
|
|
||||||
|
cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
|
||||||
|
virtual ~cMobSpawnerEntity();
|
||||||
|
|
||||||
|
bool LoadFromJson(const Json::Value & a_Value);
|
||||||
|
virtual void SaveToJson(Json::Value & a_Value) override;
|
||||||
|
|
||||||
|
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||||
|
|
||||||
|
// tolua_begin
|
||||||
|
|
||||||
|
/** Returns the entity who will be spawn by this mob spawner. */
|
||||||
|
const AString & GetEntityName(void) const { return m_EntityName; }
|
||||||
|
|
||||||
|
// tolua_end
|
||||||
|
|
||||||
|
static const char * GetClassStatic(void) { return "cMobSpawnerEntity"; }
|
||||||
|
|
||||||
|
virtual void UsedBy(cPlayer * a_Player) override;
|
||||||
|
virtual void SendTo(cClientHandle &) override {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** The entity to spawn. */
|
||||||
|
AString m_EntityName;
|
||||||
|
|
||||||
|
int m_SpawnDelay;
|
||||||
|
int m_MinSpawnDelay;
|
||||||
|
int m_MaxSpawnDelay;
|
||||||
|
|
||||||
|
/** The mob spawner spawns only mobs when the count of nearby entities (without players) is lesser than this number. */
|
||||||
|
short m_MaxNearbyEntities;
|
||||||
|
|
||||||
|
/** The mob spawner spawns only mobs when a player is in the range of the mob spawner. */
|
||||||
|
short m_ActivatingRange;
|
||||||
|
|
||||||
|
/** The range coefficient for spawning entities around. */
|
||||||
|
short m_SpawnRange;
|
||||||
|
} ; // tolua_end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user