当前位置: 首页>>代码示例>>C++>>正文


C++ cParsedNBT::GetType方法代码示例

本文整理汇总了C++中cParsedNBT::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ cParsedNBT::GetType方法的具体用法?C++ cParsedNBT::GetType怎么用?C++ cParsedNBT::GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cParsedNBT的用法示例。


在下文中一共展示了cParsedNBT::GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadMinecartCFromNBT

void cWSSAnvil::LoadMinecartCFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
    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<cMinecartWithChest> 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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:27,代码来源:WSSAnvil.cpp

示例2: ParseFromNBT

void cEnchantments::ParseFromNBT(const cParsedNBT & a_NBT, int a_EnchListTagIdx)
{
	// Read the enchantments from the specified NBT list tag (ench or StoredEnchantments)

	// Verify that the tag is a list:
	if (a_NBT.GetType(a_EnchListTagIdx) != TAG_List)
	{
		LOGWARNING("%s: Invalid EnchListTag type: exp %d, got %d. Enchantments not parsed",
			__FUNCTION__, TAG_List, a_NBT.GetType(a_EnchListTagIdx)
		);
		ASSERT(!"Bad EnchListTag type");
		return;
	}
	
	// Verify that the list is of Compounds:
	if (a_NBT.GetChildrenType(a_EnchListTagIdx) != TAG_Compound)
	{
		LOGWARNING("%s: Invalid NBT list children type: exp %d, got %d. Enchantments not parsed",
			__FUNCTION__, TAG_Compound, a_NBT.GetChildrenType(a_EnchListTagIdx)
		);
		ASSERT(!"Bad EnchListTag children type");
		return;
	}
	
	Clear();
	
	// Iterate over all the compound children, parse an enchantment from each:
	for (int tag = a_NBT.GetFirstChild(a_EnchListTagIdx); tag >= 0; tag = a_NBT.GetNextSibling(tag))
	{
		// tag is the compound inside the "ench" list tag
		ASSERT(a_NBT.GetType(tag) == TAG_Compound);
		
		// Search for the id and lvl tags' values:
		int id = -1, lvl = -1;
		for (int ch = a_NBT.GetFirstChild(tag); ch >= 0; ch = a_NBT.GetNextSibling(ch))
		{
			if (a_NBT.GetType(ch) != TAG_Short)
			{
				continue;
			}
			if (a_NBT.GetName(ch) == "id")
			{
				id = a_NBT.GetShort(ch);
			}
			else if (a_NBT.GetName(ch) == "lvl")
			{
				lvl = a_NBT.GetShort(ch);
			}
		}  // for ch - children of the compound tag
		
		if ((id == -1) || (lvl <= 0))
		{
			// Failed to parse either the id or the lvl, skip this compound
			continue;
		}
		
		// Store the enchantment:
		m_Enchantments[id] = lvl;
	}  // for tag - children of the ench list tag
}
开发者ID:Hillvith,项目名称:MCServer,代码行数:60,代码来源:Enchantments.cpp

示例3: LoadBlockEntitiesFromNBT

void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas)
{
    if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List))
    {
        return;
    }

    for (int Child = a_NBT.GetFirstChild(a_TagIdx); Child != -1; Child = a_NBT.GetNextSibling(Child))
    {
        if (a_NBT.GetType(Child) != TAG_Compound)
        {
            continue;
        }
        int sID = a_NBT.FindChildByName(Child, "id");
        if (sID < 0)
        {
            continue;
        }
        if (strncmp(a_NBT.GetData(sID), "Chest", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadChestFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "Dropper", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadDropperFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "Furnace", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child, a_BlockTypes, a_BlockMetas);
        }
        else if (strncmp(a_NBT.GetData(sID), "Hopper", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadHopperFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "Music", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadNoteFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "RecordPlayer", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadJukeboxFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "Sign", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadSignFromNBT(a_BlockEntities, a_NBT, Child);
        }
        else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0)
        {
            LoadDispenserFromNBT(a_BlockEntities, a_NBT, Child);
        }
        // TODO: Other block entities
    }  // for Child - tag children
}
开发者ID:stpinker,项目名称:MCServer,代码行数:53,代码来源:WSSAnvil.cpp

示例4: CopyNBTData

void cWSSAnvil::CopyNBTData(const cParsedNBT & a_NBT, int a_Tag, const AString & a_ChildName, char * a_Destination, int a_Length)
{
    int Child = a_NBT.FindChildByName(a_Tag, a_ChildName);
    if ((Child >= 0) && (a_NBT.GetType(Child) == TAG_ByteArray) && (a_NBT.GetDataLength(Child) == a_Length))
    {
        memcpy(a_Destination, a_NBT.GetData(Child), a_Length);
    }
}
开发者ID:stpinker,项目名称:MCServer,代码行数:8,代码来源:WSSAnvil.cpp

示例5: LoadHopperFromNBT

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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:17,代码来源:WSSAnvil.cpp

示例6: LoadItemFromNBT

bool cWSSAnvil::LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_TagIdx)
{
    int ID = a_NBT.FindChildByName(a_TagIdx, "id");
    if ((ID < 0) || (a_NBT.GetType(ID) != TAG_Short))
    {
        return false;
    }
    a_Item.m_ItemType = (ENUM_ITEM_ID)(a_NBT.GetShort(ID));

    int Damage = a_NBT.FindChildByName(a_TagIdx, "Damage");
    if ((Damage < 0) || (a_NBT.GetType(Damage) != TAG_Short))
    {
        return false;
    }
    a_Item.m_ItemDamage = a_NBT.GetShort(Damage);

    int Count = a_NBT.FindChildByName(a_TagIdx, "Count");
    if ((Count < 0) || (a_NBT.GetType(Count) != TAG_Byte))
    {
        return false;
    }
    a_Item.m_ItemCount = a_NBT.GetByte(Count);

    // Find the "tag" tag, used for enchantments and other extra data
    int TagTag = a_NBT.FindChildByName(a_TagIdx, "tag");
    if (TagTag <= 0)
    {
        // No extra data
        return true;
    }

    // Load enchantments:
    const char * EnchName = (a_Item.m_ItemType == E_ITEM_BOOK) ? "StoredEnchantments" : "ench";
    int EnchTag = a_NBT.FindChildByName(TagTag, EnchName);
    if (EnchTag > 0)
    {
        a_Item.m_Enchantments.ParseFromNBT(a_NBT, EnchTag);
    }

    return true;
}
开发者ID:stpinker,项目名称:MCServer,代码行数:41,代码来源:WSSAnvil.cpp

示例7: LoadEntitiesFromNBT

void cWSSAnvil::LoadEntitiesFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
    if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List))
    {
        return;
    }

    for (int Child = a_NBT.GetFirstChild(a_TagIdx); Child != -1; Child = a_NBT.GetNextSibling(Child))
    {
        if (a_NBT.GetType(Child) != TAG_Compound)
        {
            continue;
        }
        int sID = a_NBT.FindChildByName(Child, "id");
        if (sID < 0)
        {
            continue;
        }
        LoadEntityFromNBT(a_Entities, a_NBT, Child, a_NBT.GetData(sID), a_NBT.GetDataLength(sID));
    }  // for Child - a_NBT[]
}
开发者ID:stpinker,项目名称:MCServer,代码行数:21,代码来源:WSSAnvil.cpp

示例8: GetBlockEntityNBTPos

bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z)
{
    int x = a_NBT.FindChildByName(a_TagIdx, "x");
    if ((x < 0) || (a_NBT.GetType(x) != TAG_Int))
    {
        return false;
    }
    int y = a_NBT.FindChildByName(a_TagIdx, "y");
    if ((y < 0) || (a_NBT.GetType(y) != TAG_Int))
    {
        return false;
    }
    int z = a_NBT.FindChildByName(a_TagIdx, "z");
    if ((z < 0) || (a_NBT.GetType(z) != TAG_Int))
    {
        return false;
    }
    a_X = a_NBT.GetInt(x);
    a_Y = a_NBT.GetInt(y);
    a_Z = a_NBT.GetInt(z);
    return true;
}
开发者ID:stpinker,项目名称:MCServer,代码行数:22,代码来源:WSSAnvil.cpp

示例9: LoadDoublesListFromNBT

bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx)
{
    if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Double))
    {
        return false;
    }
    int idx = 0;
    for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumDoubles); Tag = a_NBT.GetNextSibling(Tag), ++idx)
    {
        a_Doubles[idx] = a_NBT.GetDouble(Tag);
    }  // for Tag - PosTag[]
    return (idx == a_NumDoubles);  // Did we read enough doubles?
}
开发者ID:stpinker,项目名称:MCServer,代码行数:13,代码来源:WSSAnvil.cpp

示例10: LoadJukeboxFromNBT

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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:16,代码来源:WSSAnvil.cpp

示例11: LoadNoteFromNBT

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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:16,代码来源:WSSAnvil.cpp

示例12: LoadPickupFromNBT

void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
    int ItemTag = a_NBT.FindChildByName(a_TagIdx, "Item");
    if ((ItemTag < 0) || (a_NBT.GetType(ItemTag) != TAG_Compound))
    {
        return;
    }
    cItem Item;
    if (!LoadItemFromNBT(Item, a_NBT, ItemTag))
    {
        return;
    }
    std::auto_ptr<cPickup> Pickup(new cPickup(0, 0, 0, Item, false)); // Pickup delay doesn't matter, just say false
    if (!LoadEntityBaseFromNBT(*Pickup.get(), a_NBT, a_TagIdx))
    {
        return;
    }
    a_Entities.push_back(Pickup.release());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:19,代码来源:WSSAnvil.cpp

示例13: LoadItemGridFromNBT

void cWSSAnvil::LoadItemGridFromNBT(cItemGrid & a_ItemGrid, const cParsedNBT & a_NBT, int a_ItemsTagIdx, int a_SlotOffset)
{
    int NumSlots = a_ItemGrid.GetNumSlots();
    for (int Child = a_NBT.GetFirstChild(a_ItemsTagIdx); Child != -1; Child = a_NBT.GetNextSibling(Child))
    {
        int SlotTag = a_NBT.FindChildByName(Child, "Slot");
        if ((SlotTag < 0) || (a_NBT.GetType(SlotTag) != TAG_Byte))
        {
            continue;
        }
        int SlotNum = (int)(a_NBT.GetByte(SlotTag)) - a_SlotOffset;
        if ((SlotNum < 0) || (SlotNum >= NumSlots))
        {
            // SlotNum outside of the range
            continue;
        }
        cItem Item;
        if (LoadItemFromNBT(Item, a_NBT, Child))
        {
            a_ItemGrid.SetSlot(SlotNum, Item);
        }
    }  // for itr - ItemDefs[]
}
开发者ID:stpinker,项目名称:MCServer,代码行数:23,代码来源:WSSAnvil.cpp

示例14: LoadSignFromNBT

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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:36,代码来源:WSSAnvil.cpp

示例15: LoadFurnaceFromNBT

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());
}
开发者ID:stpinker,项目名称:MCServer,代码行数:62,代码来源:WSSAnvil.cpp


注:本文中的cParsedNBT::GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。