summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Behaviors/BehaviorItemDropper.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-29 18:53:06 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-29 18:53:06 +0200
commita53d1051d9033a1be708b76b8a50bca6f5d2bbd9 (patch)
tree698439a8455592d4d9cbf6b23835eea5e0ca8a18 /src/Mobs/Behaviors/BehaviorItemDropper.cpp
parentMerge branch 'master' into mobs2 (diff)
downloadcuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.gz
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.bz2
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.lz
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.xz
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.tar.zst
cuberite-a53d1051d9033a1be708b76b8a50bca6f5d2bbd9.zip
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorItemDropper.cpp')
-rw-r--r--src/Mobs/Behaviors/BehaviorItemDropper.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorItemDropper.cpp b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
index 8b1378917..0ca718990 100644
--- a/src/Mobs/Behaviors/BehaviorItemDropper.cpp
+++ b/src/Mobs/Behaviors/BehaviorItemDropper.cpp
@@ -1 +1,50 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "BehaviorItemDropper.h"
+#include "../Monster.h"
+#include "../../World.h"
+
+
+void cBehaviorItemDropper::AttachToMonster(cMonster & a_Parent)
+{
+ m_Parent = &a_Parent;
+ m_EggDropTimer = 0;
+ m_Parent->AttachPostTickBehavior(this);
+}
+
+
+
+
+
+void cBehaviorItemDropper::PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ if (!m_Parent->IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+
+ if (m_Parent->IsBaby())
+ {
+ return; // Babies don't lay eggs
+ }
+
+ if ((m_EggDropTimer == 120) && GetRandomProvider().RandBool())
+ {
+ cItems Drops;
+ m_EggDropTimer = 0;
+ Drops.push_back(cItem(E_ITEM_EGG, 1));
+ m_Parent->GetWorld()->SpawnItemPickups(Drops, m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 10);
+ }
+ else if (m_EggDropTimer == 150)
+ {
+ cItems Drops;
+ m_EggDropTimer = 0;
+ Drops.push_back(cItem(E_ITEM_EGG, 1));
+ m_Parent->GetWorld()->SpawnItemPickups(Drops, m_Parent->GetPosX(), m_Parent->GetPosY(), m_Parent->GetPosZ(), 10);
+ }
+ else
+ {
+ m_EggDropTimer++;
+ }
+}