1
0

Anvil: Arrow Tile tags are a short in Vanilla

This commit is contained in:
Howaner 2014-09-25 19:01:44 +02:00
parent 12621e3800
commit 7cdcf0a883
2 changed files with 24 additions and 7 deletions

View File

@ -637,9 +637,9 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
{ {
cArrowEntity * Arrow = (cArrowEntity *)a_Projectile; cArrowEntity * Arrow = (cArrowEntity *)a_Projectile;
m_Writer.AddInt("xTile", (Int16)Arrow->GetBlockHit().x); m_Writer.AddShort("xTile", (Int16)Arrow->GetBlockHit().x);
m_Writer.AddInt("yTile", (Int16)Arrow->GetBlockHit().y); m_Writer.AddShort("yTile", (Int16)Arrow->GetBlockHit().y);
m_Writer.AddInt("zTile", (Int16)Arrow->GetBlockHit().z); m_Writer.AddShort("zTile", (Int16)Arrow->GetBlockHit().z);
m_Writer.AddByte("pickup", Arrow->GetPickupState()); m_Writer.AddByte("pickup", Arrow->GetPickupState());
m_Writer.AddDouble("damage", Arrow->GetDamageCoeff()); m_Writer.AddDouble("damage", Arrow->GetDamageCoeff());
break; break;

View File

@ -1752,7 +1752,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
// Load pickup state: // Load pickup state:
int PickupIdx = a_NBT.FindChildByName(a_TagIdx, "pickup"); int PickupIdx = a_NBT.FindChildByName(a_TagIdx, "pickup");
if (PickupIdx > 0) if ((PickupIdx > 0) && (a_NBT.GetType(PickupIdx) == TAG_Byte))
{ {
Arrow->SetPickupState((cArrowEntity::ePickupState)a_NBT.GetByte(PickupIdx)); Arrow->SetPickupState((cArrowEntity::ePickupState)a_NBT.GetByte(PickupIdx));
} }
@ -1760,7 +1760,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
{ {
// Try the older "player" tag: // Try the older "player" tag:
int PlayerIdx = a_NBT.FindChildByName(a_TagIdx, "player"); int PlayerIdx = a_NBT.FindChildByName(a_TagIdx, "player");
if (PlayerIdx > 0) if ((PlayerIdx > 0) && (a_NBT.GetType(PlayerIdx) == TAG_Byte))
{ {
Arrow->SetPickupState((a_NBT.GetByte(PlayerIdx) == 0) ? cArrowEntity::psNoPickup : cArrowEntity::psInSurvivalOrCreative); Arrow->SetPickupState((a_NBT.GetByte(PlayerIdx) == 0) ? cArrowEntity::psNoPickup : cArrowEntity::psInSurvivalOrCreative);
} }
@ -1768,7 +1768,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
// Load damage: // Load damage:
int DamageIdx = a_NBT.FindChildByName(a_TagIdx, "damage"); int DamageIdx = a_NBT.FindChildByName(a_TagIdx, "damage");
if (DamageIdx > 0) if ((DamageIdx > 0) && (a_NBT.GetType(DamageIdx) == TAG_Double))
{ {
Arrow->SetDamageCoeff(a_NBT.GetDouble(DamageIdx)); Arrow->SetDamageCoeff(a_NBT.GetDouble(DamageIdx));
} }
@ -1779,7 +1779,24 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
int InBlockZIdx = a_NBT.FindChildByName(a_TagIdx, "zTile"); int InBlockZIdx = a_NBT.FindChildByName(a_TagIdx, "zTile");
if ((InBlockXIdx > 0) && (InBlockYIdx > 0) && (InBlockZIdx > 0)) if ((InBlockXIdx > 0) && (InBlockYIdx > 0) && (InBlockZIdx > 0))
{ {
Arrow->SetBlockHit(Vector3i(a_NBT.GetInt(InBlockXIdx), a_NBT.GetInt(InBlockYIdx), a_NBT.GetInt(InBlockZIdx))); if (a_NBT.GetType(InBlockXIdx) == a_NBT.GetType(InBlockYIdx) == a_NBT.GetType(InBlockZIdx))
{
switch (a_NBT.GetType(InBlockXIdx))
{
case TAG_Int:
{
// Old MCS code used this, keep reading it for compatibility reasons:
Arrow->SetBlockHit(Vector3i(a_NBT.GetInt(InBlockXIdx), a_NBT.GetInt(InBlockYIdx), a_NBT.GetInt(InBlockZIdx)));
break;
}
case TAG_Short:
{
// Vanilla uses this
Arrow->SetBlockHit(Vector3i((int)a_NBT.GetShort(InBlockXIdx), (int)a_NBT.GetShort(InBlockYIdx), (int)a_NBT.GetShort(InBlockZIdx)));
break;
}
}
}
} }
// Store the new arrow in the entities list: // Store the new arrow in the entities list: