Added beacon load/save.
This commit is contained in:
parent
66d34b83d2
commit
dcd226d904
@ -41,6 +41,9 @@ public:
|
|||||||
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
|
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||||
virtual void UsedBy(cPlayer * a_Player) override;
|
virtual void UsedBy(cPlayer * a_Player) override;
|
||||||
|
|
||||||
|
/** Modify the beacon level. (It is needed to load the beacon corectly) */
|
||||||
|
void SetBeaconLevel(char a_Level) { m_BeaconLevel = a_Level; }
|
||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
|
|
||||||
/** Is the beacon active? */
|
/** Is the beacon active? */
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "../StringCompression.h"
|
#include "../StringCompression.h"
|
||||||
#include "FastNBT.h"
|
#include "FastNBT.h"
|
||||||
|
|
||||||
|
#include "../BlockEntities/BeaconEntity.h"
|
||||||
#include "../BlockEntities/ChestEntity.h"
|
#include "../BlockEntities/ChestEntity.h"
|
||||||
#include "../BlockEntities/CommandBlockEntity.h"
|
#include "../BlockEntities/CommandBlockEntity.h"
|
||||||
#include "../BlockEntities/DispenserEntity.h"
|
#include "../BlockEntities/DispenserEntity.h"
|
||||||
@ -176,6 +177,23 @@ void cNBTChunkSerializer::AddBasicTileEntity(cBlockEntity * a_Entity, const char
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cNBTChunkSerializer::AddBeaconEntity(cBeaconEntity * a_Entity)
|
||||||
|
{
|
||||||
|
m_Writer.BeginCompound("");
|
||||||
|
AddBasicTileEntity(a_Entity, "Beacon");
|
||||||
|
m_Writer.AddInt("Levels", a_Entity->GetBeaconLevel());
|
||||||
|
m_Writer.AddInt("Primary", (int)a_Entity->GetPrimaryPotion());
|
||||||
|
m_Writer.AddInt("Secondary", (int)a_Entity->GetSecondaryPotion());
|
||||||
|
m_Writer.BeginList("Items", TAG_Compound);
|
||||||
|
AddItemGrid(a_Entity->GetContents());
|
||||||
|
m_Writer.EndList();
|
||||||
|
m_Writer.EndCompound();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cNBTChunkSerializer::AddChestEntity(cChestEntity * a_Entity, BLOCKTYPE a_ChestType)
|
void cNBTChunkSerializer::AddChestEntity(cChestEntity * a_Entity, BLOCKTYPE a_ChestType)
|
||||||
{
|
{
|
||||||
m_Writer.BeginCompound("");
|
m_Writer.BeginCompound("");
|
||||||
@ -825,6 +843,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity)
|
|||||||
// Add tile-entity into NBT:
|
// Add tile-entity into NBT:
|
||||||
switch (a_Entity->GetBlockType())
|
switch (a_Entity->GetBlockType())
|
||||||
{
|
{
|
||||||
|
case E_BLOCK_BEACON: AddBeaconEntity ((cBeaconEntity *) a_Entity); break;
|
||||||
case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity, a_Entity->GetBlockType()); break;
|
case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity, a_Entity->GetBlockType()); break;
|
||||||
case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *)a_Entity); break;
|
case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *)a_Entity); break;
|
||||||
case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
|
case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break;
|
||||||
|
@ -20,6 +20,7 @@ class cFastNBTWriter;
|
|||||||
class cEntity;
|
class cEntity;
|
||||||
class cBlockEntity;
|
class cBlockEntity;
|
||||||
class cBoat;
|
class cBoat;
|
||||||
|
class cBeaconEntity;
|
||||||
class cChestEntity;
|
class cChestEntity;
|
||||||
class cCommandBlockEntity;
|
class cCommandBlockEntity;
|
||||||
class cDispenserEntity;
|
class cDispenserEntity;
|
||||||
@ -93,6 +94,7 @@ protected:
|
|||||||
|
|
||||||
// Block entities:
|
// Block entities:
|
||||||
void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID);
|
void AddBasicTileEntity(cBlockEntity * a_Entity, const char * a_EntityTypeID);
|
||||||
|
void AddBeaconEntity (cBeaconEntity * a_Entity);
|
||||||
void AddChestEntity (cChestEntity * a_Entity, BLOCKTYPE a_ChestType);
|
void AddChestEntity (cChestEntity * a_Entity, BLOCKTYPE a_ChestType);
|
||||||
void AddDispenserEntity(cDispenserEntity * a_Entity);
|
void AddDispenserEntity(cDispenserEntity * a_Entity);
|
||||||
void AddDropperEntity (cDropperEntity * a_Entity);
|
void AddDropperEntity (cDropperEntity * a_Entity);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "../StringCompression.h"
|
#include "../StringCompression.h"
|
||||||
#include "../SetChunkData.h"
|
#include "../SetChunkData.h"
|
||||||
|
|
||||||
|
#include "../BlockEntities/BeaconEntity.h"
|
||||||
#include "../BlockEntities/ChestEntity.h"
|
#include "../BlockEntities/ChestEntity.h"
|
||||||
#include "../BlockEntities/CommandBlockEntity.h"
|
#include "../BlockEntities/CommandBlockEntity.h"
|
||||||
#include "../BlockEntities/DispenserEntity.h"
|
#include "../BlockEntities/DispenserEntity.h"
|
||||||
@ -582,7 +583,11 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp(a_NBT.GetData(sID), "Chest", a_NBT.GetDataLength(sID)) == 0)
|
if (strncmp(a_NBT.GetData(sID), "Beacon", a_NBT.GetDataLength(sID)) == 0)
|
||||||
|
{
|
||||||
|
LoadBeaconFromNBT(a_BlockEntities, a_NBT, Child);
|
||||||
|
}
|
||||||
|
else if (strncmp(a_NBT.GetData(sID), "Chest", a_NBT.GetDataLength(sID)) == 0)
|
||||||
{
|
{
|
||||||
LoadChestFromNBT(a_BlockEntities, a_NBT, Child, E_BLOCK_CHEST);
|
LoadChestFromNBT(a_BlockEntities, a_NBT, Child, E_BLOCK_CHEST);
|
||||||
}
|
}
|
||||||
@ -746,6 +751,49 @@ void cWSSAnvil::LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cWSSAnvil::LoadBeaconFromNBT(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))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::auto_ptr<cBeaconEntity> Beacon(new cBeaconEntity(x, y, z, m_World));
|
||||||
|
|
||||||
|
int CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Levels");
|
||||||
|
if (CurrentLine >= 0)
|
||||||
|
{
|
||||||
|
Beacon->SetBeaconLevel((char)a_NBT.GetInt(CurrentLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Primary");
|
||||||
|
if (CurrentLine >= 0)
|
||||||
|
{
|
||||||
|
Beacon->SelectPrimaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentLine = a_NBT.FindChildByName(a_TagIdx, "Secondary");
|
||||||
|
if (CurrentLine >= 0)
|
||||||
|
{
|
||||||
|
Beacon->SelectSecondaryPotion((cEntityEffect::eType)a_NBT.GetInt(CurrentLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are better than mojang, we load/save the beacon inventory!
|
||||||
|
int Items = a_NBT.FindChildByName(a_TagIdx, "Items");
|
||||||
|
if ((Items >= 0) && (a_NBT.GetType(Items) == TAG_List))
|
||||||
|
{
|
||||||
|
LoadItemGridFromNBT(Beacon->GetContents(), a_NBT, Items);
|
||||||
|
}
|
||||||
|
|
||||||
|
a_BlockEntities.push_back(Beacon.release());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWSSAnvil::LoadChestFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType)
|
void cWSSAnvil::LoadChestFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType)
|
||||||
{
|
{
|
||||||
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
|
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
|
||||||
|
@ -133,6 +133,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a_NBT, int a_ItemsTagIdx, int s_SlotOffset = 0);
|
void LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a_NBT, int a_ItemsTagIdx, int s_SlotOffset = 0);
|
||||||
|
|
||||||
|
void LoadBeaconFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType);
|
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE a_ChestType);
|
||||||
void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
|
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 LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
|
Loading…
Reference in New Issue
Block a user