示例#1
0
void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
    std::auto_ptr<cArrowEntity> Arrow(new cArrowEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0)));
    if (!LoadProjectileBaseFromNBT(*Arrow.get(), a_NBT, a_TagIdx))
    {
        return;
    }

    // Load pickup state:
    int PickupIdx = a_NBT.FindChildByName(a_TagIdx, "pickup");
    if (PickupIdx > 0)
    {
        Arrow->SetPickupState((cArrowEntity::ePickupState)a_NBT.GetByte(PickupIdx));
    }
    else
    {
        // Try the older "player" tag:
        int PlayerIdx = a_NBT.FindChildByName(a_TagIdx, "player");
        if (PlayerIdx > 0)
        {
            Arrow->SetPickupState((a_NBT.GetByte(PlayerIdx) == 0) ? cArrowEntity::psNoPickup : cArrowEntity::psInSurvivalOrCreative);
        }
    }

    // Load damage:
    int DamageIdx = a_NBT.FindChildByName(a_TagIdx, "damage");
    if (DamageIdx > 0)
    {
        Arrow->SetDamageCoeff(a_NBT.GetDouble(DamageIdx));
    }

    // Store the new arrow in the entities list:
    a_Entities.push_back(Arrow.release());
}
示例#2
0
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?
}