void cWSSAnvil::LoadNoteFromNBT(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<cNoteEntity> Note(new cNoteEntity(x, y, z, m_World)); int note = a_NBT.FindChildByName(a_TagIdx, "note"); if (note >= 0) { Note->SetPitch(a_NBT.GetByte(note)); } a_BlockEntities.push_back(Note.release()); }
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)) { return; } std::auto_ptr<cJukeboxEntity> Jukebox(new cJukeboxEntity(x, y, z, m_World)); int Record = a_NBT.FindChildByName(a_TagIdx, "Record"); if (Record >= 0) { Jukebox->SetRecord(a_NBT.GetInt(Record)); } a_BlockEntities.push_back(Jukebox.release()); }
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; if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) { return; } int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) { 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()); }
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; if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) { 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) { Sign->SetLine(0, a_NBT.GetString(currentLine)); } 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()); }
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World) { // Load chests: Json::Value AllChests = a_Value.get("Chests", Json::nullValue); if (!AllChests.empty()) { for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr ) { std::auto_ptr<cChestEntity> ChestEntity(new cChestEntity(0, 0, 0, a_World)); if (!ChestEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING CHEST FROM JSON!" ); } else { a_BlockEntities.push_back(ChestEntity.release()); } } // for itr - AllChests[] } // Load dispensers: Json::Value AllDispensers = a_Value.get("Dispensers", Json::nullValue); for (Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr) { std::auto_ptr<cDispenserEntity> DispenserEntity(new cDispenserEntity(0, 0, 0, a_World)); if (!DispenserEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING DISPENSER FROM JSON!" ); } else { a_BlockEntities.push_back(DispenserEntity.release()); } } // for itr - AllDispensers[] // Load Flowerpots: Json::Value AllFlowerPots = a_Value.get("FlowerPots", Json::nullValue); for (Json::Value::iterator itr = AllFlowerPots.begin(); itr != AllFlowerPots.end(); ++itr) { std::auto_ptr<cFlowerPotEntity> FlowerPotEntity(new cFlowerPotEntity(0, 0, 0, a_World)); if (!FlowerPotEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING FLOWERPOT FROM JSON!" ); } else { a_BlockEntities.push_back(FlowerPotEntity.release()); } } // for itr - AllFlowerPots[] // Load furnaces: Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue); for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr) { // TODO: The block type and meta aren't correct, there's no way to get them here std::auto_ptr<cFurnaceEntity> FurnaceEntity(new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World)); if (!FurnaceEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING FURNACE FROM JSON!" ); } else { a_BlockEntities.push_back(FurnaceEntity.release()); } } // for itr - AllFurnaces[] // Load signs: Json::Value AllSigns = a_Value.get("Signs", Json::nullValue); for (Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr) { std::auto_ptr<cSignEntity> SignEntity(new cSignEntity(E_BLOCK_SIGN_POST, 0, 0, 0, a_World)); if (!SignEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING SIGN FROM JSON!"); } else { a_BlockEntities.push_back(SignEntity.release()); } } // for itr - AllSigns[] // Load note blocks: Json::Value AllNotes = a_Value.get("Notes", Json::nullValue); for (Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr) { std::auto_ptr<cNoteEntity> NoteEntity(new cNoteEntity(0, 0, 0, a_World)); if (!NoteEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING NOTE BLOCK FROM JSON!" ); } else { a_BlockEntities.push_back(NoteEntity.release()); } } // for itr - AllNotes[] // Load jukeboxes: Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue); for (Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr) { std::auto_ptr<cJukeboxEntity> JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World)); if (!JukeboxEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING JUKEBOX FROM JSON!" ); } else { a_BlockEntities.push_back(JukeboxEntity.release()); } } // for itr - AllJukeboxes[] // Load command blocks: Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue); for (Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr) { std::auto_ptr<cCommandBlockEntity> CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World)); if (!CommandBlockEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING COMMAND BLOCK FROM JSON!" ); } else { a_BlockEntities.push_back(CommandBlockEntity.release()); } } // for itr - AllCommandBlocks[] // Load mob heads: Json::Value AllMobHeads = a_Value.get("MobHeads", Json::nullValue); for (Json::Value::iterator itr = AllMobHeads.begin(); itr != AllMobHeads.end(); ++itr) { std::auto_ptr<cMobHeadEntity> MobHeadEntity(new cMobHeadEntity(0, 0, 0, a_World)); if (!MobHeadEntity->LoadFromJson(*itr)) { LOGWARNING("ERROR READING MOB HEAD FROM JSON!" ); } else { a_BlockEntities.push_back(MobHeadEntity.release()); } } // for itr - AllMobHeads[] }
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World) { // Load chests Json::Value AllChests = a_Value.get("Chests", Json::nullValue); if (!AllChests.empty()) { for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr ) { Json::Value & Chest = *itr; cChestEntity * ChestEntity = new cChestEntity(0,0,0, a_World); if (!ChestEntity->LoadFromJson( Chest ) ) { LOGERROR("ERROR READING CHEST FROM JSON!" ); delete ChestEntity; } else { a_BlockEntities.push_back( ChestEntity ); } } // for itr - AllChests[] } // Load dispensers Json::Value AllDispensers = a_Value.get("Dispensers", Json::nullValue); if( !AllDispensers.empty() ) { for( Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr ) { Json::Value & Dispenser = *itr; cDispenserEntity * DispenserEntity = new cDispenserEntity(0,0,0, a_World); if( !DispenserEntity->LoadFromJson( Dispenser ) ) { LOGERROR("ERROR READING DISPENSER FROM JSON!" ); delete DispenserEntity; } else { a_BlockEntities.push_back( DispenserEntity ); } } // for itr - AllDispensers[] } // Load furnaces Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue); if( !AllFurnaces.empty() ) { for( Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr ) { Json::Value & Furnace = *itr; // TODO: The block type and meta aren't correct, there's no way to get them here cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World); if (!FurnaceEntity->LoadFromJson(Furnace)) { LOGERROR("ERROR READING FURNACE FROM JSON!" ); delete FurnaceEntity; } else { a_BlockEntities.push_back(FurnaceEntity); } } // for itr - AllFurnaces[] } // Load signs Json::Value AllSigns = a_Value.get("Signs", Json::nullValue); if( !AllSigns.empty() ) { for( Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr ) { Json::Value & Sign = *itr; cSignEntity * SignEntity = new cSignEntity( E_BLOCK_SIGN_POST, 0,0,0, a_World); if ( !SignEntity->LoadFromJson( Sign ) ) { LOGERROR("ERROR READING SIGN FROM JSON!" ); delete SignEntity; } else { a_BlockEntities.push_back( SignEntity ); } } // for itr - AllSigns[] } // Load note blocks Json::Value AllNotes = a_Value.get("Notes", Json::nullValue); if( !AllNotes.empty() ) { for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr ) { Json::Value & Note = *itr; cNoteEntity * NoteEntity = new cNoteEntity(0, 0, 0, a_World); if ( !NoteEntity->LoadFromJson( Note ) ) { LOGERROR("ERROR READING NOTE BLOCK FROM JSON!" ); delete NoteEntity; } else { a_BlockEntities.push_back( NoteEntity ); } } // for itr - AllNotes[] } // Load jukeboxes Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue); if( !AllJukeboxes.empty() ) { for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr ) { Json::Value & Jukebox = *itr; cJukeboxEntity * JukeboxEntity = new cJukeboxEntity(0, 0, 0, a_World); if ( !JukeboxEntity->LoadFromJson( Jukebox ) ) { LOGERROR("ERROR READING JUKEBOX FROM JSON!" ); delete JukeboxEntity; } else { a_BlockEntities.push_back( JukeboxEntity ); } } // for itr - AllJukeboxes[] } }
void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) { return; } int Items = a_NBT.FindChildByName(a_TagIdx, "Items"); if ((Items < 0) || (a_NBT.GetType(Items) != TAG_List)) { return; // Make it an empty furnace - the chunk loader will provide an empty cFurnaceEntity for this } // Convert coords to relative: int RelX = x; int RelZ = z; int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative(RelX, y, RelZ, ChunkX, ChunkZ); // Create the furnace entity, with proper BlockType and BlockMeta info: BLOCKTYPE BlockType = cChunkDef::GetBlock(a_BlockTypes, RelX, y, RelZ); NIBBLETYPE BlockMeta = cChunkDef::GetNibble(a_BlockMetas, RelX, y, RelZ); std::auto_ptr<cFurnaceEntity> Furnace(new cFurnaceEntity(x, y, z, BlockType, BlockMeta, m_World)); // Load slots: 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)) { Furnace->SetSlot(a_NBT.GetByte(Slot), Item); } } // for itr - ItemDefs[] // Load burn time: int BurnTime = a_NBT.FindChildByName(a_TagIdx, "BurnTime"); if (BurnTime >= 0) { Int16 bt = a_NBT.GetShort(BurnTime); // Anvil doesn't store the time that the fuel can burn. We simply "reset" the current value to be the 100% Furnace->SetBurnTimes(bt, 0); } // Load cook time: int CookTime = a_NBT.FindChildByName(a_TagIdx, "CookTime"); if (CookTime >= 0) { Int16 ct = a_NBT.GetShort(CookTime); // Anvil doesn't store the time that an item takes to cook. We simply use the default - 10 seconds (200 ticks) Furnace->SetCookTimes(200, ct); } // Restart cooking: Furnace->ContinueCooking(); a_BlockEntities.push_back(Furnace.release()); }