From e694893edf835d426eba8e1da042f7a65ec06c1e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 9 Mar 2013 20:08:39 +0000 Subject: Minecarts get saved into Anvil. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1263 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Minecart.cpp | 2 +- source/Minecart.h | 6 ++--- source/WorldStorage/NBTChunkSerializer.cpp | 8 +++--- source/WorldStorage/WSSAnvil.cpp | 42 +++++++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/Minecart.cpp b/source/Minecart.cpp index 2606e7774..359ea5402 100644 --- a/source/Minecart.cpp +++ b/source/Minecart.cpp @@ -115,7 +115,7 @@ cMinecartWithChest::cMinecartWithChest(double a_X, double a_Y, double a_Z) : -void cMinecartWithChest::SetItem(int a_Idx, const cItem & a_Item) +void cMinecartWithChest::SetSlot(int a_Idx, const cItem & a_Item) { ASSERT((a_Idx >= 0) && (a_Idx < ARRAYCOUNT(m_Items))); diff --git a/source/Minecart.h b/source/Minecart.h index 17c766fb8..d3ca22f4b 100644 --- a/source/Minecart.h +++ b/source/Minecart.h @@ -80,10 +80,10 @@ public: cMinecartWithChest(double a_X, double a_Y, double a_Z); - const cItem & GetItem(int a_Idx) const { return m_Items[a_Idx]; } - cItem & GetItem(int a_Idx) { return m_Items[a_Idx]; } + const cItem & GetSlot(int a_Idx) const { return m_Items[a_Idx]; } + cItem & GetSlot(int a_Idx) { return m_Items[a_Idx]; } - void SetItem(int a_Idx, const cItem & a_Item); + void SetSlot(int a_Idx, const cItem & a_Item); protected: diff --git a/source/WorldStorage/NBTChunkSerializer.cpp b/source/WorldStorage/NBTChunkSerializer.cpp index f41bd5e97..992fa7f69 100644 --- a/source/WorldStorage/NBTChunkSerializer.cpp +++ b/source/WorldStorage/NBTChunkSerializer.cpp @@ -231,9 +231,9 @@ void cNBTChunkSerializer::AddMinecartEntity(cMinecart * a_Minecart) const char * EntityClass = NULL; switch (a_Minecart->GetPayload()) { - case cMinecart::mpNone: EntityClass = "MinecarRideable"; break; - case cMinecart::mpChest: EntityClass = "MinecartChest"; break; - case cMinecart::mpFurnace: EntityClass = "MinecartFurnace"; break; + case cMinecart::mpNone: EntityClass = "MinecartRideable"; break; + case cMinecart::mpChest: EntityClass = "MinecartChest"; break; + case cMinecart::mpFurnace: EntityClass = "MinecartFurnace"; break; default: { ASSERT(!"Unhandled minecart payload type"); @@ -293,7 +293,7 @@ void cNBTChunkSerializer::AddMinecartChestContents(cMinecartWithChest * a_Mineca m_Writer.BeginList("Items", TAG_Compound); for (int i = 0; i < cMinecartWithChest::NumSlots; i++) { - const cItem & Item = a_Minecart->GetItem(i); + const cItem & Item = a_Minecart->GetSlot(i); if (Item.IsEmpty()) { continue; diff --git a/source/WorldStorage/WSSAnvil.cpp b/source/WorldStorage/WSSAnvil.cpp index de9a3c3ae..a7db674ff 100644 --- a/source/WorldStorage/WSSAnvil.cpp +++ b/source/WorldStorage/WSSAnvil.cpp @@ -861,7 +861,12 @@ void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedN void cWSSAnvil::LoadMinecartRFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - // TODO + std::auto_ptr Minecart(new cEmptyMinecart(0, 0, 0)); + if (!LoadEntityBaseFromNBT(*Minecart.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Minecart.release()); } @@ -870,7 +875,30 @@ void cWSSAnvil::LoadMinecartRFromNBT(cEntityList & a_Entities, const cParsedNBT void cWSSAnvil::LoadMinecartCFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - // TODO + int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); + if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) + { + return; // Make it an empty chest - the chunk loader will provide an empty cChestEntity for this + } + std::auto_ptr Minecart(new cMinecartWithChest(0, 0, 0)); + if (!LoadEntityBaseFromNBT(*Minecart.get(), a_NBT, a_TagIdx)) + { + return; + } + for (int Child = a_NBT.GetFirstChild(Items); Child != -1; Child = a_NBT.GetNextSibling(Child)) + { + int Slot = a_NBT.FindChildByName(Child, "Slot"); + if ((Slot < 0) || (a_NBT.GetType(Slot) != TAG_Byte)) + { + continue; + } + cItem Item; + if (LoadItemFromNBT(Item, a_NBT, Child)) + { + Minecart->SetSlot(a_NBT.GetByte(Slot), Item); + } + } // for itr - ItemDefs[] + a_Entities.push_back(Minecart.release()); } @@ -879,7 +907,15 @@ void cWSSAnvil::LoadMinecartCFromNBT(cEntityList & a_Entities, const cParsedNBT void cWSSAnvil::LoadMinecartFFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - // TODO + std::auto_ptr Minecart(new cMinecartWithFurnace(0, 0, 0)); + if (!LoadEntityBaseFromNBT(*Minecart.get(), a_NBT, a_TagIdx)) + { + return; + } + + // TODO: Load the Push and Fuel tags + + a_Entities.push_back(Minecart.release()); } -- cgit v1.2.3