From cc26f1646308a71ea78f0656efa670915e5e7345 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 10 Apr 2013 19:52:03 +0000 Subject: Added cItemGrid to represent an XY grid of items; converted chests to use cItemGrid. http://forum.mc-server.org/showthread.php?tid=831 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1380 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WorldStorage/NBTChunkSerializer.cpp | 30 ++++++++++++++++++++---------- source/WorldStorage/NBTChunkSerializer.h | 5 +++++ 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'source/WorldStorage') diff --git a/source/WorldStorage/NBTChunkSerializer.cpp b/source/WorldStorage/NBTChunkSerializer.cpp index 992fa7f69..e033bfb9b 100644 --- a/source/WorldStorage/NBTChunkSerializer.cpp +++ b/source/WorldStorage/NBTChunkSerializer.cpp @@ -11,7 +11,7 @@ #include "../SignEntity.h" #include "../NoteEntity.h" #include "../JukeboxEntity.h" -#include "../Item.h" +#include "../ItemGrid.h" #include "../StringCompression.h" #include "../Entity.h" #include "../OSSupport/MakeDir.h" @@ -74,6 +74,24 @@ void cNBTChunkSerializer::AddItem(const cItem & a_Item, int a_Slot, const AStrin +void cNBTChunkSerializer::AddItemGrid(const cItemGrid & a_Grid, int a_BeginSlotNum) +{ + int NumSlots = a_Grid.GetNumSlots(); + for (int i = 0; i < NumSlots; i++) + { + const cItem & Item = a_Grid.GetItem(i); + if (Item.IsEmpty()) + { + continue; + } + AddItem(Item, i + a_BeginSlotNum); + } // for i - chest slots[] +} + + + + + void cNBTChunkSerializer::AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID) { m_Writer.AddInt ("x", a_Entity->GetPosX()); @@ -91,15 +109,7 @@ void cNBTChunkSerializer::AddChestEntity(cChestEntity * a_Entity) m_Writer.BeginCompound(""); AddBasicTileEntity(a_Entity, "Chest"); m_Writer.BeginList("Items", TAG_Compound); - for (int i = 0; i < cChestEntity::c_ChestHeight * cChestEntity::c_ChestWidth; i++) - { - const cItem * Item = a_Entity->GetSlot(i); - if ((Item == NULL) || Item->IsEmpty()) - { - continue; - } - AddItem(*Item, i); - } // for i - chest slots[] + AddItemGrid(a_Entity->GetContents()); m_Writer.EndList(); m_Writer.EndCompound(); } diff --git a/source/WorldStorage/NBTChunkSerializer.h b/source/WorldStorage/NBTChunkSerializer.h index 78847dbc0..5c59ca490 100644 --- a/source/WorldStorage/NBTChunkSerializer.h +++ b/source/WorldStorage/NBTChunkSerializer.h @@ -31,6 +31,8 @@ class cMinecartWithChest; class cMinecartWithFurnace; class cMonster; class cPickup; +class cItemGrid; + @@ -71,6 +73,9 @@ protected: /// Writes an item into the writer, if slot >= 0, adds the Slot tag. The compound is named as requested. void AddItem(const cItem & a_Item, int a_Slot, const AString & a_CompoundName = ""); + /// Writes an item grid into the writer; begins the stored slot numbers with a_BeginSlotNum + 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); -- cgit v1.2.3