summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorDebucquoy Anthony tonitch <debucquoy.anthony@gmail.com>2023-09-26 23:54:37 +0200
committerGitHub <noreply@github.com>2023-09-26 23:54:37 +0200
commit7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97 (patch)
tree62ce535a26ad0637564de14ad7b75429537162a7 /src/Mobs
parentUpdate Core (diff)
downloadcuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar.gz
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar.bz2
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar.lz
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar.xz
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.tar.zst
cuberite-7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/AggressiveMonster.cpp61
-rw-r--r--src/Mobs/AggressiveMonster.h14
-rw-r--r--src/Mobs/CMakeLists.txt2
-rw-r--r--src/Mobs/Enderman.cpp23
-rw-r--r--src/Mobs/Endermite.cpp41
-rw-r--r--src/Mobs/Endermite.h24
-rw-r--r--src/Mobs/IncludeAllMonsters.h1
-rw-r--r--src/Mobs/Monster.cpp7
8 files changed, 166 insertions, 7 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index f7392d92e..c93985b90 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -3,9 +3,9 @@
#include "AggressiveMonster.h"
-#include "../World.h"
-#include "../Entities/Player.h"
-#include "../LineBlockTracer.h"
+#include "LineBlockTracer.h"
+#include "World.h"
+#include "Entities/Player.h"
@@ -46,6 +46,61 @@ void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
+cMonster * cAggressiveMonster::GetMonsterOfTypeInSight(eMonsterType a_MobType, unsigned int a_SightDistance)
+{
+
+ cMonster * FoundTarget = nullptr;
+ auto MinimumDistance = static_cast<double>(a_SightDistance * a_SightDistance);
+
+ class cCallback : public cBlockTracer::cCallbacks
+ {
+ public:
+ bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override
+ {
+ return a_BlockType != E_BLOCK_AIR;
+ }
+ };
+
+ auto Callbacks = cCallback();
+ auto Tracer = cLineBlockTracer(*GetWorld(), Callbacks);
+
+ cEntityCallback Callback = [&](cEntity & a_Entity)
+ {
+ if (!a_Entity.IsMob())
+ {
+ return false;
+ }
+
+ auto & Other = dynamic_cast<cMonster &>(a_Entity);
+ if (Other.GetMobType() != a_MobType)
+ {
+ return false;
+ }
+
+ Vector3d MyHeadPosition = GetPosition().addedY(GetHeight());
+ Vector3d TargetPosition = Other.GetPosition().addedY(Other.GetHeight());
+ double TargetDistance = (MyHeadPosition - TargetPosition).SqrLength();
+
+ if (
+ (MinimumDistance > TargetDistance) &&
+ (TargetDistance < (a_SightDistance * a_SightDistance))
+ )
+ {
+ FoundTarget = & Other;
+ return true;
+ }
+ return false;
+ };
+
+ cBoundingBox CheckZone(GetPosition().addedXZ(-a_SightDistance, -a_SightDistance), GetPosition().addedXZ(a_SightDistance, a_SightDistance));
+ m_World->ForEachEntityInBox(CheckZone, Callback);
+ return FoundTarget;
+}
+
+
+
+
+
void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
Super::Tick(a_Dt, a_Chunk);
diff --git a/src/Mobs/AggressiveMonster.h b/src/Mobs/AggressiveMonster.h
index 8f648eab9..48ed7932e 100644
--- a/src/Mobs/AggressiveMonster.h
+++ b/src/Mobs/AggressiveMonster.h
@@ -30,12 +30,18 @@ public:
virtual void EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk) override;
+ /**
+ * Check if a monster of certain type is in sight
+ *
+ * @param a_mobtype the mob type to find
+ * @param SightDistance max distance to check
+ *
+ * @return pointer to the mob found
+ */
+ cMonster * GetMonsterOfTypeInSight(eMonsterType a_mobtype, unsigned int SightDistance=16);
+
/** Try to perform attack
returns true if attack was deemed successful (hit player, fired projectile, creeper exploded, etc.) even if it didn't actually do damage
return false if e.g. the mob is still in cooldown from a previous attack */
virtual bool Attack(std::chrono::milliseconds a_Dt);
} ;
-
-
-
-
diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt
index 932b90b29..010b39afa 100644
--- a/src/Mobs/CMakeLists.txt
+++ b/src/Mobs/CMakeLists.txt
@@ -9,6 +9,7 @@ target_sources(
Cow.cpp
Creeper.cpp
EnderDragon.cpp
+ Endermite.cpp
Enderman.cpp
Ghast.cpp
Giant.cpp
@@ -49,6 +50,7 @@ target_sources(
Cow.h
Creeper.h
EnderDragon.h
+ Endermite.h
Enderman.h
Ghast.h
Giant.h
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 656668fb3..3711d7f07 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -149,6 +149,29 @@ void cEnderman::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
return;
}
+ if (m_EMState != CHASING)
+ {
+ cMonster * EndermiteFound = GetMonsterOfTypeInSight(mtEndermite, 64);
+ if (EndermiteFound != nullptr)
+ {
+ SetTarget(EndermiteFound);
+ m_EMState = CHASING;
+ m_bIsScreaming = true;
+ }
+ }
+ else
+ {
+ const auto Target = GetTarget();
+ if (Target != nullptr)
+ {
+ if (!Target->IsTicking())
+ {
+ m_EMState = IDLE;
+ m_bIsScreaming = false;
+ }
+ }
+ }
+
PREPARE_REL_AND_CHUNK(GetPosition().Floor(), a_Chunk);
if (!RelSuccess)
{
diff --git a/src/Mobs/Endermite.cpp b/src/Mobs/Endermite.cpp
new file mode 100644
index 000000000..3a89de98a
--- /dev/null
+++ b/src/Mobs/Endermite.cpp
@@ -0,0 +1,41 @@
+
+#include "Globals.h"
+
+#include "Endermite.h"
+
+#include "../World.h"
+#include "../Chunk.h"
+#include "../Blocks/BlockHandler.h"
+#include "../Blocks/BlockInfested.h"
+
+
+
+
+
+cEndermite::cEndermite() :
+ Super("Endermite", mtEndermite, "entity.endermite.hurt", "entity.endermite.death", "entity.endermite.ambient", 0.4f, 0.3f),
+ m_Timer(0),
+ m_Lifetime(2 * 1000 * 60) // 2 minutes (2 * 1000 (mili to sec) * 60 (sec to min) * 2 because tick = 0.5 sec)
+{
+}
+
+
+
+
+
+void cEndermite::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ Super::Tick(a_Dt, a_Chunk);
+
+ // Not destroying the endermite if a name is set
+ if (m_CustomName.empty())
+ {
+ m_Timer += a_Dt;
+ // Destroy the endermite after 2 minutes
+ if (m_Timer > m_Lifetime)
+ {
+ Destroy();
+ }
+
+ }
+}
diff --git a/src/Mobs/Endermite.h b/src/Mobs/Endermite.h
new file mode 100644
index 000000000..9e0102a07
--- /dev/null
+++ b/src/Mobs/Endermite.h
@@ -0,0 +1,24 @@
+
+#pragma once
+
+#include "AggressiveMonster.h"
+
+
+
+class cEndermite:
+ public cAggressiveMonster
+{
+ using Super = cAggressiveMonster;
+
+ // Endermite should despawn in two minutes
+ std::chrono::milliseconds m_Timer;
+ std::chrono::milliseconds m_Lifetime;
+
+public:
+
+ cEndermite();
+
+ CLASS_PROTODEF(cEndermite)
+
+ void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+} ;
diff --git a/src/Mobs/IncludeAllMonsters.h b/src/Mobs/IncludeAllMonsters.h
index afb79c97c..f31c761fe 100644
--- a/src/Mobs/IncludeAllMonsters.h
+++ b/src/Mobs/IncludeAllMonsters.h
@@ -5,6 +5,7 @@
#include "Cow.h"
#include "Creeper.h"
#include "Enderman.h"
+#include "Endermite.h"
#include "EnderDragon.h"
#include "Ghast.h"
#include "Giant.h"
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index e05264f9f..788d1b66f 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -45,6 +45,7 @@ static const struct
{mtCow, "cow", "Cow", "cow"},
{mtCreeper, "creeper", "Creeper", "creeper"},
{mtEnderman, "enderman", "Enderman", "enderman"},
+ {mtEndermite, "endermite", "Endermite", "endermite"},
{mtEnderDragon, "enderdragon", "EnderDragon", "ender_dragon"},
{mtGhast, "ghast", "Ghast", "ghast"},
{mtGiant, "giant", "Giant", "giant"},
@@ -653,6 +654,11 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI)
Reward = GetRandomProvider().RandInt(6, 8);
break;
}
+ case mtEndermite:
+ {
+ Reward = 3;
+ break;
+ }
case mtBlaze:
{
Reward = 10;
@@ -1286,6 +1292,7 @@ std::unique_ptr<cMonster> cMonster::NewMonsterFromType(eMonsterType a_MobType)
case mtCow: return std::make_unique<cCow>();
case mtCreeper: return std::make_unique<cCreeper>();
case mtEnderDragon: return std::make_unique<cEnderDragon>();
+ case mtEndermite: return std::make_unique<cEndermite>();
case mtEnderman: return std::make_unique<cEnderman>();
case mtGhast: return std::make_unique<cGhast>();
case mtGiant: return std::make_unique<cGiant>();