Support ageable mobs
Move ageable stuff in Monster directly
This commit is contained in:
parent
9b3b047004
commit
53207d3f18
@ -101,6 +101,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A
|
|||||||
, m_TicksSinceLastDamaged(100)
|
, m_TicksSinceLastDamaged(100)
|
||||||
, m_BurnsInDaylight(false)
|
, m_BurnsInDaylight(false)
|
||||||
, m_RelativeWalkSpeed(1)
|
, m_RelativeWalkSpeed(1)
|
||||||
|
, m_Age(1)
|
||||||
{
|
{
|
||||||
if (!a_ConfigName.empty())
|
if (!a_ConfigName.empty())
|
||||||
{
|
{
|
||||||
|
@ -112,10 +112,14 @@ public:
|
|||||||
void SetRelativeWalkSpeed(double a_WalkSpeed) { m_RelativeWalkSpeed = a_WalkSpeed; } // tolua_export
|
void SetRelativeWalkSpeed(double a_WalkSpeed) { m_RelativeWalkSpeed = a_WalkSpeed; } // tolua_export
|
||||||
|
|
||||||
// Overridables to handle ageable mobs
|
// Overridables to handle ageable mobs
|
||||||
virtual bool IsBaby (void) const { return false; }
|
|
||||||
virtual bool IsTame (void) const { return false; }
|
virtual bool IsTame (void) const { return false; }
|
||||||
virtual bool IsSitting (void) const { return false; }
|
virtual bool IsSitting (void) const { return false; }
|
||||||
|
|
||||||
|
bool IsBaby (void) const { return m_Age < 0; }
|
||||||
|
char GetAge (void) const { return m_Age; }
|
||||||
|
void SetAge(char a_Age) { m_Age = a_Age; }
|
||||||
|
|
||||||
|
|
||||||
// tolua_begin
|
// tolua_begin
|
||||||
|
|
||||||
/** Returns true if the monster has a custom name. */
|
/** Returns true if the monster has a custom name. */
|
||||||
@ -270,6 +274,8 @@ protected:
|
|||||||
bool m_BurnsInDaylight;
|
bool m_BurnsInDaylight;
|
||||||
double m_RelativeWalkSpeed;
|
double m_RelativeWalkSpeed;
|
||||||
|
|
||||||
|
char m_Age;
|
||||||
|
|
||||||
/** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/
|
/** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/
|
||||||
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
|
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
|
||||||
|
|
||||||
|
@ -3388,10 +3388,6 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
{
|
{
|
||||||
Flags |= 0x08;
|
Flags |= 0x08;
|
||||||
}
|
}
|
||||||
if (Horse.IsBaby())
|
|
||||||
{
|
|
||||||
Flags |= 0x10;
|
|
||||||
}
|
|
||||||
if (Horse.IsEating())
|
if (Horse.IsEating())
|
||||||
{
|
{
|
||||||
Flags |= 0x20;
|
Flags |= 0x20;
|
||||||
@ -3415,6 +3411,9 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
a_Pkt.WriteBEInt32(Appearance);
|
a_Pkt.WriteBEInt32(Appearance);
|
||||||
a_Pkt.WriteBEUInt8(0x56); // Int at index 22
|
a_Pkt.WriteBEUInt8(0x56); // Int at index 22
|
||||||
a_Pkt.WriteBEInt32(Horse.GetHorseArmour());
|
a_Pkt.WriteBEInt32(Horse.GetHorseArmour());
|
||||||
|
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Horse.GetAge());
|
||||||
break;
|
break;
|
||||||
} // case mtHorse
|
} // case mtHorse
|
||||||
|
|
||||||
@ -3426,17 +3425,38 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
break;
|
break;
|
||||||
} // case mtMagmaCube
|
} // case mtMagmaCube
|
||||||
|
|
||||||
|
case mtOcelot:
|
||||||
|
{
|
||||||
|
auto & Ocelot = reinterpret_cast<const cOcelot &>(a_Mob);
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Ocelot.GetAge());
|
||||||
|
break;
|
||||||
|
} // case mtOcelot
|
||||||
|
|
||||||
case mtPig:
|
case mtPig:
|
||||||
{
|
{
|
||||||
auto & Pig = reinterpret_cast<const cPig &>(a_Mob);
|
auto & Pig = reinterpret_cast<const cPig &>(a_Mob);
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Pig.GetAge());
|
||||||
a_Pkt.WriteBEUInt8(0x10);
|
a_Pkt.WriteBEUInt8(0x10);
|
||||||
a_Pkt.WriteBEUInt8(Pig.IsSaddled() ? 1 : 0);
|
a_Pkt.WriteBEUInt8(Pig.IsSaddled() ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
} // case mtPig
|
} // case mtPig
|
||||||
|
|
||||||
|
case mtRabbit:
|
||||||
|
{
|
||||||
|
auto & Rabbit = reinterpret_cast<const cRabbit &>(a_Mob);
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Rabbit.GetAge());
|
||||||
|
break;
|
||||||
|
} // case mtRabbit
|
||||||
|
|
||||||
case mtSheep:
|
case mtSheep:
|
||||||
{
|
{
|
||||||
auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob);
|
auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob);
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Sheep.GetAge());
|
||||||
|
|
||||||
a_Pkt.WriteBEUInt8(0x10);
|
a_Pkt.WriteBEUInt8(0x10);
|
||||||
Byte SheepMetadata = 0;
|
Byte SheepMetadata = 0;
|
||||||
SheepMetadata = Sheep.GetFurColor();
|
SheepMetadata = Sheep.GetFurColor();
|
||||||
@ -3469,6 +3489,8 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
auto & Villager = reinterpret_cast<const cVillager &>(a_Mob);
|
auto & Villager = reinterpret_cast<const cVillager &>(a_Mob);
|
||||||
a_Pkt.WriteBEUInt8(0x50);
|
a_Pkt.WriteBEUInt8(0x50);
|
||||||
a_Pkt.WriteBEInt32(Villager.GetVilType());
|
a_Pkt.WriteBEInt32(Villager.GetVilType());
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Villager.GetAge());
|
||||||
break;
|
break;
|
||||||
} // case mtVillager
|
} // case mtVillager
|
||||||
|
|
||||||
@ -3515,6 +3537,9 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
a_Pkt.WriteBEUInt8(Wolf.IsBegging() ? 1 : 0);
|
a_Pkt.WriteBEUInt8(Wolf.IsBegging() ? 1 : 0);
|
||||||
a_Pkt.WriteBEUInt8(0x14);
|
a_Pkt.WriteBEUInt8(0x14);
|
||||||
a_Pkt.WriteBEUInt8(Wolf.GetCollarColor());
|
a_Pkt.WriteBEUInt8(Wolf.GetCollarColor());
|
||||||
|
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(Wolf.GetAge());
|
||||||
break;
|
break;
|
||||||
} // case mtWolf
|
} // case mtWolf
|
||||||
|
|
||||||
@ -3522,13 +3547,21 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
|
|||||||
{
|
{
|
||||||
auto & Zombie = reinterpret_cast<const cZombie &>(a_Mob);
|
auto & Zombie = reinterpret_cast<const cZombie &>(a_Mob);
|
||||||
a_Pkt.WriteBEUInt8(0x0c);
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
a_Pkt.WriteBEUInt8(Zombie.IsBaby() ? 1 : 0);
|
a_Pkt.WriteBEInt8(Zombie.IsBaby() ? 1 : -1);
|
||||||
a_Pkt.WriteBEUInt8(0x0d);
|
a_Pkt.WriteBEUInt8(0x0d);
|
||||||
a_Pkt.WriteBEUInt8(Zombie.IsVillagerZombie() ? 1 : 0);
|
a_Pkt.WriteBEUInt8(Zombie.IsVillagerZombie() ? 1 : 0);
|
||||||
a_Pkt.WriteBEUInt8(0x0e);
|
a_Pkt.WriteBEUInt8(0x0e);
|
||||||
a_Pkt.WriteBEUInt8(Zombie.IsConverting() ? 1 : 0);
|
a_Pkt.WriteBEUInt8(Zombie.IsConverting() ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
} // case mtZombie
|
} // case mtZombie
|
||||||
|
|
||||||
|
case mtZombiePigman:
|
||||||
|
{
|
||||||
|
auto & ZombiePigman = reinterpret_cast<const cZombiePigman &>(a_Mob);
|
||||||
|
a_Pkt.WriteBEUInt8(0x0c);
|
||||||
|
a_Pkt.WriteBEInt8(ZombiePigman.IsBaby() ? 1 : -1);
|
||||||
|
break;
|
||||||
|
} // case mtZombiePigman
|
||||||
} // switch (a_Mob.GetType())
|
} // switch (a_Mob.GetType())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,6 +554,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
m_Writer.AddInt ("Style", Horse.GetHorseStyle());
|
m_Writer.AddInt ("Style", Horse.GetHorseStyle());
|
||||||
m_Writer.AddInt ("ArmorType", Horse.GetHorseArmour());
|
m_Writer.AddInt ("ArmorType", Horse.GetHorseArmour());
|
||||||
m_Writer.AddByte("Saddle", Horse.IsSaddled());
|
m_Writer.AddByte("Saddle", Horse.IsSaddled());
|
||||||
|
m_Writer.AddByte("Age", Horse.GetAge());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtMagmaCube:
|
case mtMagmaCube:
|
||||||
@ -565,6 +566,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
{
|
{
|
||||||
m_Writer.AddByte("Sheared", ((const cSheep *)a_Monster)->IsSheared());
|
m_Writer.AddByte("Sheared", ((const cSheep *)a_Monster)->IsSheared());
|
||||||
m_Writer.AddByte("Color", ((const cSheep *)a_Monster)->GetFurColor());
|
m_Writer.AddByte("Color", ((const cSheep *)a_Monster)->GetFurColor());
|
||||||
|
m_Writer.AddByte("Age", ((const cSheep *)a_Monster)->GetAge());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtSlime:
|
case mtSlime:
|
||||||
@ -580,6 +582,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
case mtVillager:
|
case mtVillager:
|
||||||
{
|
{
|
||||||
m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType());
|
m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType());
|
||||||
|
m_Writer.AddByte("Age", ((const cVillager *)a_Monster)->GetAge());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtWither:
|
case mtWither:
|
||||||
@ -601,13 +604,37 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
|
m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
|
||||||
m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
|
m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
|
||||||
m_Writer.AddByte("CollarColor", (unsigned char)Wolf.GetCollarColor());
|
m_Writer.AddByte("CollarColor", (unsigned char)Wolf.GetCollarColor());
|
||||||
|
m_Writer.AddByte("Age", Wolf.GetAge());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtZombie:
|
case mtZombie:
|
||||||
{
|
{
|
||||||
m_Writer.AddByte("IsVillager", (((const cZombie *)a_Monster)->IsVillagerZombie() ? 1 : 0));
|
m_Writer.AddByte("IsVillager", (((const cZombie *)a_Monster)->IsVillagerZombie() ? 1 : 0));
|
||||||
m_Writer.AddByte("IsBaby", (((const cZombie *)a_Monster)->IsBaby() ? 1 : 0));
|
|
||||||
m_Writer.AddByte("IsConverting", (((const cZombie *)a_Monster)->IsConverting() ? 1 : 0));
|
m_Writer.AddByte("IsConverting", (((const cZombie *)a_Monster)->IsConverting() ? 1 : 0));
|
||||||
|
m_Writer.AddByte("Age", (((const cZombie *)a_Monster)->GetAge()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mtZombiePigman:
|
||||||
|
{
|
||||||
|
m_Writer.AddByte("Age", (((const cZombiePigman *)a_Monster)->GetAge()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mtOcelot:
|
||||||
|
{
|
||||||
|
const cOcelot & Ocelot = *((cOcelot *)a_Monster);
|
||||||
|
m_Writer.AddByte("Age", Ocelot.GetAge());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mtPig:
|
||||||
|
{
|
||||||
|
const cPig & Pig = *((cPig *)a_Monster);
|
||||||
|
m_Writer.AddByte("Age", Pig.GetAge());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case mtRabbit:
|
||||||
|
{
|
||||||
|
const cRabbit & Rabbit = *((cRabbit *)a_Monster);
|
||||||
|
m_Writer.AddByte("Age", Rabbit.GetAge());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case mtInvalidType:
|
case mtInvalidType:
|
||||||
@ -621,15 +648,11 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
|
|||||||
case mtGuardian:
|
case mtGuardian:
|
||||||
case mtIronGolem:
|
case mtIronGolem:
|
||||||
case mtMooshroom:
|
case mtMooshroom:
|
||||||
case mtOcelot:
|
|
||||||
case mtPig:
|
|
||||||
case mtRabbit:
|
|
||||||
case mtSilverfish:
|
case mtSilverfish:
|
||||||
case mtSnowGolem:
|
case mtSnowGolem:
|
||||||
case mtSpider:
|
case mtSpider:
|
||||||
case mtSquid:
|
case mtSquid:
|
||||||
case mtWitch:
|
case mtWitch:
|
||||||
case mtZombiePigman:
|
|
||||||
{
|
{
|
||||||
// Other mobs have no special tags.
|
// Other mobs have no special tags.
|
||||||
break;
|
break;
|
||||||
|
@ -2257,6 +2257,13 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2346,6 +2353,13 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2366,6 +2380,13 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2386,6 +2407,13 @@ void cWSSAnvil::LoadRabbitFromNBT(cEntityList & a_Entities, const cParsedNBT & a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2419,6 +2447,13 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
|
|||||||
Monster->SetSheared(a_NBT.GetByte(ShearedIdx) != 0);
|
Monster->SetSheared(a_NBT.GetByte(ShearedIdx) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2584,6 +2619,14 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT &
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2683,6 +2726,14 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2711,6 +2762,13 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2731,6 +2789,13 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
|
||||||
|
if (AgeableIdx > 0)
|
||||||
|
{
|
||||||
|
Byte Age = a_NBT.GetByte(AgeableIdx);
|
||||||
|
Monster->SetAge(Age);
|
||||||
|
}
|
||||||
|
|
||||||
a_Entities.push_back(Monster.release());
|
a_Entities.push_back(Monster.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user