1
0

Merge pull request #1133 from Howaner/Sheep

Sheep fixes
This commit is contained in:
Mattes D 2014-07-13 11:04:24 +02:00
commit 48b5c11022
4 changed files with 75 additions and 10 deletions

View File

@ -900,7 +900,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
case mtMooshroom: toReturn = new cMooshroom(); break; case mtMooshroom: toReturn = new cMooshroom(); break;
case mtOcelot: toReturn = new cOcelot(); break; case mtOcelot: toReturn = new cOcelot(); break;
case mtPig: toReturn = new cPig(); break; case mtPig: toReturn = new cPig(); break;
case mtSheep: toReturn = new cSheep (Random.NextInt(15)); break; // Colour parameter case mtSheep: toReturn = new cSheep(); break;
case mtSilverfish: toReturn = new cSilverfish(); break; case mtSilverfish: toReturn = new cSilverfish(); break;
case mtSnowGolem: toReturn = new cSnowGolem(); break; case mtSnowGolem: toReturn = new cSnowGolem(); break;
case mtSpider: toReturn = new cSpider(); break; case mtSpider: toReturn = new cSpider(); break;

View File

@ -5,6 +5,7 @@
#include "../BlockID.h" #include "../BlockID.h"
#include "../Entities/Player.h" #include "../Entities/Player.h"
#include "../World.h" #include "../World.h"
#include "FastRandom.h"
@ -16,6 +17,16 @@ cSheep::cSheep(int a_Color) :
m_WoolColor(a_Color), m_WoolColor(a_Color),
m_TimeToStopEating(-1) m_TimeToStopEating(-1)
{ {
// Generate random wool color.
if (m_WoolColor == -1)
{
m_WoolColor = GenerateNaturalRandomColor();
}
if ((m_WoolColor < 0) || (m_WoolColor > 15))
{
m_WoolColor = 0;
}
} }
@ -37,7 +48,7 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSheep::OnRightClicked(cPlayer & a_Player) void cSheep::OnRightClicked(cPlayer & a_Player)
{ {
const cItem & EquippedItem = a_Player.GetEquippedItem(); const cItem & EquippedItem = a_Player.GetEquippedItem();
if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby())
{ {
m_IsSheared = true; m_IsSheared = true;
m_World->BroadcastEntityMetadata(*this); m_World->BroadcastEntityMetadata(*this);
@ -51,6 +62,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player)
int NumDrops = m_World->GetTickRandomNumber(2) + 1; int NumDrops = m_World->GetTickRandomNumber(2) + 1;
Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor));
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
m_World->BroadcastSoundEffect("mob.sheep.shear", POSX_TOINT * 8, POSY_TOINT * 8, POSZ_TOINT * 8, 1.0f, 1.0f);
} }
else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage)) else if ((EquippedItem.m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - EquippedItem.m_ItemDamage))
{ {
@ -109,3 +121,38 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
} }
} }
NIBBLETYPE cSheep::GenerateNaturalRandomColor(void)
{
cFastRandom Random;
int Chance = Random.NextInt(101);
if (Chance <= 81)
{
return E_META_WOOL_WHITE;
}
else if (Chance <= 86)
{
return E_META_WOOL_BLACK;
}
else if (Chance <= 91)
{
return E_META_WOOL_GRAY;
}
else if (Chance <= 96)
{
return E_META_WOOL_LIGHTGRAY;
}
else if (Chance <= 99)
{
return E_META_WOOL_BROWN;
}
else
{
return E_META_WOOL_PINK;
}
}

View File

@ -13,21 +13,32 @@ class cSheep :
typedef cPassiveMonster super; typedef cPassiveMonster super;
public: public:
cSheep(int a_Color);
/** The number is the color of the sheep.
Use E_META_WOOL_* constants for the wool color.
If you type -1, the server will generate a random color
with the GenerateNaturalRandomColor() function. */
cSheep(int a_Color = -1);
CLASS_PROTODEF(cSheep); CLASS_PROTODEF(cSheep);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override; virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
/** Generates a random color for the sheep like the vanilla server.
The percent's where used are from the wiki: http://minecraft.gamepedia.com/Sheep#Breeding */
static NIBBLETYPE GenerateNaturalRandomColor(void);
bool IsSheared(void) const { return m_IsSheared; } bool IsSheared(void) const { return m_IsSheared; }
void SetSheared(bool a_IsSheared) { m_IsSheared = a_IsSheared; }
int GetFurColor(void) const { return m_WoolColor; } int GetFurColor(void) const { return m_WoolColor; }
void SetFurColor(int a_WoolColor) { m_WoolColor = a_WoolColor; }
private: private:
bool m_IsSheared; bool m_IsSheared;
int m_WoolColor; int m_WoolColor;
int m_TimeToStopEating; int m_TimeToStopEating;

View File

@ -2086,10 +2086,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB
void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{ {
int ColorIdx = a_NBT.FindChildByName(a_TagIdx, "Color"); int ColorIdx = a_NBT.FindChildByName(a_TagIdx, "Color");
int Color = -1;
if (ColorIdx < 0) { return; } if (ColorIdx > 0)
{
int Color = (int)a_NBT.GetByte(ColorIdx); Color = (int)a_NBT.GetByte(ColorIdx);
}
std::auto_ptr<cSheep> Monster(new cSheep(Color)); std::auto_ptr<cSheep> Monster(new cSheep(Color));
if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
@ -2102,6 +2103,12 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_
return; return;
} }
int ShearedIdx = a_NBT.FindChildByName(a_TagIdx, "Sheared");
if (ShearedIdx > 0)
{
Monster->SetSheared(a_NBT.GetByte(ShearedIdx) != 0);
}
a_Entities.push_back(Monster.release()); a_Entities.push_back(Monster.release());
} }