diff options
Diffstat (limited to '')
-rw-r--r-- | src/Generating/Trees.h | 1 | ||||
-rw-r--r-- | src/Mobs/Rabbit.cpp | 15 | ||||
-rw-r--r-- | src/Mobs/Rabbit.h | 25 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 19 | ||||
-rw-r--r-- | src/WorldStorage/NBTChunkSerializer.cpp | 91 | ||||
-rwxr-xr-x | src/WorldStorage/WSSAnvil.cpp | 13 |
6 files changed, 110 insertions, 54 deletions
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h index 092d71182..b0363e050 100644 --- a/src/Generating/Trees.h +++ b/src/Generating/Trees.h @@ -106,6 +106,7 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & /// Generates an image of a small jungle tree (1x1 trunk) void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +/// Moves the x and z coordinants to the north-west corner of a 2x2 of saplings. Returns true if a 2x2 was found, otherwise it returns false bool GetLargeTreeAdjustment(cWorld & a_World, int & a_X, int & a_Y, int & a_Z, NIBBLETYPE a_Meta); diff --git a/src/Mobs/Rabbit.cpp b/src/Mobs/Rabbit.cpp index c7f3d58f0..9d10212bf 100644 --- a/src/Mobs/Rabbit.cpp +++ b/src/Mobs/Rabbit.cpp @@ -10,7 +10,20 @@ 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) { } diff --git a/src/Mobs/Rabbit.h b/src/Mobs/Rabbit.h index e86c85579..56181e3d0 100644 --- a/src/Mobs/Rabbit.h +++ b/src/Mobs/Rabbit.h @@ -7,6 +7,21 @@ +enum class eRabbitType : UInt8 +{ + Brown = 0, + White = 1, + Black = 2, + BlackAndWhite = 3, + Gold = 4, + SaltAndPepper = 5, + TheKillerBunny = 99 +}; + + + + + class cRabbit : public cPassiveMonster { @@ -14,11 +29,19 @@ class cRabbit : public: cRabbit(); + cRabbit(eRabbitType Type, int MoreCarrotTicks = 0); CLASS_PROTODEF(cRabbit) virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - 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 } ; diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index f4f32dfdb..e8acf8bd4 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -3437,14 +3437,6 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) break; } // 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: { auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob); @@ -3462,6 +3454,17 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) break; } // 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: { auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob); diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 234c60d62..cfbbcd0b4 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -528,113 +528,118 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) { case mtBat: { - m_Writer.AddByte("BatFlags", ((const cBat *)a_Monster)->IsHanging()); + m_Writer.AddByte("BatFlags", reinterpret_cast<const cBat *>(a_Monster)->IsHanging()); break; } case mtCreeper: { - m_Writer.AddByte("powered", ((const cCreeper *)a_Monster)->IsCharged()); - m_Writer.AddByte("ignited", ((const cCreeper *)a_Monster)->IsBlowing()); + const cCreeper *Creeper = reinterpret_cast<const cCreeper *>(a_Monster); + m_Writer.AddByte("powered", Creeper->IsCharged()); + m_Writer.AddByte("ignited", Creeper->IsBlowing()); break; } case mtEnderman: { - m_Writer.AddShort("carried", (Int16)((const cEnderman *)a_Monster)->GetCarriedBlock()); - m_Writer.AddShort("carriedData", (Int16)((const cEnderman *)a_Monster)->GetCarriedMeta()); + const cEnderman *Enderman = reinterpret_cast<const cEnderman *>(a_Monster); + m_Writer.AddShort("carried", (Int16) Enderman->GetCarriedBlock()); + m_Writer.AddShort("carriedData", (Int16) Enderman->GetCarriedMeta()); break; } case mtHorse: { - const cHorse & Horse = *((const cHorse *)a_Monster); - m_Writer.AddByte("ChestedHorse", Horse.IsChested()); - m_Writer.AddByte("EatingHaystack", Horse.IsEating()); - m_Writer.AddByte("Tame", Horse.IsTame()); - m_Writer.AddInt ("Type", Horse.GetHorseType()); - m_Writer.AddInt ("Color", Horse.GetHorseColor()); - m_Writer.AddInt ("Style", Horse.GetHorseStyle()); - m_Writer.AddInt ("ArmorType", Horse.GetHorseArmour()); - m_Writer.AddByte("Saddle", Horse.IsSaddled()); - m_Writer.AddByte("Age", Horse.GetAge()); + const cHorse *Horse = reinterpret_cast<const cHorse *>(a_Monster); + m_Writer.AddByte("ChestedHorse", Horse->IsChested()); + m_Writer.AddByte("EatingHaystack", Horse->IsEating()); + m_Writer.AddByte("Tame", Horse->IsTame()); + m_Writer.AddInt ("Type", Horse->GetHorseType()); + m_Writer.AddInt ("Color", Horse->GetHorseColor()); + m_Writer.AddInt ("Style", Horse->GetHorseStyle()); + m_Writer.AddInt ("ArmorType", Horse->GetHorseArmour()); + m_Writer.AddByte("Saddle", Horse->IsSaddled()); + m_Writer.AddByte("Age", Horse->GetAge()); break; } case mtMagmaCube: { - m_Writer.AddInt("Size", ((const cMagmaCube *)a_Monster)->GetSize()); + m_Writer.AddInt("Size", reinterpret_cast<const cMagmaCube *>(a_Monster)->GetSize()); break; } case mtSheep: { - m_Writer.AddByte("Sheared", ((const cSheep *)a_Monster)->IsSheared()); - m_Writer.AddByte("Color", ((const cSheep *)a_Monster)->GetFurColor()); - m_Writer.AddByte("Age", ((const cSheep *)a_Monster)->GetAge()); + const cSheep *Sheep = reinterpret_cast<const cSheep *>(a_Monster); + m_Writer.AddByte("Sheared", Sheep->IsSheared()); + m_Writer.AddByte("Color", Sheep->GetFurColor()); + m_Writer.AddByte("Age", Sheep->GetAge()); break; } case mtSlime: { - m_Writer.AddInt("Size", ((const cSlime *)a_Monster)->GetSize()); + m_Writer.AddInt("Size", reinterpret_cast<const cSlime *>(a_Monster)->GetSize()); break; } 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; } case mtVillager: { - m_Writer.AddInt("Profession", ((const cVillager *)a_Monster)->GetVilType()); - m_Writer.AddByte("Age", ((const cVillager *)a_Monster)->GetAge()); + const cVillager *Villager = reinterpret_cast<const cVillager *>(a_Monster); + m_Writer.AddInt("Profession", Villager->GetVilType()); + m_Writer.AddByte("Age", Villager->GetAge()); break; } case mtWither: { - m_Writer.AddInt("Invul", ((const cWither *)a_Monster)->GetWitherInvulnerableTicks()); + m_Writer.AddInt("Invul", reinterpret_cast<const cWither *>(a_Monster)->GetWitherInvulnerableTicks()); break; } case mtWolf: { - const cWolf & Wolf = *((cWolf *)a_Monster); - if (!Wolf.GetOwnerName().empty()) + const cWolf *Wolf = reinterpret_cast<const cWolf *>(a_Monster); + 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("Angry", Wolf.IsAngry() ? 1 : 0); - m_Writer.AddByte("CollarColor", (unsigned char)Wolf.GetCollarColor()); - m_Writer.AddByte("Age", Wolf.GetAge()); + m_Writer.AddByte("Sitting", Wolf->IsSitting() ? 1 : 0); + m_Writer.AddByte("Angry", Wolf->IsAngry() ? 1 : 0); + m_Writer.AddByte("CollarColor", (unsigned char) Wolf->GetCollarColor()); + m_Writer.AddByte("Age", Wolf->GetAge()); break; } case mtZombie: { - m_Writer.AddByte("IsVillager", (((const cZombie *)a_Monster)->IsVillagerZombie() ? 1 : 0)); - m_Writer.AddByte("IsConverting", (((const cZombie *)a_Monster)->IsConverting() ? 1 : 0)); - m_Writer.AddByte("Age", (((const cZombie *)a_Monster)->GetAge())); + const cZombie *Zombie = reinterpret_cast<const cZombie *>(a_Monster); + m_Writer.AddByte("IsVillager", Zombie->IsVillagerZombie() ? 1 : 0); + m_Writer.AddByte("IsConverting", Zombie->IsConverting() ? 1 : 0); + m_Writer.AddByte("Age", Zombie->GetAge()); break; } case mtZombiePigman: { - m_Writer.AddByte("Age", (((const cZombiePigman *)a_Monster)->GetAge())); + m_Writer.AddByte("Age", reinterpret_cast<const cZombiePigman *>(a_Monster)->GetAge()); break; } case mtOcelot: { - const cOcelot & Ocelot = *((cOcelot *)a_Monster); - m_Writer.AddByte("Age", Ocelot.GetAge()); + m_Writer.AddByte("Age", reinterpret_cast<const cOcelot *>(a_Monster)->GetAge()); break; } case mtPig: { - const cPig & Pig = *((cPig *)a_Monster); - m_Writer.AddByte("Age", Pig.GetAge()); + m_Writer.AddByte("Age", reinterpret_cast<const cPig *>(a_Monster)->GetAge()); break; } case mtRabbit: { - const cRabbit & Rabbit = *((cRabbit *)a_Monster); - m_Writer.AddByte("Age", Rabbit.GetAge()); + const cRabbit *Rabbit = reinterpret_cast<const cRabbit *>(a_Monster); + m_Writer.AddInt("RabbitType", Rabbit->GetRabbitTypeAsNumber()); + m_Writer.AddInt("MoreCarrotTicks", Rabbit->GetMoreCarrotTicks()); + m_Writer.AddByte("Age", Rabbit->GetAge()); break; } case mtInvalidType: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 62918f44e..54071b9df 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -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) { - 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)) { return; |