Finished mob spawner implementation.
This commit is contained in:
parent
42120e2ea5
commit
8b028c5c78
@ -1,3 +1,4 @@
|
||||
|
||||
// BeaconEntity.h
|
||||
|
||||
// Declares the cBeaconEntity class representing a single beacon in the world
|
||||
@ -14,15 +15,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
class cBeaconEntity :
|
||||
public cBlockEntityWithItems
|
||||
|
@ -28,11 +28,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
};
|
||||
|
||||
class cChunk;
|
||||
class cPlayer;
|
||||
class cWorld;
|
||||
|
@ -7,11 +7,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
};
|
||||
|
||||
class cClientHandle;
|
||||
|
||||
|
||||
|
@ -15,14 +15,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
|
@ -16,10 +16,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
class cClientHandle;
|
||||
|
||||
|
@ -15,16 +15,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
class cFlowerPotEntity :
|
||||
|
@ -8,11 +8,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
class cClientHandle;
|
||||
|
||||
|
||||
|
@ -7,15 +7,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
class cJukeboxEntity :
|
||||
|
@ -14,14 +14,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "MobSpawnerEntity.h"
|
||||
#include "json/json.h"
|
||||
|
||||
#include "../World.h"
|
||||
#include "../FastRandom.h"
|
||||
@ -38,8 +37,8 @@ void cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
|
||||
{
|
||||
if (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SPAWN_EGG)
|
||||
{
|
||||
cMonster::eType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(a_Player->GetEquippedItem().m_ItemDamage);
|
||||
if (MonsterType == mtInvalidType)
|
||||
eMonsterType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(a_Player->GetEquippedItem().m_ItemDamage);
|
||||
if (MonsterType == eMonsterType::mtInvalidType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -50,7 +49,7 @@ void cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
|
||||
{
|
||||
a_Player->GetInventory().RemoveOneEquippedItem();
|
||||
}
|
||||
LOGD("Changed monster spawner entity to %s!", GetEntityName().c_str());
|
||||
LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), GetEntityName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +104,7 @@ bool cMobSpawnerEntity::Tick(float a_Dt, cChunk & a_Chunk)
|
||||
|
||||
void cMobSpawnerEntity::ResetTimer(void)
|
||||
{
|
||||
m_SpawnDelay = 200 + m_World->GetTickRandomNumber(600);
|
||||
m_SpawnDelay = (short) (200 + m_World->GetTickRandomNumber(600));
|
||||
m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ);
|
||||
}
|
||||
|
||||
@ -196,30 +195,6 @@ void cMobSpawnerEntity::SpawnEntity(void)
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cMobSpawnerEntity::SaveToJson(Json::Value & a_Value)
|
||||
{
|
||||
a_Value["x"] = m_PosX;
|
||||
a_Value["y"] = m_PosY;
|
||||
a_Value["z"] = m_PosZ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AString cMobSpawnerEntity::GetEntityName() const
|
||||
{
|
||||
switch (m_Entity)
|
||||
|
@ -8,15 +8,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
class cMobSpawnerEntity :
|
||||
@ -54,23 +45,23 @@ public:
|
||||
AString GetEntityName(void) const;
|
||||
|
||||
/** Returns the spawn delay. */
|
||||
int GetSpawnDelay(void) const { return m_SpawnDelay; }
|
||||
short GetSpawnDelay(void) const { return m_SpawnDelay; }
|
||||
|
||||
/** Sets the spawn delay. */
|
||||
void SetSpawnDelay(short a_Delay) { m_SpawnDelay = a_Delay; }
|
||||
|
||||
int GetNearbyPlayersNum(void);
|
||||
int GetNearbyMonsterNum(eMonsterType a_EntityType);
|
||||
|
||||
// tolua_end
|
||||
|
||||
bool LoadFromJson(const Json::Value & a_Value);
|
||||
virtual void SaveToJson(Json::Value & a_Value) override;
|
||||
|
||||
static const char * GetClassStatic(void) { return "cMobSpawnerEntity"; }
|
||||
|
||||
private:
|
||||
/** The entity to spawn. */
|
||||
eMonsterType m_Entity;
|
||||
|
||||
int m_SpawnDelay;
|
||||
short m_SpawnDelay;
|
||||
|
||||
bool m_IsActive;
|
||||
} ; // tolua_end
|
||||
|
@ -5,12 +5,6 @@
|
||||
#include "RedstonePoweredEntity.h"
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -14,15 +14,6 @@
|
||||
|
||||
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
|
||||
class cSignEntity :
|
||||
|
@ -52,7 +52,7 @@ public :
|
||||
tSpawnedContainer & getSpawned(void);
|
||||
|
||||
/** Returns true if specified type of mob can spawn on specified block */
|
||||
static bool CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome);
|
||||
static bool CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, eMonsterType a_MobType, EMCSBiome a_Biome);
|
||||
|
||||
protected :
|
||||
// return a random type that can spawn on specified biome.
|
||||
|
@ -41,6 +41,7 @@ Implements the 1.8.x protocol classes:
|
||||
#include "../BlockEntities/BeaconEntity.h"
|
||||
#include "../BlockEntities/CommandBlockEntity.h"
|
||||
#include "../BlockEntities/MobHeadEntity.h"
|
||||
#include "../BlockEntities/MobSpawnerEntity.h"
|
||||
#include "../BlockEntities/FlowerPotEntity.h"
|
||||
#include "Bindings/PluginManager.h"
|
||||
|
||||
@ -2972,6 +2973,18 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt
|
||||
Writer.AddString("id", "FlowerPot"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though
|
||||
break;
|
||||
}
|
||||
case E_BLOCK_MOB_SPAWNER:
|
||||
{
|
||||
cMobSpawnerEntity & MobSpawnerEntity = (cMobSpawnerEntity &)a_BlockEntity;
|
||||
|
||||
Writer.AddInt("x", MobSpawnerEntity.GetPosX());
|
||||
Writer.AddInt("y", MobSpawnerEntity.GetPosY());
|
||||
Writer.AddInt("z", MobSpawnerEntity.GetPosZ());
|
||||
Writer.AddString("EntityId", MobSpawnerEntity.GetEntityName());
|
||||
Writer.AddShort("Delay", MobSpawnerEntity.GetSpawnDelay());
|
||||
Writer.AddString("id", "MobSpawner");
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
@ -294,9 +294,10 @@ void cNBTChunkSerializer::AddJukeboxEntity(cJukeboxEntity * a_Jukebox)
|
||||
void cNBTChunkSerializer::AddMobSpawnerEntity(cMobSpawnerEntity * a_MobSpawner)
|
||||
{
|
||||
m_Writer.BeginCompound("");
|
||||
AddBasicTileEntity(a_MobSpawner, "MobSpawner");
|
||||
AddBasicTileEntity(a_MobSpawner, "MobSpawner");
|
||||
m_Writer.AddShort("Entity", static_cast<short>(a_MobSpawner->GetEntity()));
|
||||
m_Writer.AddString("EntityId", a_MobSpawner->GetEntityName());
|
||||
m_Writer.AddShort("Delay", (Int16)a_MobSpawner->GetSpawnDelay());
|
||||
m_Writer.AddShort("Delay", a_MobSpawner->GetSpawnDelay());
|
||||
m_Writer.EndCompound();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "../BlockEntities/NoteEntity.h"
|
||||
#include "../BlockEntities/SignEntity.h"
|
||||
#include "../BlockEntities/MobHeadEntity.h"
|
||||
#include "../BlockEntities/MobSpawnerEntity.h"
|
||||
#include "../BlockEntities/FlowerPotEntity.h"
|
||||
|
||||
#include "../Mobs/Monster.h"
|
||||
@ -664,6 +665,7 @@ cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a
|
||||
case E_BLOCK_HOPPER: return LoadHopperFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ);
|
||||
case E_BLOCK_JUKEBOX: return LoadJukeboxFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ);
|
||||
case E_BLOCK_LIT_FURNACE: return LoadFurnaceFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LIT_FURNACE, a_BlockMeta);
|
||||
case E_BLOCK_MOB_SPAWNER: return LoadMobSpawnerFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ);
|
||||
case E_BLOCK_NOTE_BLOCK: return LoadNoteBlockFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ);
|
||||
case E_BLOCK_SIGN_POST: return LoadSignFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_SIGN_POST);
|
||||
case E_BLOCK_TRAPPED_CHEST: return LoadChestFromNBT (a_NBT, a_Tag, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_TRAPPED_CHEST);
|
||||
@ -1085,6 +1087,54 @@ cBlockEntity * cWSSAnvil::LoadFurnaceFromNBT(const cParsedNBT & a_NBT, int a_Tag
|
||||
|
||||
|
||||
|
||||
cBlockEntity * cWSSAnvil::LoadMobSpawnerFromNBT(const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
{
|
||||
// Check if the data has a proper type:
|
||||
if (!CheckBlockEntityType(a_NBT, a_TagIdx, "MobSpawner"))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::auto_ptr<cMobSpawnerEntity> MobSpawner(new cMobSpawnerEntity(a_BlockX, a_BlockY, a_BlockZ, m_World));
|
||||
|
||||
// Load entity (MCServer worlds):
|
||||
int Type = a_NBT.FindChildByName(a_TagIdx, "Entity");
|
||||
if ((Type >= 0) && (a_NBT.GetType(Type) == TAG_Short))
|
||||
{
|
||||
short MonsterType = a_NBT.GetShort(Type);
|
||||
if ((MonsterType >= 50) && (MonsterType <= 120))
|
||||
{
|
||||
MobSpawner->SetEntity(static_cast<eMonsterType>(MonsterType));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Load entity (vanilla worlds):
|
||||
Type = a_NBT.FindChildByName(a_TagIdx, "EntityId");
|
||||
if ((Type >= 0) && (a_NBT.GetType(Type) == TAG_String))
|
||||
{
|
||||
eMonsterType MonsterType = cMonster::StringToMobType(a_NBT.GetString(Type));
|
||||
if (MonsterType != eMonsterType::mtInvalidType)
|
||||
{
|
||||
MobSpawner->SetEntity(MonsterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load delay:
|
||||
int Delay = a_NBT.FindChildByName(a_TagIdx, "Delay");
|
||||
if ((Delay >= 0) && (a_NBT.GetType(Delay) == TAG_Short))
|
||||
{
|
||||
MobSpawner->SetSpawnDelay(a_NBT.GetShort(Delay));
|
||||
}
|
||||
|
||||
return MobSpawner.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBlockEntity * cWSSAnvil::LoadHopperFromNBT(const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
{
|
||||
// Check if the data has a proper type:
|
||||
|
@ -148,6 +148,7 @@ protected:
|
||||
cBlockEntity * LoadDropperFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
cBlockEntity * LoadFlowerPotFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
cBlockEntity * LoadFurnaceFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
cBlockEntity * LoadMobSpawnerFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
cBlockEntity * LoadHopperFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
cBlockEntity * LoadJukeboxFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
cBlockEntity * LoadMobHeadFromNBT (const cParsedNBT & a_NBT, int a_TagIdx, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
|
Loading…
x
Reference in New Issue
Block a user