1
0

Added Rabbit Metadata values.

Added the Rabbit Types and the MoreCarrotTicks value. Types are selected randomly on creation.
Fixes #1867
This commit is contained in:
bibo38 2015-07-17 01:09:06 +02:00
parent c633dd8cec
commit 6a27ec2ea0
5 changed files with 109 additions and 54 deletions

View File

@ -10,7 +10,20 @@
cRabbit::cRabbit(void) : cRabbit::cRabbit(void) :
super("Rabbit", mtRabbit, "mob.rabbit.idle", "mob.rabbit.death", 0.82, 0.68) cRabbit(static_cast<eRabbitType>(cFastRandom().NextInt(
static_cast<UInt8>(eRabbitType::SaltAndPepper) + 1 // Max possible Rabbit-Type
)), 0)
{
}
cRabbit::cRabbit(eRabbitType Type, int MoreCarrotTicks) :
super("Rabbit", mtRabbit, "mob.rabbit.idle", "mob.rabbit.death", 0.82, 0.68),
m_Type(Type),
m_MoreCarrotTicks(MoreCarrotTicks)
{ {
} }

View File

@ -7,6 +7,21 @@
enum class eRabbitType : UInt8
{
Brown = 0,
White = 1,
Black = 2,
BlackAndWhite = 3,
Gold = 4,
SaltAndPepper = 5,
TheKillerBunny = 99
};
class cRabbit : class cRabbit :
public cPassiveMonster public cPassiveMonster
{ {
@ -14,11 +29,19 @@ class cRabbit :
public: public:
cRabbit(); cRabbit();
cRabbit(eRabbitType Type, int MoreCarrotTicks = 0);
CLASS_PROTODEF(cRabbit) CLASS_PROTODEF(cRabbit)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); } virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
eRabbitType GetRabbitType() const { return m_Type; }
UInt8 GetRabbitTypeAsNumber() const { return static_cast<UInt8>(GetRabbitType()); }
int GetMoreCarrotTicks() const { return m_MoreCarrotTicks; }
private:
eRabbitType m_Type;
int m_MoreCarrotTicks; // Ticks until the Rabbit eat planted Carrots
} ; } ;

View File

@ -3437,14 +3437,6 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
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);
@ -3462,6 +3454,17 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
break; break;
} // case mtSheep } // case mtSheep
case mtRabbit:
{
auto & Rabbit = reinterpret_cast<const cRabbit &>(a_Mob);
a_Pkt.WriteBEUInt8(0x12);
a_Pkt.WriteBEUInt8(Rabbit.GetRabbitTypeAsNumber());
a_Pkt.WriteBEUInt8(0x0c);
a_Pkt.WriteBEInt8(Rabbit.GetAge());
break;
} // case mtRabbit
case mtSkeleton: case mtSkeleton:
{ {
auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob); auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob);

View File

@ -528,113 +528,118 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
{ {
case mtBat: case mtBat:
{ {
m_Writer.AddByte("BatFlags", ((const cBat *)a_Monster)->IsHanging()); m_Writer.AddByte("BatFlags", reinterpret_cast<const cBat *>(a_Monster)->IsHanging());
break; break;
} }
case mtCreeper: case mtCreeper:
{ {
m_Writer.AddByte("powered", ((const cCreeper *)a_Monster)->IsCharged()); const cCreeper *Creeper = reinterpret_cast<const cCreeper *>(a_Monster);
m_Writer.AddByte("ignited", ((const cCreeper *)a_Monster)->IsBlowing()); m_Writer.AddByte("powered", Creeper->IsCharged());
m_Writer.AddByte("ignited", Creeper->IsBlowing());
break; break;
} }
case mtEnderman: case mtEnderman:
{ {
m_Writer.AddShort("carried", (Int16)((const cEnderman *)a_Monster)->GetCarriedBlock()); const cEnderman *Enderman = reinterpret_cast<const cEnderman *>(a_Monster);
m_Writer.AddShort("carriedData", (Int16)((const cEnderman *)a_Monster)->GetCarriedMeta()); m_Writer.AddShort("carried", (Int16) Enderman->GetCarriedBlock());
m_Writer.AddShort("carriedData", (Int16) Enderman->GetCarriedMeta());
break; break;
} }
case mtHorse: case mtHorse:
{ {
const cHorse & Horse = *((const cHorse *)a_Monster); const cHorse *Horse = reinterpret_cast<const cHorse *>(a_Monster);
m_Writer.AddByte("ChestedHorse", Horse.IsChested()); m_Writer.AddByte("ChestedHorse", Horse->IsChested());
m_Writer.AddByte("EatingHaystack", Horse.IsEating()); m_Writer.AddByte("EatingHaystack", Horse->IsEating());
m_Writer.AddByte("Tame", Horse.IsTame()); m_Writer.AddByte("Tame", Horse->IsTame());
m_Writer.AddInt ("Type", Horse.GetHorseType()); m_Writer.AddInt ("Type", Horse->GetHorseType());
m_Writer.AddInt ("Color", Horse.GetHorseColor()); m_Writer.AddInt ("Color", Horse->GetHorseColor());
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()); m_Writer.AddByte("Age", Horse->GetAge());
break; break;
} }
case mtMagmaCube: case mtMagmaCube:
{ {
m_Writer.AddInt("Size", ((const cMagmaCube *)a_Monster)->GetSize()); m_Writer.AddInt("Size", reinterpret_cast<const cMagmaCube *>(a_Monster)->GetSize());
break; break;
} }
case mtSheep: case mtSheep:
{ {
m_Writer.AddByte("Sheared", ((const cSheep *)a_Monster)->IsSheared()); const cSheep *Sheep = reinterpret_cast<const cSheep *>(a_Monster);
m_Writer.AddByte("Color", ((const cSheep *)a_Monster)->GetFurColor()); m_Writer.AddByte("Sheared", Sheep->IsSheared());
m_Writer.AddByte("Age", ((const cSheep *)a_Monster)->GetAge()); m_Writer.AddByte("Color", Sheep->GetFurColor());
m_Writer.AddByte("Age", Sheep->GetAge());
break; break;
} }
case mtSlime: case mtSlime:
{ {
m_Writer.AddInt("Size", ((const cSlime *)a_Monster)->GetSize()); m_Writer.AddInt("Size", reinterpret_cast<const cSlime *>(a_Monster)->GetSize());
break; break;
} }
case mtSkeleton: case mtSkeleton:
{ {
m_Writer.AddByte("SkeletonType", (((const cSkeleton *)a_Monster)->IsWither() ? 1 : 0)); m_Writer.AddByte("SkeletonType", (reinterpret_cast<const cSkeleton *>(a_Monster)->IsWither() ? 1 : 0));
break; break;
} }
case mtVillager: case mtVillager:
{ {
m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType()); const cVillager *Villager = reinterpret_cast<const cVillager *>(a_Monster);
m_Writer.AddByte("Age", ((const cVillager *)a_Monster)->GetAge()); m_Writer.AddInt("Profession", Villager->GetVilType());
m_Writer.AddByte("Age", Villager->GetAge());
break; break;
} }
case mtWither: case mtWither:
{ {
m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetWitherInvulnerableTicks()); m_Writer.AddInt("Invul", reinterpret_cast<const cWither *>(a_Monster)->GetWitherInvulnerableTicks());
break; break;
} }
case mtWolf: case mtWolf:
{ {
const cWolf & Wolf = *((cWolf *)a_Monster); const cWolf *Wolf = reinterpret_cast<const cWolf *>(a_Monster);
if (!Wolf.GetOwnerName().empty()) if (!Wolf->GetOwnerName().empty())
{ {
m_Writer.AddString("Owner", Wolf.GetOwnerName()); m_Writer.AddString("Owner", Wolf->GetOwnerName());
} }
if (!Wolf.GetOwnerUUID().empty()) if (!Wolf->GetOwnerUUID().empty())
{ {
m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID()); m_Writer.AddString("OwnerUUID", Wolf->GetOwnerUUID());
} }
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()); m_Writer.AddByte("Age", Wolf->GetAge());
break; break;
} }
case mtZombie: case mtZombie:
{ {
m_Writer.AddByte("IsVillager", (((const cZombie *)a_Monster)->IsVillagerZombie() ? 1 : 0)); const cZombie *Zombie = reinterpret_cast<const cZombie *>(a_Monster);
m_Writer.AddByte("IsConverting", (((const cZombie *)a_Monster)->IsConverting() ? 1 : 0)); m_Writer.AddByte("IsVillager", Zombie->IsVillagerZombie() ? 1 : 0);
m_Writer.AddByte("Age", (((const cZombie *)a_Monster)->GetAge())); m_Writer.AddByte("IsConverting", Zombie->IsConverting() ? 1 : 0);
m_Writer.AddByte("Age", Zombie->GetAge());
break; break;
} }
case mtZombiePigman: case mtZombiePigman:
{ {
m_Writer.AddByte("Age", (((const cZombiePigman *)a_Monster)->GetAge())); m_Writer.AddByte("Age", reinterpret_cast<const cZombiePigman *>(a_Monster)->GetAge());
break; break;
} }
case mtOcelot: case mtOcelot:
{ {
const cOcelot & Ocelot = *((cOcelot *)a_Monster); m_Writer.AddByte("Age", reinterpret_cast<const cOcelot *>(a_Monster)->GetAge());
m_Writer.AddByte("Age", Ocelot.GetAge());
break; break;
} }
case mtPig: case mtPig:
{ {
const cPig & Pig = *((cPig *)a_Monster); m_Writer.AddByte("Age", reinterpret_cast<const cPig *>(a_Monster)->GetAge());
m_Writer.AddByte("Age", Pig.GetAge());
break; break;
} }
case mtRabbit: case mtRabbit:
{ {
const cRabbit & Rabbit = *((cRabbit *)a_Monster); const cRabbit *Rabbit = reinterpret_cast<const cRabbit *>(a_Monster);
m_Writer.AddByte("Age", Rabbit.GetAge()); m_Writer.AddInt("RabbitType", Rabbit->GetRabbitTypeAsNumber());
m_Writer.AddInt("MoreCarrotTicks", Rabbit->GetMoreCarrotTicks());
m_Writer.AddByte("Age", Rabbit->GetAge());
break; break;
} }
case mtInvalidType: case mtInvalidType:

View File

@ -2396,7 +2396,18 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
void cWSSAnvil::LoadRabbitFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) void cWSSAnvil::LoadRabbitFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{ {
std::unique_ptr<cRabbit> Monster = cpp14::make_unique<cRabbit>(); int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "RabbitType");
int MoreCarrotTicksIdx = a_NBT.FindChildByName(a_TagIdx, "MoreCarrotTicks");
if ((TypeIdx < 0) || (MoreCarrotTicksIdx < 0))
{
return;
}
int Type = a_NBT.GetInt(TypeIdx);
int MoreCarrotTicks = a_NBT.GetInt(MoreCarrotTicksIdx);
std::unique_ptr<cRabbit> Monster = cpp14::make_unique<cRabbit>(static_cast<eRabbitType>(Type), MoreCarrotTicks);
if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{ {
return; return;