summaryrefslogtreecommitdiffstats
path: root/source/cChestEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 17:01:45 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 17:01:45 +0100
commit51dc47bc70d66667ed1aee597d82dbdcfaf92fa1 (patch)
tree9e5fd39541516c0f8ced34b36f6e546bcd3886bb /source/cChestEntity.cpp
parentInitial cFile implementation (using stdio FILE) and test in cChunkMap (diff)
downloadcuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar.gz
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar.bz2
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar.lz
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar.xz
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.tar.zst
cuberite-51dc47bc70d66667ed1aee597d82dbdcfaf92fa1.zip
Diffstat (limited to 'source/cChestEntity.cpp')
-rw-r--r--source/cChestEntity.cpp46
1 files changed, 20 insertions, 26 deletions
diff --git a/source/cChestEntity.cpp b/source/cChestEntity.cpp
index 4df900327..b30800700 100644
--- a/source/cChestEntity.cpp
+++ b/source/cChestEntity.cpp
@@ -77,46 +77,40 @@ void cChestEntity::SetSlot( int a_Slot, cItem & a_Item )
}
}
-void cChestEntity::WriteToFile(FILE* a_File)
-{
- fwrite( &m_BlockType, sizeof( ENUM_BLOCK_ID ), 1, a_File );
- fwrite( &m_PosX, sizeof( int ), 1, a_File );
- fwrite( &m_PosY, sizeof( int ), 1, a_File );
- fwrite( &m_PosZ, sizeof( int ), 1, a_File );
- unsigned int NumSlots = c_ChestHeight*c_ChestWidth;
- fwrite( &NumSlots, sizeof(unsigned int), 1, a_File );
- for(unsigned int i = 0; i < NumSlots; i++)
- {
- cItem* Item = GetSlot( i );
- if( Item )
- {
- fwrite( &Item->m_ItemID, sizeof(Item->m_ItemID), 1, a_File );
- fwrite( &Item->m_ItemCount, sizeof(Item->m_ItemCount), 1, a_File );
- fwrite( &Item->m_ItemHealth, sizeof(Item->m_ItemHealth), 1, a_File );
- }
+
+
+
+#define READ(File, Var) \
+ if (File.Read(&Var, sizeof(Var)) != sizeof(Var)) \
+ { \
+ LOGERROR("ERROR READING cChestEntity %s FROM FILE (line %d)", #Var, __LINE__); \
+ return false; \
}
-}
-bool cChestEntity::LoadFromFile(FILE* a_File)
+bool cChestEntity::LoadFromFile(cFile & f)
{
- if( fread( &m_PosX, sizeof(int), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
- if( fread( &m_PosY, sizeof(int), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
- if( fread( &m_PosZ, sizeof(int), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
+ READ(f, m_PosX);
+ READ(f, m_PosY);
+ READ(f, m_PosZ);
unsigned int NumSlots = 0;
- if( fread( &NumSlots, sizeof(unsigned int), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
+ READ(f, NumSlots);
for(unsigned int i = 0; i < NumSlots; i++)
{
cItem Item;
- if( fread( &Item.m_ItemID, sizeof(Item.m_ItemID), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
- if( fread( &Item.m_ItemCount, sizeof(Item.m_ItemCount), 1, a_File) != 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
- if( fread( &Item.m_ItemHealth, sizeof(Item.m_ItemHealth), 1, a_File)!= 1 ) { LOGERROR("ERROR READING CHEST FROM FILE"); return false; }
+ READ(f, Item.m_ItemID);
+ READ(f, Item.m_ItemCount);
+ READ(f, Item.m_ItemHealth);
SetSlot( i, Item );
}
return true;
}
+
+
+
+
bool cChestEntity::LoadFromJson( const Json::Value& a_Value )
{
m_PosX = a_Value.get("x", 0).asInt();