summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-11-18 15:33:41 +0100
committerHowaner <franzi.moos@googlemail.com>2014-11-18 15:33:41 +0100
commit8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d (patch)
tree8b45393b6cc7095482dc377c2448e06d408830f9 /src/WorldStorage
parentMerge branch 'master' into MobSpawner (diff)
downloadcuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar.gz
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar.bz2
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar.lz
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar.xz
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.tar.zst
cuberite-8b028c5c78e53c149dfa8b3e7ec878f7f0428f1d.zip
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp5
-rw-r--r--src/WorldStorage/WSSAnvil.cpp50
-rw-r--r--src/WorldStorage/WSSAnvil.h1
3 files changed, 54 insertions, 2 deletions
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<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();
}
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<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:
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);