From 3d94a7ea560f00585f454476928ba4ba3ec28ef7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 17 Sep 2014 17:45:13 +0200 Subject: Created MobSpawnerEntity class. --- src/BlockEntities/BlockEntity.h | 2 +- src/BlockEntities/CMakeLists.txt | 2 + src/BlockEntities/MobSpawnerEntity.cpp | 92 ++++++++++++++++++++++++++++++++++ src/BlockEntities/MobSpawnerEntity.h | 70 ++++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 src/BlockEntities/MobSpawnerEntity.cpp create mode 100644 src/BlockEntities/MobSpawnerEntity.h diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 5710f8543..e9d3a00ae 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -87,7 +87,7 @@ public: 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. - virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) + virtual bool Tick(float a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); return false; diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index d87594b0d..5f4af288d 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -18,6 +18,7 @@ SET (SRCS HopperEntity.cpp JukeboxEntity.cpp MobHeadEntity.cpp + MobSpawnerEntity.cpp NoteEntity.cpp SignEntity.cpp) @@ -36,6 +37,7 @@ SET (HDRS HopperEntity.h JukeboxEntity.h MobHeadEntity.h + MobSpawnerEntity.h NoteEntity.h SignEntity.h) diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp new file mode 100644 index 000000000..1db1aad9b --- /dev/null +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -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; +} + + + + diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h new file mode 100644 index 000000000..b173214a5 --- /dev/null +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -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 + + + + -- cgit v1.2.3 From 718eb227abe3b9a0e5277d663e32c6e10d51ab52 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 19 Sep 2014 23:00:54 +0200 Subject: Implemented mob spawner. --- src/BlockEntities/BlockEntity.cpp | 6 +- src/BlockEntities/MobSpawnerEntity.cpp | 310 +++++++++++++++++++++++++++++--- src/BlockEntities/MobSpawnerEntity.h | 50 +++--- src/Blocks/BlockMobSpawner.h | 12 ++ src/Chunk.cpp | 7 +- src/MobSpawner.cpp | 13 +- src/MobSpawner.h | 5 +- src/Mobs/Monster.h | 2 +- src/Protocol/Protocol17x.cpp | 14 +- src/WorldStorage/NBTChunkSerializer.cpp | 15 ++ src/WorldStorage/NBTChunkSerializer.h | 26 +-- 11 files changed, 393 insertions(+), 67 deletions(-) diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 05ad03a3d..a969f493e 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -14,10 +14,11 @@ #include "FlowerPotEntity.h" #include "FurnaceEntity.h" #include "HopperEntity.h" +#include "MobHeadEntity.h" +#include "MobSpawnerEntity.h" #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" -#include "MobHeadEntity.h" @@ -35,8 +36,9 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_MOB_SPAWNER: return new cMobSpawnerEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 1db1aad9b..2b963c3f9 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -2,22 +2,22 @@ #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" +#include "../World.h" +#include "../FastRandom.h" +#include "../MobSpawner.h" +#include "../Items/ItemSpawnEgg.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) + , m_Entity(cMonster::mtPig) + , m_SpawnDelay(100) + , m_IsActive(false) { } @@ -25,37 +25,170 @@ cMobSpawnerEntity::cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c -cMobSpawnerEntity::~cMobSpawnerEntity() +void cMobSpawnerEntity::SendTo(cClientHandle & a_Client) { - + a_Client.SendUpdateBlockEntity(*this); } -bool cMobSpawnerEntity::Tick(float a_Dt, cChunk & a_Chunk) +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 == cMonster::mtInvalidType) + { + return; + } + + m_Entity = MonsterType; + ResetTimer(); + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + LOGD("Changed monster spawner entity to %s!", GetEntityName().c_str()); + } +} + + + + + +void cMobSpawnerEntity::UpdateActiveState(void) { - + if (GetNearbyPlayersNum() > 0) + { + m_IsActive = true; + } + else + { + m_IsActive = false; + } } -void cMobSpawnerEntity::UsedBy(cPlayer * a_Player) +bool cMobSpawnerEntity::Tick(float a_Dt, cChunk & a_Chunk) { - if (IsPlayingRecord()) + // Update the active flag every 5 seconds + if ((m_World->GetWorldAge() % 100) == 0) + { + UpdateActiveState(); + } + + if (!m_IsActive) + { + return false; + } + + if (m_SpawnDelay <= 0) { - EjectRecord(); + SpawnEntity(); + return true; } else { - const cItem & HeldItem = a_Player->GetEquippedItem(); - if (PlayRecord(HeldItem.m_ItemType)) + m_SpawnDelay--; + } + return false; +} + + + + + +void cMobSpawnerEntity::ResetTimer(void) +{ + m_SpawnDelay = 200 + m_World->GetTickRandomNumber(600); + m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ); +} + + + + + +void cMobSpawnerEntity::SpawnEntity(void) +{ + int NearbyEntities = GetNearbyEntityNum(m_Entity); + if (NearbyEntities >= 6) + { + ResetTimer(); + return; + } + + class cCallback : public cChunkCallback + { + public: + cCallback(int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, int a_NearbyEntitiesNum) : + m_RelX(a_RelX), + m_RelY(a_RelY), + m_RelZ(a_RelZ), + m_MobType(a_MobType), + m_NearbyEntitiesNum(a_NearbyEntitiesNum) { - a_Player->GetInventory().RemoveOneEquippedItem(); } + + virtual bool Item(cChunk * a_Chunk) + { + cFastRandom Random; + + bool EntitiesSpawned = false; + for (size_t i = 0; i < 4; i++) + { + if (m_NearbyEntitiesNum >= 6) + { + break; + } + + int RelX = (int) (m_RelX + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + int RelY = m_RelY + Random.NextInt(3) - 1; + int RelZ = (int) (m_RelZ + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + + cChunk * Chunk = a_Chunk->GetRelNeighborChunkAdjustCoords(RelX, RelZ); + if ((Chunk == NULL) || !Chunk->IsValid()) + { + continue; + } + EMCSBiome Biome = Chunk->GetBiomeAt(RelX, RelZ); + + if (cMobSpawner::CanSpawnHere(Chunk, RelX, RelY, RelZ, m_MobType, Biome)) + { + double PosX = Chunk->GetPosX() * cChunkDef::Width + RelX; + double PosZ = Chunk->GetPosZ() * cChunkDef::Width + RelZ; + + cMonster * Monster = cMonster::NewMonsterFromType(m_MobType); + if (Monster == NULL) + { + continue; + } + + Monster->SetPosition(PosX, RelY, PosZ); + Monster->SetYaw(Random.NextFloat() * 360.0f); + if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != cMonster::mtInvalidType) + { + EntitiesSpawned = true; + Chunk->BroadcastSoundParticleEffect(2004, (int)(PosX * 8.0), (int)(RelY * 8.0), (int)(PosZ * 8.0), 0); + m_NearbyEntitiesNum++; + } + } + } + return EntitiesSpawned; + } + protected: + int m_RelX, m_RelY, m_RelZ; + cMonster::eType m_MobType; + int m_NearbyEntitiesNum; + } Callback(m_RelX, m_PosY, m_RelZ, m_Entity, NearbyEntities); + + if (m_World->DoWithChunk(GetChunkX(), GetChunkZ(), Callback)) + { + ResetTimer(); } } @@ -69,8 +202,6 @@ bool cMobSpawnerEntity::LoadFromJson(const Json::Value & a_Value) 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; } @@ -83,8 +214,145 @@ 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) + { + case cMonster::mtBat: return "Bat"; + case cMonster::mtBlaze: return "Blaze"; + case cMonster::mtCaveSpider: return "CaveSpider"; + case cMonster::mtChicken: return "Chicken"; + case cMonster::mtCow: return "Cow"; + case cMonster::mtCreeper: return "Creeper"; + case cMonster::mtEnderDragon: return "EnderDragon"; + case cMonster::mtEnderman: return "Enderman"; + case cMonster::mtGhast: return "Ghast"; + case cMonster::mtGiant: return "Giant"; + case cMonster::mtHorse: return "EntityHorse"; + case cMonster::mtIronGolem: return "VillagerGolem"; + case cMonster::mtMagmaCube: return "LavaSlime"; + case cMonster::mtMooshroom: return "MushroomCow"; + case cMonster::mtOcelot: return "Ozelot"; + case cMonster::mtPig: return "Pig"; + case cMonster::mtSheep: return "Sheep"; + case cMonster::mtSilverfish: return "Silverfish"; + case cMonster::mtSkeleton: return "Skeleton"; + case cMonster::mtSlime: return "Slime"; + case cMonster::mtSnowGolem: return "SnowMan"; + case cMonster::mtSpider: return "Spider"; + case cMonster::mtSquid: return "Squid"; + case cMonster::mtVillager: return "Villager"; + case cMonster::mtWitch: return "Witch"; + case cMonster::mtWither: return "WitherBoss"; + case cMonster::mtWolf: return "Wolf"; + case cMonster::mtZombie: return "Zombie"; + case cMonster::mtZombiePigman: return "PigZombie"; + default: + { + ASSERT(!"Unknown monster type!"); + return "Pig"; + } + } +} + + + + + +int cMobSpawnerEntity::GetNearbyPlayersNum(void) +{ + Vector3d SpawnerPos(m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); + int NumPlayers = 0; + + class cCallback : public cChunkDataCallback + { + public: + cCallback(Vector3d a_SpawnerPos, int & a_NumPlayers) : + m_SpawnerPos(a_SpawnerPos), + m_NumPlayers(a_NumPlayers) + { + } + + virtual void Entity(cEntity * a_Entity) override + { + if (!a_Entity->IsPlayer()) + { + return; + } + + if ((m_SpawnerPos - a_Entity->GetPosition()).Length() <= 16) + { + m_NumPlayers++; + } + } + + protected: + Vector3d m_SpawnerPos; + int & m_NumPlayers; + } Callback(SpawnerPos, NumPlayers); + + int ChunkX = GetChunkX(); + int ChunkZ = GetChunkZ(); + m_World->ForEachChunkInRect(ChunkX - 1, ChunkX + 1, ChunkZ - 1, ChunkZ + 1, Callback); + + return NumPlayers; +} + + + + + +int cMobSpawnerEntity::GetNearbyEntityNum(cMonster::eType a_EntityType) +{ + Vector3d SpawnerPos(m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); + int NumEntities = 0; + + class cCallback : public cChunkDataCallback + { + public: + cCallback(Vector3d a_SpawnerPos, cMonster::eType a_EntityType, int & a_NumEntities) : + m_SpawnerPos(a_SpawnerPos), + m_EntityType(a_EntityType), + m_NumEntities(a_NumEntities) + { + } + + virtual void Entity(cEntity * a_Entity) override + { + if (!a_Entity->IsMob()) + { + return; + } + + cMonster * Mob = (cMonster *)a_Entity; + if (Mob->GetMobType() != m_EntityType) + { + return; + } + + if (((m_SpawnerPos - a_Entity->GetPosition()).Length() <= 8) && (Diff(m_SpawnerPos.y, a_Entity->GetPosY()) <= 4.0)) + { + m_NumEntities++; + } + } + + protected: + Vector3d m_SpawnerPos; + cMonster::eType m_EntityType; + int & m_NumEntities; + } Callback(SpawnerPos, a_EntityType, NumEntities); + + int ChunkX = GetChunkX(); + int ChunkZ = GetChunkZ(); + m_World->ForEachChunkInRect(ChunkX - 1, ChunkX + 1, ChunkZ - 1, ChunkZ + 1, Callback); - a_Value["Record"] = m_Record; + return NumEntities; } diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index b173214a5..b12a97d65 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -28,41 +28,51 @@ 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 void SendTo(cClientHandle & a_Client) override; + virtual void UsedBy(cPlayer * a_Player) 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; } + /** Upate the active flag from the mob spawner. This function will called every 5 seconds from the Tick() function. */ + void UpdateActiveState(void); + + /** Sets the spawn delay to a new random value. */ + void ResetTimer(void); + + /** Spawns the entity. This function automaticly change the spawn delay! */ + void SpawnEntity(void); + + /** Returns the entity type who will be spawn by this mob spawner. */ + cMonster::eType GetEntity(void) const { return m_Entity; } + + /** Sets the entity type who will be spawn by this mob spawner. */ + void SetEntity(cMonster::eType a_EntityType) { m_Entity = a_EntityType; } + + /** Returns the entity name. (Required by the protocol) */ + AString GetEntityName(void) const; + + /** Returns the spawn delay. */ + int GetSpawnDelay(void) const { return m_SpawnDelay; } + + int GetNearbyPlayersNum(void); + int GetNearbyEntityNum(cMonster::eType 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"; } - - virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle &) override {} private: /** The entity to spawn. */ - AString m_EntityName; + cMonster::eType m_Entity; 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; + bool m_IsActive; } ; // tolua_end diff --git a/src/Blocks/BlockMobSpawner.h b/src/Blocks/BlockMobSpawner.h index a51fbaafc..d5e7c273f 100644 --- a/src/Blocks/BlockMobSpawner.h +++ b/src/Blocks/BlockMobSpawner.h @@ -19,6 +19,18 @@ public: } + virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + a_ChunkInterface.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); + } + + + virtual bool IsUseable() override + { + return true; + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // No pickups diff --git a/src/Chunk.cpp b/src/Chunk.cpp index e75acb03b..c799f65fd 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -16,13 +16,14 @@ #include "BlockEntities/ChestEntity.h" #include "BlockEntities/DispenserEntity.h" #include "BlockEntities/DropperEntity.h" +#include "BlockEntities/FlowerPotEntity.h" #include "BlockEntities/FurnaceEntity.h" #include "BlockEntities/HopperEntity.h" #include "BlockEntities/JukeboxEntity.h" +#include "BlockEntities/MobHeadEntity.h" +#include "BlockEntities/MobSpawnerEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" -#include "BlockEntities/MobHeadEntity.h" -#include "BlockEntities/FlowerPotEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -1344,6 +1345,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: case E_BLOCK_FLOWER_POT: + case E_BLOCK_MOB_SPAWNER: { if (!HasBlockEntityAt(x + m_PosX * Width, y, z + m_PosZ * Width)) { @@ -1475,6 +1477,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: case E_BLOCK_FLOWER_POT: + case E_BLOCK_MOB_SPAWNER: { AddBlockEntity(cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, WorldPos.x, WorldPos.y, WorldPos.z, m_World)); break; diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index db05b70af..2350ffe85 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -126,8 +126,9 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome) { + cFastRandom Random; BLOCKTYPE TargetBlock = E_BLOCK_AIR; - if (m_AllowedTypes.find(a_MobType) != m_AllowedTypes.end() && a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) + if (a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) { if ((a_RelY + 1 > cChunkDef::Height) || (a_RelY - 1 < 0)) { @@ -177,7 +178,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R (BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES) ) && (a_RelY >= 62) && - (m_Random.NextInt(3, a_Biome) != 0) + (Random.NextInt(3, a_Biome) != 0) ); } @@ -238,7 +239,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R (!cBlockInfo::IsTransparent(BlockBelow)) && (SkyLight <= 7) && (BlockLight <= 7) && - (m_Random.NextInt(2, a_Biome) == 0) + (Random.NextInt(2, a_Biome) == 0) ); } @@ -262,7 +263,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && (!cBlockInfo::IsTransparent(BlockBelow)) && - (m_Random.NextInt(20, a_Biome) == 0) + (Random.NextInt(20, a_Biome) == 0) ); } @@ -322,8 +323,8 @@ cMonster* cMobSpawner::TryToSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, // Make sure we are looking at the right chunk to spawn in a_Chunk = a_Chunk->GetRelNeighborChunkAdjustCoords(a_RelX, a_RelZ); - - if (CanSpawnHere(a_Chunk, a_RelX, a_RelY, a_RelZ, m_MobType, a_Biome)) + + if ((m_AllowedTypes.find(m_MobType) != m_AllowedTypes.end()) && CanSpawnHere(a_Chunk, a_RelX, a_RelY, a_RelZ, m_MobType, a_Biome)) { cMonster * newMob = cMonster::NewMonsterFromType(m_MobType); if (newMob) diff --git a/src/MobSpawner.h b/src/MobSpawner.h index f3c56fe2d..e139f6923 100644 --- a/src/MobSpawner.h +++ b/src/MobSpawner.h @@ -51,9 +51,10 @@ public : typedef const std::set tSpawnedContainer; 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); + protected : - // return true if specified type of mob can spawn on specified block - bool CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, EMCSBiome a_Biome); // return a random type that can spawn on specified biome. // returns E_ENTITY_TYPE_DONOTUSE if none is possible diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index ca3c04c23..86c882d47 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -96,7 +96,7 @@ public: virtual bool ReachedDestination(void); // tolua_begin - eType GetMobType(void) const {return m_MobType; } + eType GetMobType(void) const { return m_MobType; } eFamily GetMobFamily(void) const; // tolua_end diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 7d80e79fb..49a62e4f3 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -40,6 +40,7 @@ Implements the 1.7.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" @@ -2695,6 +2696,18 @@ void cProtocol172::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; } @@ -3151,4 +3164,3 @@ void cProtocol176::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) - diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 68e541eba..a2bf3f8e1 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -18,6 +18,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/JukeboxEntity.h" +#include "../BlockEntities/MobSpawnerEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" #include "../BlockEntities/MobHeadEntity.h" @@ -278,6 +279,19 @@ void cNBTChunkSerializer::AddJukeboxEntity(cJukeboxEntity * a_Jukebox) +void cNBTChunkSerializer::AddMobSpawnerEntity(cMobSpawnerEntity * a_MobSpawner) +{ + m_Writer.BeginCompound(""); + AddBasicTileEntity(a_MobSpawner, "MobSpawner"); + m_Writer.AddString("EntityId", a_MobSpawner->GetEntityName()); + m_Writer.AddShort("Delay", (Int16)a_MobSpawner->GetSpawnDelay()); + m_Writer.EndCompound(); +} + + + + + void cNBTChunkSerializer::AddNoteEntity(cNoteEntity * a_Note) { m_Writer.BeginCompound(""); @@ -862,6 +876,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_LIT_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; + case E_BLOCK_MOB_SPAWNER: AddMobSpawnerEntity ((cMobSpawnerEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: AddSignEntity ((cSignEntity *) a_Entity); break; case E_BLOCK_TRAPPED_CHEST: AddChestEntity ((cChestEntity *) a_Entity, a_Entity->GetBlockType()); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 4c229a65c..7ff4b0e9b 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -32,6 +32,7 @@ class cJukeboxEntity; class cNoteEntity; class cSignEntity; class cMobHeadEntity; +class cMobSpawnerEntity; class cFlowerPotEntity; class cFallingBlock; class cMinecart; @@ -93,19 +94,20 @@ protected: void AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum = 0); // Block entities: - void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID); - void AddBeaconEntity (cBeaconEntity * a_Entity); - void AddChestEntity (cChestEntity * a_Entity, BLOCKTYPE a_ChestType); - void AddDispenserEntity(cDispenserEntity * a_Entity); - void AddDropperEntity (cDropperEntity * a_Entity); - void AddFurnaceEntity (cFurnaceEntity * a_Furnace); - void AddHopperEntity (cHopperEntity * a_Entity); - void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); - void AddNoteEntity (cNoteEntity * a_Note); - void AddSignEntity (cSignEntity * a_Sign); - void AddMobHeadEntity (cMobHeadEntity * a_MobHead); + void AddBasicTileEntity (cBlockEntity * a_Entity, const char * a_EntityTypeID); + void AddBeaconEntity (cBeaconEntity * a_Entity); + void AddChestEntity (cChestEntity * a_Entity, BLOCKTYPE a_ChestType); + void AddDispenserEntity (cDispenserEntity * a_Entity); + void AddDropperEntity (cDropperEntity * a_Entity); + void AddFurnaceEntity (cFurnaceEntity * a_Furnace); + void AddHopperEntity (cHopperEntity * a_Entity); + void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); + void AddMobSpawnerEntity (cMobSpawnerEntity * a_MobSpawner); + void AddNoteEntity (cNoteEntity * a_Note); + void AddSignEntity (cSignEntity * a_Sign); + void AddMobHeadEntity (cMobHeadEntity * a_MobHead); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); - void AddFlowerPotEntity(cFlowerPotEntity * a_FlowerPot); + void AddFlowerPotEntity (cFlowerPotEntity * a_FlowerPot); // Entities: void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName); -- cgit v1.2.3 From 5e71d5299c9cc8c80166ab202f376ffb086a2fa7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 27 Sep 2014 00:07:17 +0200 Subject: Fixed compile errors. --- src/BlockEntities/MobSpawnerEntity.cpp | 76 +++++++++++++++++----------------- src/BlockEntities/MobSpawnerEntity.h | 8 ++-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 2b963c3f9..0d14ad647 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -15,7 +15,7 @@ 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_Entity(cMonster::mtPig) + , m_Entity(mtPig) , m_SpawnDelay(100) , m_IsActive(false) { @@ -39,7 +39,7 @@ 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 == cMonster::mtInvalidType) + if (MonsterType == mtInvalidType) { return; } @@ -115,7 +115,7 @@ void cMobSpawnerEntity::ResetTimer(void) void cMobSpawnerEntity::SpawnEntity(void) { - int NearbyEntities = GetNearbyEntityNum(m_Entity); + int NearbyEntities = GetNearbyMonsterNum(m_Entity); if (NearbyEntities >= 6) { ResetTimer(); @@ -125,7 +125,7 @@ void cMobSpawnerEntity::SpawnEntity(void) class cCallback : public cChunkCallback { public: - cCallback(int a_RelX, int a_RelY, int a_RelZ, cMonster::eType a_MobType, int a_NearbyEntitiesNum) : + cCallback(int a_RelX, int a_RelY, int a_RelZ, eMonsterType a_MobType, int a_NearbyEntitiesNum) : m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ), @@ -170,7 +170,7 @@ void cMobSpawnerEntity::SpawnEntity(void) Monster->SetPosition(PosX, RelY, PosZ); Monster->SetYaw(Random.NextFloat() * 360.0f); - if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != cMonster::mtInvalidType) + if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != mtInvalidType) { EntitiesSpawned = true; Chunk->BroadcastSoundParticleEffect(2004, (int)(PosX * 8.0), (int)(RelY * 8.0), (int)(PosZ * 8.0), 0); @@ -182,7 +182,7 @@ void cMobSpawnerEntity::SpawnEntity(void) } protected: int m_RelX, m_RelY, m_RelZ; - cMonster::eType m_MobType; + eMonsterType m_MobType; int m_NearbyEntitiesNum; } Callback(m_RelX, m_PosY, m_RelZ, m_Entity, NearbyEntities); @@ -224,35 +224,35 @@ AString cMobSpawnerEntity::GetEntityName() const { switch (m_Entity) { - case cMonster::mtBat: return "Bat"; - case cMonster::mtBlaze: return "Blaze"; - case cMonster::mtCaveSpider: return "CaveSpider"; - case cMonster::mtChicken: return "Chicken"; - case cMonster::mtCow: return "Cow"; - case cMonster::mtCreeper: return "Creeper"; - case cMonster::mtEnderDragon: return "EnderDragon"; - case cMonster::mtEnderman: return "Enderman"; - case cMonster::mtGhast: return "Ghast"; - case cMonster::mtGiant: return "Giant"; - case cMonster::mtHorse: return "EntityHorse"; - case cMonster::mtIronGolem: return "VillagerGolem"; - case cMonster::mtMagmaCube: return "LavaSlime"; - case cMonster::mtMooshroom: return "MushroomCow"; - case cMonster::mtOcelot: return "Ozelot"; - case cMonster::mtPig: return "Pig"; - case cMonster::mtSheep: return "Sheep"; - case cMonster::mtSilverfish: return "Silverfish"; - case cMonster::mtSkeleton: return "Skeleton"; - case cMonster::mtSlime: return "Slime"; - case cMonster::mtSnowGolem: return "SnowMan"; - case cMonster::mtSpider: return "Spider"; - case cMonster::mtSquid: return "Squid"; - case cMonster::mtVillager: return "Villager"; - case cMonster::mtWitch: return "Witch"; - case cMonster::mtWither: return "WitherBoss"; - case cMonster::mtWolf: return "Wolf"; - case cMonster::mtZombie: return "Zombie"; - case cMonster::mtZombiePigman: return "PigZombie"; + case mtBat: return "Bat"; + case mtBlaze: return "Blaze"; + case mtCaveSpider: return "CaveSpider"; + case mtChicken: return "Chicken"; + case mtCow: return "Cow"; + case mtCreeper: return "Creeper"; + case mtEnderDragon: return "EnderDragon"; + case mtEnderman: return "Enderman"; + case mtGhast: return "Ghast"; + case mtGiant: return "Giant"; + case mtHorse: return "EntityHorse"; + case mtIronGolem: return "VillagerGolem"; + case mtMagmaCube: return "LavaSlime"; + case mtMooshroom: return "MushroomCow"; + case mtOcelot: return "Ozelot"; + case mtPig: return "Pig"; + case mtSheep: return "Sheep"; + case mtSilverfish: return "Silverfish"; + case mtSkeleton: return "Skeleton"; + case mtSlime: return "Slime"; + case mtSnowGolem: return "SnowMan"; + case mtSpider: return "Spider"; + case mtSquid: return "Squid"; + case mtVillager: return "Villager"; + case mtWitch: return "Witch"; + case mtWither: return "WitherBoss"; + case mtWolf: return "Wolf"; + case mtZombie: return "Zombie"; + case mtZombiePigman: return "PigZombie"; default: { ASSERT(!"Unknown monster type!"); @@ -308,7 +308,7 @@ int cMobSpawnerEntity::GetNearbyPlayersNum(void) -int cMobSpawnerEntity::GetNearbyEntityNum(cMonster::eType a_EntityType) +int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) { Vector3d SpawnerPos(m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); int NumEntities = 0; @@ -316,7 +316,7 @@ int cMobSpawnerEntity::GetNearbyEntityNum(cMonster::eType a_EntityType) class cCallback : public cChunkDataCallback { public: - cCallback(Vector3d a_SpawnerPos, cMonster::eType a_EntityType, int & a_NumEntities) : + cCallback(Vector3d a_SpawnerPos, eMonsterType a_EntityType, int & a_NumEntities) : m_SpawnerPos(a_SpawnerPos), m_EntityType(a_EntityType), m_NumEntities(a_NumEntities) @@ -344,7 +344,7 @@ int cMobSpawnerEntity::GetNearbyEntityNum(cMonster::eType a_EntityType) protected: Vector3d m_SpawnerPos; - cMonster::eType m_EntityType; + eMonsterType m_EntityType; int & m_NumEntities; } Callback(SpawnerPos, a_EntityType, NumEntities); diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index b12a97d65..7fec2699c 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -45,10 +45,10 @@ public: void SpawnEntity(void); /** Returns the entity type who will be spawn by this mob spawner. */ - cMonster::eType GetEntity(void) const { return m_Entity; } + eMonsterType GetEntity(void) const { return m_Entity; } /** Sets the entity type who will be spawn by this mob spawner. */ - void SetEntity(cMonster::eType a_EntityType) { m_Entity = a_EntityType; } + void SetEntity(eMonsterType a_EntityType) { m_Entity = a_EntityType; } /** Returns the entity name. (Required by the protocol) */ AString GetEntityName(void) const; @@ -57,7 +57,7 @@ public: int GetSpawnDelay(void) const { return m_SpawnDelay; } int GetNearbyPlayersNum(void); - int GetNearbyEntityNum(cMonster::eType a_EntityType); + int GetNearbyMonsterNum(eMonsterType a_EntityType); // tolua_end @@ -68,7 +68,7 @@ public: private: /** The entity to spawn. */ - cMonster::eType m_Entity; + eMonsterType m_Entity; int m_SpawnDelay; -- cgit v1.2.3 From 8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 18 Nov 2014 15:33:41 +0100 Subject: Finished mob spawner implementation. --- src/BlockEntities/BeaconEntity.h | 10 +------ src/BlockEntities/BlockEntity.h | 5 ---- src/BlockEntities/ChestEntity.h | 5 ---- src/BlockEntities/CommandBlockEntity.h | 8 ------ src/BlockEntities/DropSpenserEntity.h | 4 --- src/BlockEntities/FlowerPotEntity.h | 10 ------- src/BlockEntities/FurnaceEntity.h | 5 ---- src/BlockEntities/JukeboxEntity.h | 9 ------ src/BlockEntities/MobHeadEntity.h | 8 ------ src/BlockEntities/MobSpawnerEntity.cpp | 33 +++------------------- src/BlockEntities/MobSpawnerEntity.h | 19 ++++--------- src/BlockEntities/NoteEntity.h | 6 ---- src/BlockEntities/SignEntity.h | 9 ------ src/MobSpawner.h | 2 +- src/Protocol/Protocol18x.cpp | 13 +++++++++ src/WorldStorage/NBTChunkSerializer.cpp | 5 ++-- src/WorldStorage/WSSAnvil.cpp | 50 +++++++++++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 1 + 18 files changed, 78 insertions(+), 124 deletions(-) diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h index d1db3a68f..783e04fe2 100644 --- a/src/BlockEntities/BeaconEntity.h +++ b/src/BlockEntities/BeaconEntity.h @@ -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 diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index c778e97bc..056a88721 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -28,11 +28,6 @@ -namespace Json -{ - class Value; -}; - class cChunk; class cPlayer; class cWorld; diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 09fffb923..a8a765430 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -7,11 +7,6 @@ -namespace Json -{ - class Value; -}; - class cClientHandle; diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index 217390293..8b5a2b87f 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -15,14 +15,6 @@ -namespace Json -{ - class Value; -} - - - - // tolua_begin diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index f77a28c28..8ce7f8bb8 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -16,10 +16,6 @@ -namespace Json -{ - class Value; -} class cClientHandle; diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h index fc886c51f..e98d0a395 100644 --- a/src/BlockEntities/FlowerPotEntity.h +++ b/src/BlockEntities/FlowerPotEntity.h @@ -15,16 +15,6 @@ - -namespace Json -{ - class Value; -} - - - - - // tolua_begin class cFlowerPotEntity : diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 71c2fe127..0a66c60e3 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -8,11 +8,6 @@ -namespace Json -{ - class Value; -} - class cClientHandle; diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 7a69d6499..67a8aa62a 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -7,15 +7,6 @@ -namespace Json -{ - class Value; -} - - - - - // tolua_begin class cJukeboxEntity : diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index 7132ef558..55e45f0a6 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -14,14 +14,6 @@ -namespace Json -{ - class Value; -} - - - - // tolua_begin diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 0d14ad647..696a109d1 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -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) diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index 7fec2699c..073eb03ab 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -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 diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index fc5f27d07..b33edba4e 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -5,12 +5,6 @@ #include "RedstonePoweredEntity.h" -namespace Json -{ - class Value; -} - - diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index 52baa486d..09ab46f0b 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -14,15 +14,6 @@ -namespace Json -{ - class Value; -} - - - - - // tolua_begin class cSignEntity : diff --git a/src/MobSpawner.h b/src/MobSpawner.h index 3d2d4a6ce..e8b8f191b 100644 --- a/src/MobSpawner.h +++ b/src/MobSpawner.h @@ -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. diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 8170a494f..42f365e80 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -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; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 05d5709db..228df2686 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -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(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(); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 0c77b4d67..451f20ca5 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -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 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(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: diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 9c579a617..7a98a9a04 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -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); -- cgit v1.2.3 From 2478e290f9f7f6a74bba4ac885cfaef6327bc9ee Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 29 Nov 2014 15:20:44 +0100 Subject: Many api fixes, add vanilla names to mob type -> string functions and mob spawner fixes. --- MCServer/Plugins/APIDump/APIDesc.lua | 20 ++-- MCServer/Plugins/APIDump/Classes/BlockEntities.lua | 37 +++++++ src/Bindings/AllToLua.pkg | 1 + src/BlockEntities/MobHeadEntity.h | 12 +-- src/BlockEntities/MobSpawnerEntity.cpp | 47 +-------- src/BlockEntities/MobSpawnerEntity.h | 10 +- src/Mobs/Monster.cpp | 113 +++++++++++---------- src/Mobs/Monster.h | 11 +- src/Protocol/Protocol17x.cpp | 2 +- src/Protocol/Protocol17x.h | 1 + src/Protocol/Protocol18x.cpp | 2 +- src/Protocol/Protocol18x.h | 1 + src/WorldStorage/NBTChunkSerializer.cpp | 2 +- 13 files changed, 137 insertions(+), 122 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 9b87781a6..832540d3e 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1668,13 +1668,14 @@ a_Player:OpenWindow(Window); SetCustomName = { Params = "string", Return = "", Notes = "Sets the custom name of the monster. You see the name over the monster. If you want to disable the custom name, simply set an empty string." }, IsCustomNameAlwaysVisible = { Params = "", Return = "bool", Notes = "Is the custom name of this monster always visible? If not, you only see the name when you sight the mob." }, SetCustomNameAlwaysVisible = { Params = "bool", Return = "", Notes = "Sets the custom name visiblity of this monster. If it's false, you only see the name when you sight the mob. If it's true, you always see the custom name." }, - FamilyFromType = { Params = "{{cMonster#MobType|MobType}}", Return = "{{cMonster#MobFamily|MobFamily}}", Notes = "(STATIC) Returns the mob family ({{cMonster#MobFamily|mfXXX}} constants) based on the mob type ({{cMonster#MobType|mtXXX}} constants)" }, + FamilyFromType = { Params = "{{Globals#MobType|MobType}}", Return = "{{cMonster#MobFamily|MobFamily}}", Notes = "(STATIC) Returns the mob family ({{cMonster#MobFamily|mfXXX}} constants) based on the mob type ({{Globals#MobType|mtXXX}} constants)" }, GetMobFamily = { Params = "", Return = "{{cMonster#MobFamily|MobFamily}}", Notes = "Returns this mob's family ({{cMonster#MobFamily|mfXXX}} constant)" }, - GetMobType = { Params = "", Return = "{{cMonster#MobType|MobType}}", Notes = "Returns the type of this mob ({{cMonster#MobType|mtXXX}} constant)" }, + GetMobType = { Params = "", Return = "{{Globals#MobType|MobType}}", Notes = "Returns the type of this mob ({{Globals#MobType|mtXXX}} constant)" }, GetSpawnDelay = { Params = "{{cMonster#MobFamily|MobFamily}}", Return = "number", Notes = "(STATIC) Returns the spawn delay - the number of game ticks between spawn attempts - for the specified mob family." }, - MobTypeToString = { Params = "{{cMonster#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the string representing the given mob type ({{cMonster#MobType|mtXXX}} constant), or empty string if unknown type." }, + MobTypeToString = { Params = "{{Globals#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the string representing the given mob type ({{Globals#MobType|mtXXX}} constant), or empty string if unknown type." }, + MobTypeToVanillaName = { Params = "{{Globals#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the correct vanilla name of the given mob type, or empty string if unknown type." }, MoveToPosition = { Params = "Position", Return = "", Notes = "Moves mob to the specified position" }, - StringToMobType = { Params = "string", Return = "{{cMonster#MobType|MobType}}", Notes = "(STATIC) Returns the mob type ({{cMonster#MobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized." }, + StringToMobType = { Params = "string", Return = "{{Globals#MobType|MobType}}", Notes = "(STATIC) Returns the mob type ({{Globals#MobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized." }, GetRelativeWalkSpeed = { Params = "", Return = "number", Notes = "Returns the relative walk speed of this mob. Standard is 1.0" }, SetRelativeWalkSpeed = { Params = "number", Return = "", Notes = "Sets the relative walk speed of this mob. Standard is 1.0" }, }, @@ -2571,7 +2572,7 @@ World:ForEachEntity( return; end local Monster = tolua.cast(a_Entity, "cMonster"); -- Get the cMonster out of cEntity, now that we know the entity represents one. - if (Monster:GetMobType() == cMonster.mtSpider) then + if (Monster:GetMobType() == mtSpider) then Monster:TeleportToCoords(Monster:GetPosX(), Monster:GetPosY() + 100, Monster:GetPosZ()); end end @@ -2928,7 +2929,7 @@ end StringToDamageType = {Params = "string", Return = "{{Globals#DamageType|DamageType}}", Notes = "Converts a string representation to a {{Globals#DamageType|DamageType}} enumerated value."}, StringToDimension = {Params = "string", Return = "{{Globals#WorldDimension|Dimension}}", Notes = "Converts a string representation to a {{Globals#WorldDimension|Dimension}} enumerated value"}, StringToItem = {Params = "string, {{cItem|cItem}}", Return = "bool", Notes = "Parses the given string and sets the item; returns true if successful"}, - StringToMobType = {Params = "string", Return = "{{cMonster#MobType|MobType}}", Notes = "Converts a string representation to a {{cMonster#MobType|MobType}} enumerated value"}, + StringToMobType = {Params = "string", Return = "{{Globals#MobType|MobType}}", Notes = "Converts a string representation to a {{Globals#MobType|MobType}} enumerated value"}, StripColorCodes = {Params = "string", Return = "string", Notes = "Removes all control codes used by MC for colors and styles"}, TrimString = {Params = "string", Return = "string", Notes = "Trims whitespace at both ends of the string"}, md5 = {Params = "string", Return = "string", Notes = "converts a string to an md5 hash"}, @@ -3014,6 +3015,13 @@ end gmXXX constants, the eGameMode_ constants are deprecated and will be removed from the API. ]], }, + MobType = + { + Include = { "^mt.*" }, + TextBefore = [[ + The following constants are used for the mob types. + ]], + }, Weather = { Include = { "^eWeather_.*", "wSunny", "wRain", "wStorm", "wThunderstorm" }, diff --git a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua index 90ebf12e6..daa658654 100644 --- a/MCServer/Plugins/APIDump/Classes/BlockEntities.lua +++ b/MCServer/Plugins/APIDump/Classes/BlockEntities.lua @@ -231,6 +231,43 @@ World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(), }, }, -- cJukeboxEntity + cMobHeadEntity = + { + Desc = [[ + This class represents a mob head block entity in the world. + ]], + Inherits = "cBlockEntity", + Functions = + { + SetType = { Params = "eMobHeadType", Return = "", Notes = "Set the type of the mob head" }, + SetRotation = { Params = "eMobHeadRotation", Return = "", Notes = "Sets the rotation of the mob head" }, + SetOwner = { Params = "string", Return = "", Notes = "Set the player name for mob heads with player type" }, + GetType = { Params = "", Return = "eMobHeadType", Notes = "Returns the type of the mob head" }, + GetRotation = { Params = "", Return = "eMobHeadRotation", Notes = "Returns the rotation of the mob head" }, + GetOwner = { Params = "", Return = "string", Notes = "Returns the player name of the mob head" }, + }, + }, -- cMobHeadEntity + + cMobSpawnerEntity = + { + Desc = [[ + This class represents a mob spawner block entity in the world. + ]], + Inherits = "cBlockEntity", + Functions = + { + UpdateActiveState = { Params = "", Return = "", Notes = "Upate the active flag from the mob spawner. This function will called every 5 seconds from the Tick() function." }, + ResetTimer = { Params = "", Return = "", Notes = "Sets the spawn delay to a new random value." }, + SpawnEntity = { Params = "", Return = "", Notes = "Spawns the entity. This function automaticly change the spawn delay!" }, + GetEntity = { Params = "", Return = "{{Globals#MobType|MobType}}", Notes = "Returns the entity type that will be spawn by this mob spawner." }, + SetEntity = { Params = "{{Globals#MobType|MobType}}", Return = "", Notes = "Sets the entity type who will be spawn by this mob spawner." }, + GetSpawnDelay = { Params = "", Return = "number", Notes = "Returns the spawn delay. This is the tick delay that is needed to spawn new monsters." }, + SetSpawnDelay = { Params = "number", Return = "", Notes = "Sets the spawn delay." }, + GetNearbyPlayersNum = { Params = "", Return = "number", Notes = "Returns the amount of the nearby players in a 16-block radius." }, + GetNearbyMonsterNum = { Params = "", Return = "number", Notes = "Returns the amount of this monster type in a 8-block radius (Y: 4-block radius)." }, + }, + }, -- cMobSpawnerEntity + cNoteEntity = { Desc = [[ diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 7b78578ee..7e174e770 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -74,6 +74,7 @@ $cfile "../BlockEntities/JukeboxEntity.h" $cfile "../BlockEntities/NoteEntity.h" $cfile "../BlockEntities/SignEntity.h" $cfile "../BlockEntities/MobHeadEntity.h" +$cfile "../BlockEntities/MobSpawnerEntity.h" $cfile "../BlockEntities/FlowerPotEntity.h" $cfile "../WebAdmin.h" $cfile "../Root.h" diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index e26c0bdd0..7f08c5ab2 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -33,22 +33,22 @@ public: // tolua_begin - /** Set the Type */ + /** Set the type of the mob head */ void SetType(const eMobHeadType & a_SkullType); - /** Set the Rotation */ + /** Set the rotation of the mob head */ void SetRotation(eMobHeadRotation a_Rotation); - /** Set the Player Name for Mobheads with Player type */ + /** Set the player name for mob heads with player type */ void SetOwner(const AString & a_Owner); - /** Get the Type */ + /** Returns the type of the mob head */ eMobHeadType GetType(void) const { return m_Type; } - /** Get the Rotation */ + /** Returns the rotation of the mob head */ eMobHeadRotation GetRotation(void) const { return m_Rotation; } - /** Get the setted Player Name */ + /** Returns the player name of the mob head */ AString GetOwner(void) const { return m_Owner; } // tolua_end diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 696a109d1..26499972d 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -49,7 +49,7 @@ void cMobSpawnerEntity::UsedBy(cPlayer * a_Player) { a_Player->GetInventory().RemoveOneEquippedItem(); } - LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), GetEntityName().c_str()); + LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), cMonster::MobTypeToString(MonsterType).c_str()); } } @@ -195,51 +195,6 @@ void cMobSpawnerEntity::SpawnEntity(void) -AString cMobSpawnerEntity::GetEntityName() const -{ - switch (m_Entity) - { - case mtBat: return "Bat"; - case mtBlaze: return "Blaze"; - case mtCaveSpider: return "CaveSpider"; - case mtChicken: return "Chicken"; - case mtCow: return "Cow"; - case mtCreeper: return "Creeper"; - case mtEnderDragon: return "EnderDragon"; - case mtEnderman: return "Enderman"; - case mtGhast: return "Ghast"; - case mtGiant: return "Giant"; - case mtHorse: return "EntityHorse"; - case mtIronGolem: return "VillagerGolem"; - case mtMagmaCube: return "LavaSlime"; - case mtMooshroom: return "MushroomCow"; - case mtOcelot: return "Ozelot"; - case mtPig: return "Pig"; - case mtSheep: return "Sheep"; - case mtSilverfish: return "Silverfish"; - case mtSkeleton: return "Skeleton"; - case mtSlime: return "Slime"; - case mtSnowGolem: return "SnowMan"; - case mtSpider: return "Spider"; - case mtSquid: return "Squid"; - case mtVillager: return "Villager"; - case mtWitch: return "Witch"; - case mtWither: return "WitherBoss"; - case mtWolf: return "Wolf"; - case mtZombie: return "Zombie"; - case mtZombiePigman: return "PigZombie"; - default: - { - ASSERT(!"Unknown monster type!"); - return "Pig"; - } - } -} - - - - - int cMobSpawnerEntity::GetNearbyPlayersNum(void) { Vector3d SpawnerPos(m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index 073eb03ab..0a3367c97 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -35,22 +35,22 @@ public: /** Spawns the entity. This function automaticly change the spawn delay! */ void SpawnEntity(void); - /** Returns the entity type who will be spawn by this mob spawner. */ + /** Returns the entity type that will be spawn by this mob spawner. */ eMonsterType GetEntity(void) const { return m_Entity; } /** Sets the entity type who will be spawn by this mob spawner. */ void SetEntity(eMonsterType a_EntityType) { m_Entity = a_EntityType; } - /** Returns the entity name. (Required by the protocol) */ - AString GetEntityName(void) const; - - /** Returns the spawn delay. */ + /** Returns the spawn delay. This is the tick delay that is needed to spawn new monsters. */ short GetSpawnDelay(void) const { return m_SpawnDelay; } /** Sets the spawn delay. */ void SetSpawnDelay(short a_Delay) { m_SpawnDelay = a_Delay; } + /** Returns the amount of the nearby players in a 16-block radius. */ int GetNearbyPlayersNum(void); + + /** Returns the amount of this monster type in a 8-block radius (Y: 4-block radius). */ int GetNearbyMonsterNum(eMonsterType a_EntityType); // tolua_end diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 5319bdf91..9937e6a95 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -26,36 +26,37 @@ static const struct { eMonsterType m_Type; const char * m_lcName; + const char * m_VanillaName; } g_MobTypeNames[] = { - {mtBat, "bat"}, - {mtBlaze, "blaze"}, - {mtCaveSpider, "cavespider"}, - {mtChicken, "chicken"}, - {mtCow, "cow"}, - {mtCreeper, "creeper"}, - {mtEnderman, "enderman"}, - {mtEnderDragon, "enderdragon"}, - {mtGhast, "ghast"}, - {mtHorse, "horse"}, - {mtIronGolem, "irongolem"}, - {mtMagmaCube, "magmacube"}, - {mtMooshroom, "mooshroom"}, - {mtOcelot, "ocelot"}, - {mtPig, "pig"}, - {mtSheep, "sheep"}, - {mtSilverfish, "silverfish"}, - {mtSkeleton, "skeleton"}, - {mtSlime, "slime"}, - {mtSnowGolem, "snowgolem"}, - {mtSpider, "spider"}, - {mtSquid, "squid"}, - {mtVillager, "villager"}, - {mtWitch, "witch"}, - {mtWither, "wither"}, - {mtWolf, "wolf"}, - {mtZombie, "zombie"}, - {mtZombiePigman, "zombiepigman"}, + {mtBat, "bat", "Bat"}, + {mtBlaze, "blaze", "Blaze"}, + {mtCaveSpider, "cavespider", "CaveSpider"}, + {mtChicken, "chicken", "Chicken"}, + {mtCow, "cow", "Cow"}, + {mtCreeper, "creeper", "Creeper"}, + {mtEnderman, "enderman", "Enderman"}, + {mtEnderDragon, "enderdragon", "EnderDragon"}, + {mtGhast, "ghast", "Ghast"}, + {mtHorse, "horse", "EntityHorse"}, + {mtIronGolem, "irongolem", "VillagerGolem"}, + {mtMagmaCube, "magmacube", "LavaSlime"}, + {mtMooshroom, "mooshroom", "MushroomCow"}, + {mtOcelot, "ocelot", "Ozelot"}, + {mtPig, "pig", "Pig"}, + {mtSheep, "sheep", "Sheep"}, + {mtSilverfish, "silverfish", "Silverfish"}, + {mtSkeleton, "skeleton", "Skeleton"}, + {mtSlime, "slime", "Slime"}, + {mtSnowGolem, "snowgolem", "SnowMan"}, + {mtSpider, "spider", "Spider"}, + {mtSquid, "squid", "Squid"}, + {mtVillager, "villager", "Villager"}, + {mtWitch, "witch", "Witch"}, + {mtWither, "wither", "WitherBoss"}, + {mtWolf, "wolf", "Wolf"}, + {mtZombie, "zombie", "Zombie"}, + {mtZombiePigman, "zombiepigman", "PigZombie"}, } ; @@ -784,39 +785,47 @@ AString cMonster::MobTypeToString(eMonsterType a_MobType) -eMonsterType cMonster::StringToMobType(const AString & a_Name) +AString cMonster::MobTypeToVanillaName(eMonsterType a_MobType) { - AString lcName = StrToLower(a_Name); - - // Binary-search for the lowercase name: - int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1; - while (hi - lo > 1) + // Mob types aren't sorted, so we need to search linearly: + for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) { - int mid = (lo + hi) / 2; - int res = strcmp(g_MobTypeNames[mid].m_lcName, lcName.c_str()); - if (res == 0) - { - return g_MobTypeNames[mid].m_Type; - } - if (res < 0) - { - lo = mid; - } - else + if (g_MobTypeNames[i].m_Type == a_MobType) { - hi = mid; + return g_MobTypeNames[i].m_VanillaName; } } - // Range has collapsed to at most two elements, compare each: - if (strcmp(g_MobTypeNames[lo].m_lcName, lcName.c_str()) == 0) + + // Not found: + return ""; +} + + + + + +eMonsterType cMonster::StringToMobType(const AString & a_Name) +{ + AString lcName = StrToLower(a_Name); + + // Search MCServer name: + for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) { - return g_MobTypeNames[lo].m_Type; + if (strcmp(g_MobTypeNames[i].m_lcName, lcName.c_str()) == 0) + { + return g_MobTypeNames[i].m_Type; + } } - if ((lo != hi) && (strcmp(g_MobTypeNames[hi].m_lcName, lcName.c_str()) == 0)) + + // Not found. Search Vanilla name: + for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) { - return g_MobTypeNames[hi].m_Type; + if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaName).c_str(), lcName.c_str()) == 0) + { + return g_MobTypeNames[i].m_Type; + } } - + // Not found: return mtInvalidType; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index fd4e8a659..4903c38ad 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -133,16 +133,19 @@ public: If it's false, you only see the name when you sight the mob. If it's true, you always see the custom name. */ void SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible); - /// Translates MobType enum to a string, empty string if unknown + /** Translates MobType enum to a string, empty string if unknown */ static AString MobTypeToString(eMonsterType a_MobType); - /// Translates MobType string to the enum, mtInvalidType if not recognized + /** Translates MobType enum to the correct vanilla name of the mob, empty string if unknown. */ + static AString MobTypeToVanillaName(eMonsterType a_MobType); + + /** Translates MobType string to the enum, mtInvalidType if not recognized */ static eMonsterType StringToMobType(const AString & a_MobTypeName); - /// Returns the mob family based on the type + /** Returns the mob family based on the type */ static eFamily FamilyFromType(eMonsterType a_MobType); - /// Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family + /** Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family */ static int GetSpawnDelay(cMonster::eFamily a_MobFamily); // tolua_end diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9067131b2..1e5fe5586 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2670,7 +2670,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddInt("x", MobSpawnerEntity.GetPosX()); Writer.AddInt("y", MobSpawnerEntity.GetPosY()); Writer.AddInt("z", MobSpawnerEntity.GetPosZ()); - Writer.AddString("EntityId", MobSpawnerEntity.GetEntityName()); + Writer.AddString("EntityId", cMonster::MobTypeToVanillaName(MobSpawnerEntity.GetEntity())); Writer.AddShort("Delay", MobSpawnerEntity.GetSpawnDelay()); Writer.AddString("id", "MobSpawner"); break; diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index f939bfb5e..3865b086c 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -33,6 +33,7 @@ Declares the 1.7.x protocol classes: #include "PolarSSL++/AesCfb128Decryptor.h" #include "PolarSSL++/AesCfb128Encryptor.h" +#include "../Mobs/MonsterTypes.h" diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 42f365e80..ce580d73e 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -2980,7 +2980,7 @@ void cProtocol180::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddInt("x", MobSpawnerEntity.GetPosX()); Writer.AddInt("y", MobSpawnerEntity.GetPosY()); Writer.AddInt("z", MobSpawnerEntity.GetPosZ()); - Writer.AddString("EntityId", MobSpawnerEntity.GetEntityName()); + Writer.AddString("EntityId", cMonster::MobTypeToVanillaName(MobSpawnerEntity.GetEntity())); Writer.AddShort("Delay", MobSpawnerEntity.GetSpawnDelay()); Writer.AddString("id", "MobSpawner"); break; diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 92d9825ef..216639319 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -32,6 +32,7 @@ Declares the 1.8.x protocol classes: #include "PolarSSL++/AesCfb128Decryptor.h" #include "PolarSSL++/AesCfb128Encryptor.h" +#include "../Mobs/MonsterTypes.h" diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 228df2686..432e122b5 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -296,7 +296,7 @@ void cNBTChunkSerializer::AddMobSpawnerEntity(cMobSpawnerEntity * a_MobSpawner) m_Writer.BeginCompound(""); AddBasicTileEntity(a_MobSpawner, "MobSpawner"); m_Writer.AddShort("Entity", static_cast(a_MobSpawner->GetEntity())); - m_Writer.AddString("EntityId", a_MobSpawner->GetEntityName()); + m_Writer.AddString("EntityId", cMonster::MobTypeToVanillaName(a_MobSpawner->GetEntity())); m_Writer.AddShort("Delay", a_MobSpawner->GetSpawnDelay()); m_Writer.EndCompound(); } -- cgit v1.2.3 From 473cb6e0b2ec3c0fd497e66d407204ca47ec1cc9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 29 Nov 2014 15:22:24 +0100 Subject: Removed unused imports. --- src/Protocol/Protocol17x.h | 1 - src/Protocol/Protocol18x.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 3865b086c..f939bfb5e 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -33,7 +33,6 @@ Declares the 1.7.x protocol classes: #include "PolarSSL++/AesCfb128Decryptor.h" #include "PolarSSL++/AesCfb128Encryptor.h" -#include "../Mobs/MonsterTypes.h" diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 216639319..92d9825ef 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -32,7 +32,6 @@ Declares the 1.8.x protocol classes: #include "PolarSSL++/AesCfb128Decryptor.h" #include "PolarSSL++/AesCfb128Encryptor.h" -#include "../Mobs/MonsterTypes.h" -- cgit v1.2.3 From ea20ccaa960f2eab1a249080bfa5bb870d0f5b6f Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 29 Nov 2014 15:45:12 +0100 Subject: Removed old MobType category. --- MCServer/Plugins/APIDump/APIDesc.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 832540d3e..5a64345ca 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1726,13 +1726,6 @@ a_Player:OpenWindow(Window); Mobs are divided into families. The following constants are used for individual family types: ]], }, - MobType = - { - Include = "mt.*", - TextBefore = [[ - The following constants are used for distinguishing between the individual mob types: - ]], - }, }, Inherits = "cPawn", }, -- cMonster @@ -3019,7 +3012,7 @@ end { Include = { "^mt.*" }, TextBefore = [[ - The following constants are used for the mob types. + The following constants are used for distinguishing between the individual mob types: ]], }, Weather = -- cgit v1.2.3 From bcbd73f7d80b0a64b87c30840048f99613308ce0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Dec 2014 14:58:13 +0100 Subject: MobSpawner fixes. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- src/BlockEntities/BlockEntity.cpp | 2 +- src/BlockEntities/MobSpawnerEntity.cpp | 4 ++-- src/BlockEntities/MobSpawnerEntity.h | 7 +++++++ src/Mobs/Monster.cpp | 1 + src/Mobs/Monster.h | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index ecb8f6226..72dcce5e4 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1673,7 +1673,7 @@ a_Player:OpenWindow(Window); GetMobType = { Params = "", Return = "{{Globals#MobType|MobType}}", Notes = "Returns the type of this mob ({{Globals#MobType|mtXXX}} constant)" }, GetSpawnDelay = { Params = "{{cMonster#MobFamily|MobFamily}}", Return = "number", Notes = "(STATIC) Returns the spawn delay - the number of game ticks between spawn attempts - for the specified mob family." }, MobTypeToString = { Params = "{{Globals#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the string representing the given mob type ({{Globals#MobType|mtXXX}} constant), or empty string if unknown type." }, - MobTypeToVanillaName = { Params = "{{Globals#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the correct vanilla name of the given mob type, or empty string if unknown type." }, + MobTypeToVanillaName = { Params = "{{Globals#MobType|MobType}}", Return = "string", Notes = "(STATIC) Returns the vanilla name of the given mob type, or empty string if unknown type." }, MoveToPosition = { Params = "Position", Return = "", Notes = "Moves mob to the specified position" }, StringToMobType = { Params = "string", Return = "{{Globals#MobType|MobType}}", Notes = "(STATIC) Returns the mob type ({{Globals#MobType|mtXXX}} constant) parsed from the string type (\"creeper\"), or mtInvalidType if unrecognized." }, GetRelativeWalkSpeed = { Params = "", Return = "number", Notes = "Returns the relative walk speed of this mob. Standard is 1.0" }, diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 346970cd2..c59198e79 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -36,8 +36,8 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_MOB_SPAWNER: return new cMobSpawnerEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 26499972d..5edee888a 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -104,7 +104,7 @@ bool cMobSpawnerEntity::Tick(float a_Dt, cChunk & a_Chunk) void cMobSpawnerEntity::ResetTimer(void) { - m_SpawnDelay = (short) (200 + m_World->GetTickRandomNumber(600)); + m_SpawnDelay = static_cast(200 + m_World->GetTickRandomNumber(600)); m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ); } @@ -266,7 +266,7 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) return; } - if (((m_SpawnerPos - a_Entity->GetPosition()).Length() <= 8) && (Diff(m_SpawnerPos.y, a_Entity->GetPosY()) <= 4.0)) + if ((Diff(m_SpawnerPos.x, a_Entity->GetPosX()) <= 8.0) && (Diff(m_SpawnerPos.y, a_Entity->GetPosY()) <= 4.0) && (Diff(m_SpawnerPos.z, a_Entity->GetPosZ()) <= 8.0)) { m_NumEntities++; } diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index 0a3367c97..594b5301e 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -1,3 +1,10 @@ +// MobSpawnerEntity.h + +// Declares the cMobSpawnerEntity class representing a single mob spawner in the world + + + + #pragma once diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3011acd85..b8926e31d 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -21,6 +21,7 @@ /** Map for eType <-> string Needs to be alpha-sorted by the strings, because binary search is used in StringToMobType() The strings need to be lowercase (for more efficient comparisons in StringToMobType()) +m_VanillaName is the name that vanilla use for this mob. */ static const struct { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 4903c38ad..f04e45ac6 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -136,7 +136,7 @@ public: /** Translates MobType enum to a string, empty string if unknown */ static AString MobTypeToString(eMonsterType a_MobType); - /** Translates MobType enum to the correct vanilla name of the mob, empty string if unknown. */ + /** Translates MobType enum to the vanilla name of the mob, empty string if unknown. */ static AString MobTypeToVanillaName(eMonsterType a_MobType); /** Translates MobType string to the enum, mtInvalidType if not recognized */ diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4520751c7..ddee5e514 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1095,7 +1095,7 @@ cBlockEntity * cWSSAnvil::LoadMobSpawnerFromNBT(const cParsedNBT & a_NBT, int a_ return nullptr; } - std::auto_ptr MobSpawner(new cMobSpawnerEntity(a_BlockX, a_BlockY, a_BlockZ, m_World)); + std::unique_ptr MobSpawner(new cMobSpawnerEntity(a_BlockX, a_BlockY, a_BlockZ, m_World)); // Load entity (MCServer worlds): int Type = a_NBT.FindChildByName(a_TagIdx, "Entity"); -- cgit v1.2.3 From e74ad386f076348114d871842265c81d2bb7b87e Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Dec 2014 16:04:49 +0100 Subject: Reverted bad .gitignore change --- MCServer/Plugins/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/.gitignore b/MCServer/Plugins/.gitignore index 92424459f..8553945b5 100644 --- a/MCServer/Plugins/.gitignore +++ b/MCServer/Plugins/.gitignore @@ -1,3 +1,3 @@ *.txt *.md - +*/ -- cgit v1.2.3 From 3bf9e978aea9dd66bfb56dce6eb5ffc56853d0c8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Dec 2014 16:05:22 +0100 Subject: Updated core --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 5b7a6d464..4183d6cfb 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 5b7a6d464ed3e0e5d2a438ebf119430cacab26ae +Subproject commit 4183d6cfb2049d0757d811a65bd4e75ed78b9f41 -- cgit v1.2.3