summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Sheep.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-07-13 11:04:24 +0200
committerMattes D <github@xoft.cz>2014-07-13 11:04:24 +0200
commit48b5c11022a1140ff36d853eba391320da6e3983 (patch)
tree9d13c3e0537c5eca0a030889ec2f167359375d73 /src/Mobs/Sheep.cpp
parentMerge pull request #1166 from Howaner/GlobalFixes (diff)
parentChanged comments. (diff)
downloadcuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar.gz
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar.bz2
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar.lz
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar.xz
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.tar.zst
cuberite-48b5c11022a1140ff36d853eba391320da6e3983.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Sheep.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 5a6b760af..e208aa891 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -5,6 +5,7 @@
#include "../BlockID.h"
#include "../Entities/Player.h"
#include "../World.h"
+#include "FastRandom.h"
@@ -16,6 +17,16 @@ cSheep::cSheep(int a_Color) :
m_WoolColor(a_Color),
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)
{
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_World->BroadcastEntityMetadata(*this);
@@ -51,6 +62,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player)
int NumDrops = m_World->GetTickRandomNumber(2) + 1;
Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor));
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))
{
@@ -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;
+ }
+}
+