parent
f5aaf52210
commit
3136fc6246
@ -68,6 +68,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
if (!IsTame() && !IsAngry())
|
if (!IsTame() && !IsAngry())
|
||||||
{
|
{
|
||||||
|
// If the player is holding a bone, try to tame the wolf:
|
||||||
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
|
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
|
||||||
{
|
{
|
||||||
if (!a_Player.IsGameModeCreative())
|
if (!a_Player.IsGameModeCreative())
|
||||||
@ -77,14 +78,16 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
|
|
||||||
if (m_World->GetTickRandomNumber(7) == 0)
|
if (m_World->GetTickRandomNumber(7) == 0)
|
||||||
{
|
{
|
||||||
|
// Taming succeeded
|
||||||
SetMaxHealth(20);
|
SetMaxHealth(20);
|
||||||
SetIsTame(true);
|
SetIsTame(true);
|
||||||
SetOwner(a_Player.GetName());
|
SetOwner(a_Player.GetName(), a_Player.GetUUID());
|
||||||
m_World->BroadcastEntityStatus(*this, esWolfTamed);
|
m_World->BroadcastEntityStatus(*this, esWolfTamed);
|
||||||
m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
|
m_World->BroadcastParticleEffect("heart", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Taming failed
|
||||||
m_World->BroadcastEntityStatus(*this, esWolfTaming);
|
m_World->BroadcastEntityStatus(*this, esWolfTaming);
|
||||||
m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
|
m_World->BroadcastParticleEffect("smoke", (float) GetPosX(), (float) GetPosY(), (float) GetPosZ(), 0, 0, 0, 0, 5);
|
||||||
}
|
}
|
||||||
@ -92,6 +95,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
}
|
}
|
||||||
else if (IsTame())
|
else if (IsTame())
|
||||||
{
|
{
|
||||||
|
// Feed the wolf, restoring its health, or dye its collar:
|
||||||
switch (a_Player.GetEquippedItem().m_ItemType)
|
switch (a_Player.GetEquippedItem().m_ItemType)
|
||||||
{
|
{
|
||||||
case E_ITEM_RAW_BEEF:
|
case E_ITEM_RAW_BEEF:
|
||||||
|
@ -29,7 +29,8 @@ public:
|
|||||||
bool IsTame (void) const { return m_IsTame; }
|
bool IsTame (void) const { return m_IsTame; }
|
||||||
bool IsBegging (void) const { return m_IsBegging; }
|
bool IsBegging (void) const { return m_IsBegging; }
|
||||||
bool IsAngry (void) const { return m_IsAngry; }
|
bool IsAngry (void) const { return m_IsAngry; }
|
||||||
AString GetOwner (void) const { return m_OwnerName; }
|
AString GetOwnerName (void) const { return m_OwnerName; }
|
||||||
|
AString GetOwnerUUID (void) const { return m_OwnerUUID; }
|
||||||
int GetCollarColor(void) const { return m_CollarColor; }
|
int GetCollarColor(void) const { return m_CollarColor; }
|
||||||
|
|
||||||
// Set functions
|
// Set functions
|
||||||
@ -37,8 +38,12 @@ public:
|
|||||||
void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; }
|
void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; }
|
||||||
void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; }
|
void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; }
|
||||||
void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; }
|
void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; }
|
||||||
void SetOwner (const AString & a_NewOwner) { m_OwnerName = a_NewOwner; }
|
|
||||||
void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; }
|
void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; }
|
||||||
|
void SetOwner (const AString & a_NewOwnerName, const AString & a_NewOwnerUUID)
|
||||||
|
{
|
||||||
|
m_OwnerName = a_NewOwnerName;
|
||||||
|
m_OwnerUUID = a_NewOwnerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -47,6 +52,7 @@ protected:
|
|||||||
bool m_IsBegging;
|
bool m_IsBegging;
|
||||||
bool m_IsAngry;
|
bool m_IsAngry;
|
||||||
AString m_OwnerName;
|
AString m_OwnerName;
|
||||||
|
AString m_OwnerUUID;
|
||||||
int m_CollarColor;
|
int m_CollarColor;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -569,10 +569,12 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
}
|
}
|
||||||
case cMonster::mtWolf:
|
case cMonster::mtWolf:
|
||||||
{
|
{
|
||||||
m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner());
|
const cWolf & Wolf = *((cWolf *)a_Monster);
|
||||||
m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0));
|
m_Writer.AddString("Owner", Wolf.GetOwnerName());
|
||||||
m_Writer.AddByte("Angry", (((const cWolf *)a_Monster)->IsAngry() ? 1 : 0));
|
m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
|
||||||
m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor());
|
m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
|
||||||
|
m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
|
||||||
|
m_Writer.AddInt("CollarColor", Wolf.GetCollarColor());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case cMonster::mtZombie:
|
case cMonster::mtZombie:
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "../ItemGrid.h"
|
#include "../ItemGrid.h"
|
||||||
#include "../StringCompression.h"
|
#include "../StringCompression.h"
|
||||||
#include "../SetChunkData.h"
|
#include "../SetChunkData.h"
|
||||||
|
#include "../Root.h"
|
||||||
|
|
||||||
#include "../BlockEntities/BeaconEntity.h"
|
#include "../BlockEntities/BeaconEntity.h"
|
||||||
#include "../BlockEntities/ChestEntity.h"
|
#include "../BlockEntities/ChestEntity.h"
|
||||||
@ -49,6 +50,8 @@
|
|||||||
#include "../Entities/HangingEntity.h"
|
#include "../Entities/HangingEntity.h"
|
||||||
#include "../Entities/ItemFrame.h"
|
#include "../Entities/ItemFrame.h"
|
||||||
|
|
||||||
|
#include "../Protocol/MojangAPI.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2411,16 +2414,9 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
|
|
||||||
if (OwnerIdx > 0)
|
LoadWolfOwner(*Monster.get(), a_NBT, a_TagIdx);
|
||||||
{
|
|
||||||
AString OwnerName = a_NBT.GetString(OwnerIdx);
|
|
||||||
if (OwnerName != "")
|
|
||||||
{
|
|
||||||
Monster->SetOwner(OwnerName);
|
|
||||||
Monster->SetIsTame(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
|
int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
|
||||||
if (SittingIdx > 0)
|
if (SittingIdx > 0)
|
||||||
{
|
{
|
||||||
@ -2492,6 +2488,59 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx)
|
||||||
|
{
|
||||||
|
// Load the owner information. OwnerUUID or Owner may be specified, possibly both:
|
||||||
|
AString OwnerUUID, OwnerName;
|
||||||
|
int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
|
||||||
|
if (OwnerUUIDIdx > 0)
|
||||||
|
{
|
||||||
|
OwnerUUID = cMojangAPI::MakeUUIDShort(a_NBT.GetString(OwnerUUIDIdx));
|
||||||
|
}
|
||||||
|
int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
|
||||||
|
if (OwnerIdx > 0)
|
||||||
|
{
|
||||||
|
OwnerName = a_NBT.GetString(OwnerIdx);
|
||||||
|
}
|
||||||
|
if (OwnerName.empty() && OwnerUUID.empty())
|
||||||
|
{
|
||||||
|
// There is no owner, bail out:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert name to UUID, if needed:
|
||||||
|
if (OwnerUUID.empty())
|
||||||
|
{
|
||||||
|
// This wolf has only playername stored (pre-1.7.6), look up the UUID
|
||||||
|
// The lookup is blocking, but we're running in a separate thread, so it's ok
|
||||||
|
OwnerUUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(OwnerName);
|
||||||
|
if (OwnerUUID.empty())
|
||||||
|
{
|
||||||
|
// Not a known player, un-tame the wolf by bailing out
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert UUID to name, if needed:
|
||||||
|
if (OwnerName.empty())
|
||||||
|
{
|
||||||
|
// The lookup is blocking, but we're running in a separate thread, so it's ok
|
||||||
|
OwnerName = cRoot::Get()->GetMojangAPI().GetPlayerNameFromUUID(OwnerUUID);
|
||||||
|
if (OwnerName.empty())
|
||||||
|
{
|
||||||
|
// Not a known player, un-tame the wolf by bailing out
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a_Wolf.SetOwner(OwnerName, OwnerUUID);
|
||||||
|
a_Wolf.SetIsTame(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
|
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
|
||||||
{
|
{
|
||||||
double Pos[3];
|
double Pos[3];
|
||||||
|
@ -21,6 +21,7 @@ class cItemGrid;
|
|||||||
|
|
||||||
class cProjectileEntity;
|
class cProjectileEntity;
|
||||||
class cHangingEntity;
|
class cHangingEntity;
|
||||||
|
class cWolf;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -201,6 +202,9 @@ protected:
|
|||||||
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
|
|
||||||
|
/** Loads the wolf's owner information from the NBT into the specified wolf entity. */
|
||||||
|
void LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
|
|
||||||
/// Loads entity common data from the NBT compound; returns true if successful
|
/// Loads entity common data from the NBT compound; returns true if successful
|
||||||
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
|
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user