diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-13 09:36:43 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-13 09:36:43 +0200 |
commit | 03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43 (patch) | |
tree | 8027076867da60f62e52362059717c94084bcfd9 /source/WorldStorage | |
parent | ProtectionAreas: Added proper ignored files (diff) | |
download | cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar.gz cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar.bz2 cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar.lz cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar.xz cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.tar.zst cuberite-03c6bb9f85b929a99df2c800b8ba7d8ef4a8ec43.zip |
Diffstat (limited to 'source/WorldStorage')
-rw-r--r-- | source/WorldStorage/NBTChunkSerializer.cpp | 34 | ||||
-rw-r--r-- | source/WorldStorage/NBTChunkSerializer.h | 24 | ||||
-rw-r--r-- | source/WorldStorage/WSSAnvil.cpp | 82 | ||||
-rw-r--r-- | source/WorldStorage/WSSAnvil.h | 5 |
4 files changed, 96 insertions, 49 deletions
diff --git a/source/WorldStorage/NBTChunkSerializer.cpp b/source/WorldStorage/NBTChunkSerializer.cpp index 2cf34a24f..9c4f8a2ae 100644 --- a/source/WorldStorage/NBTChunkSerializer.cpp +++ b/source/WorldStorage/NBTChunkSerializer.cpp @@ -9,6 +9,7 @@ #include "../BlockEntities/DispenserEntity.h"
#include "../BlockEntities/DropperEntity.h"
#include "../BlockEntities/FurnaceEntity.h"
+#include "../BlockEntities/HopperEntity.h"
#include "../BlockEntities/JukeboxEntity.h"
#include "../BlockEntities/NoteEntity.h"
#include "../BlockEntities/SignEntity.h"
@@ -175,14 +176,25 @@ void cNBTChunkSerializer::AddFurnaceEntity(cFurnaceEntity * a_Furnace) -void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign)
+void cNBTChunkSerializer::AddHopperEntity(cHopperEntity * a_Entity)
{
m_Writer.BeginCompound("");
- AddBasicTileEntity(a_Sign, "Sign");
- m_Writer.AddString("Text1", a_Sign->GetLine(0));
- m_Writer.AddString("Text2", a_Sign->GetLine(1));
- m_Writer.AddString("Text3", a_Sign->GetLine(2));
- m_Writer.AddString("Text4", a_Sign->GetLine(3));
+ AddBasicTileEntity(a_Entity, "Hopper");
+ m_Writer.BeginList("Items", TAG_Compound);
+ AddItemGrid(a_Entity->GetContents());
+ m_Writer.EndList();
+ m_Writer.EndCompound();
+}
+
+
+
+
+
+void cNBTChunkSerializer::AddJukeboxEntity(cJukeboxEntity * a_Jukebox)
+{
+ m_Writer.BeginCompound("");
+ AddBasicTileEntity(a_Jukebox, "RecordPlayer");
+ m_Writer.AddInt("Record", a_Jukebox->GetRecord());
m_Writer.EndCompound();
}
@@ -202,11 +214,14 @@ void cNBTChunkSerializer::AddNoteEntity(cNoteEntity * a_Note) -void cNBTChunkSerializer::AddJukeboxEntity(cJukeboxEntity * a_Jukebox)
+void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign)
{
m_Writer.BeginCompound("");
- AddBasicTileEntity(a_Jukebox, "RecordPlayer");
- m_Writer.AddInt("Record", a_Jukebox->GetRecord());
+ AddBasicTileEntity(a_Sign, "Sign");
+ m_Writer.AddString("Text1", a_Sign->GetLine(0));
+ m_Writer.AddString("Text2", a_Sign->GetLine(1));
+ m_Writer.AddString("Text3", a_Sign->GetLine(2));
+ m_Writer.AddString("Text4", a_Sign->GetLine(3));
m_Writer.EndCompound();
}
@@ -428,6 +443,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break;
case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break;
+ case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break;
case E_BLOCK_SIGN_POST:
case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break;
case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break;
diff --git a/source/WorldStorage/NBTChunkSerializer.h b/source/WorldStorage/NBTChunkSerializer.h index 47389dfe8..14c31be01 100644 --- a/source/WorldStorage/NBTChunkSerializer.h +++ b/source/WorldStorage/NBTChunkSerializer.h @@ -20,12 +20,13 @@ class cFastNBTWriter; class cEntity;
class cBlockEntity;
class cChestEntity;
-class cFurnaceEntity;
class cDispenserEntity;
class cDropperEntity;
-class cSignEntity;
-class cNoteEntity;
+class cFurnaceEntity;
+class cHopperEntity;
class cJukeboxEntity;
+class cNoteEntity;
+class cSignEntity;
class cFallingBlock;
class cMinecart;
class cMinecartWithChest;
@@ -78,17 +79,18 @@ protected: void AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum = 0);
// Block entities:
- void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID);
- void AddChestEntity(cChestEntity * a_Entity);
+ void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID);
+ void AddChestEntity (cChestEntity * a_Entity);
void AddDispenserEntity(cDispenserEntity * a_Entity);
- void AddDropperEntity(cDropperEntity * a_Entity);
- void AddFurnaceEntity(cFurnaceEntity * a_Furnace);
- void AddSignEntity(cSignEntity * a_Sign);
- void AddNoteEntity(cNoteEntity * a_Note);
- void AddJukeboxEntity(cJukeboxEntity * a_Jukebox);
- void AddBasicEntity(cEntity * a_Entity, const AString & a_ClassName);
+ 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);
// Entities:
+ void AddBasicEntity (cEntity * a_Entity, const AString & a_ClassName);
void AddFallingBlockEntity(cFallingBlock * a_FallingBlock);
void AddMinecartEntity (cMinecart * a_Minecart);
void AddMonsterEntity (cMonster * a_Monster);
diff --git a/source/WorldStorage/WSSAnvil.cpp b/source/WorldStorage/WSSAnvil.cpp index 1b70083c2..43e6dce05 100644 --- a/source/WorldStorage/WSSAnvil.cpp +++ b/source/WorldStorage/WSSAnvil.cpp @@ -13,6 +13,7 @@ #include "../BlockEntities/DispenserEntity.h" #include "../BlockEntities/DropperEntity.h" #include "../BlockEntities/FurnaceEntity.h" +#include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" @@ -568,6 +569,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con { LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child); } + else if (strncmp(a_NBT.GetData(sID), "Hopper", a_NBT.GetDataLength(sID)) == 0) + { + LoadHopperFromNBT(a_BlockEntities, a_NBT, Child); + } else if (strncmp(a_NBT.GetData(sID), "Music", a_NBT.GetDataLength(sID)) == 0) { LoadNoteFromNBT(a_BlockEntities, a_NBT, Child); @@ -721,7 +726,7 @@ void cWSSAnvil::LoadDropperFromNBT(cBlockEntityList & a_BlockEntities, const cPa int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) { - return; // Make it an empty dispenser - the chunk loader will provide an empty cDispenserEntity for this + return; // Make it an empty dropper - the chunk loader will provide an empty cDropperEntity for this } std::auto_ptr<cDropperEntity> Dropper(new cDropperEntity(x, y, z, m_World)); LoadItemGridFromNBT(Dropper->GetContents(), a_NBT, Items); @@ -781,7 +786,7 @@ void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cPa -void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +void cWSSAnvil::LoadHopperFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; @@ -789,38 +794,41 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse { return; } - std::auto_ptr<cSignEntity> Sign(new cSignEntity(E_BLOCK_SIGN_POST, x, y, z, m_World)); - - int currentLine = a_NBT.FindChildByName(a_TagIdx, "Text1"); - if (currentLine >= 0) + int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); + if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) { - Sign->SetLine(0, a_NBT.GetString(currentLine)); + return; // Make it an empty hopper - the chunk loader will provide an empty cHopperEntity for this } + std::auto_ptr<cHopperEntity> Hopper(new cHopperEntity(x, y, z, m_World)); + LoadItemGridFromNBT(Hopper->GetContents(), a_NBT, Items); + a_BlockEntities.push_back(Hopper.release()); +} - currentLine = a_NBT.FindChildByName(a_TagIdx, "Text2"); - if (currentLine >= 0) - { - Sign->SetLine(1, a_NBT.GetString(currentLine)); - } - currentLine = a_NBT.FindChildByName(a_TagIdx, "Text3"); - if (currentLine >= 0) + + + +void cWSSAnvil::LoadJukeboxFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); + int x, y, z; + if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) { - Sign->SetLine(2, a_NBT.GetString(currentLine)); + return; } - - currentLine = a_NBT.FindChildByName(a_TagIdx, "Text4"); - if (currentLine >= 0) + std::auto_ptr<cJukeboxEntity> Jukebox(new cJukeboxEntity(x, y, z, m_World)); + int Record = a_NBT.FindChildByName(a_TagIdx, "Record"); + if (Record >= 0) { - Sign->SetLine(3, a_NBT.GetString(currentLine)); + Jukebox->SetRecord(a_NBT.GetInt(Record)); } - - a_BlockEntities.push_back(Sign.release()); + a_BlockEntities.push_back(Jukebox.release()); } + void cWSSAnvil::LoadNoteFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); @@ -842,7 +850,7 @@ void cWSSAnvil::LoadNoteFromNBT(cBlockEntityList & a_BlockEntities, const cParse -void cWSSAnvil::LoadJukeboxFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; @@ -850,13 +858,33 @@ void cWSSAnvil::LoadJukeboxFromNBT(cBlockEntityList & a_BlockEntities, const cPa { return; } - std::auto_ptr<cJukeboxEntity> Jukebox(new cJukeboxEntity(x, y, z, m_World)); - int Record = a_NBT.FindChildByName(a_TagIdx, "Record"); - if (Record >= 0) + std::auto_ptr<cSignEntity> Sign(new cSignEntity(E_BLOCK_SIGN_POST, x, y, z, m_World)); + + int currentLine = a_NBT.FindChildByName(a_TagIdx, "Text1"); + if (currentLine >= 0) { - Jukebox->SetRecord(a_NBT.GetInt(Record)); + Sign->SetLine(0, a_NBT.GetString(currentLine)); } - a_BlockEntities.push_back(Jukebox.release()); + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Text2"); + if (currentLine >= 0) + { + Sign->SetLine(1, a_NBT.GetString(currentLine)); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Text3"); + if (currentLine >= 0) + { + Sign->SetLine(2, a_NBT.GetString(currentLine)); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Text4"); + if (currentLine >= 0) + { + Sign->SetLine(3, a_NBT.GetString(currentLine)); + } + + a_BlockEntities.push_back(Sign.release()); } diff --git a/source/WorldStorage/WSSAnvil.h b/source/WorldStorage/WSSAnvil.h index 7281d687d..2dc17d2e9 100644 --- a/source/WorldStorage/WSSAnvil.h +++ b/source/WorldStorage/WSSAnvil.h @@ -131,9 +131,10 @@ protected: void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadHopperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); |