summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDarkoGNU <42816979+DarkoGNU@users.noreply.github.com>2022-05-07 01:24:50 +0200
committerGitHub <noreply@github.com>2022-05-07 01:24:50 +0200
commit5d00247cce71aae67660623799b66f51bce2b88a (patch)
tree6149ca4c87f652710613eed2b71037e45d2a2979 /src
parentImplement relative SendPlayerMoveLook. Use it in TurnToDirt (#5413) (diff)
downloadcuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar.gz
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar.bz2
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar.lz
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar.xz
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.tar.zst
cuberite-5d00247cce71aae67660623799b66f51bce2b88a.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/SnowGolem.cpp37
-rw-r--r--src/Mobs/SnowGolem.h1
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp1
3 files changed, 39 insertions, 0 deletions
diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp
index 3b66311a1..fabcfb070 100644
--- a/src/Mobs/SnowGolem.cpp
+++ b/src/Mobs/SnowGolem.cpp
@@ -5,6 +5,7 @@
#include "SnowGolem.h"
#include "../BlockInfo.h"
#include "../World.h"
+#include "../Entities/ThrownSnowballEntity.h"
@@ -56,3 +57,39 @@ void cSnowGolem::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
}
+
+
+
+
+
+bool cSnowGolem::Attack(std::chrono::milliseconds a_Dt)
+{
+ UNUSED(a_Dt);
+
+ // Comment inherited from skeletons
+ StopMovingToPosition(); // Todo handle this in a better way, the snowman does some uneeded recalcs due to inStateChasing
+
+ if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0))
+ {
+ auto & Random = GetRandomProvider();
+ Vector3d Inaccuracy = Vector3d(Random.RandReal<double>(-0.75, 0.75), Random.RandReal<double>(-0.75, 0.75), Random.RandReal<double>(-0.75, 0.75));
+
+ // The projectile is launched from the head
+ const auto HeadPos = GetPosition().addedY(1.5);
+ // It aims around the head / chest
+ const auto TargetPos = GetTarget()->GetPosition().addedY(GetTarget()->GetHeight() * 0.75);
+ // With this data, we can calculate the speed
+ const auto Speed = (TargetPos + Inaccuracy - HeadPos) * 5;
+
+ auto Snowball = std::make_unique<cThrownSnowballEntity>(this, HeadPos, Speed);
+ auto SnowballPtr = Snowball.get();
+ if (!SnowballPtr->Initialize(std::move(Snowball), *GetWorld()))
+ {
+ return false;
+ }
+
+ ResetAttackCooldown();
+ return true;
+ }
+ return false;
+}
diff --git a/src/Mobs/SnowGolem.h b/src/Mobs/SnowGolem.h
index 8504965cb..6c6e88868 100644
--- a/src/Mobs/SnowGolem.h
+++ b/src/Mobs/SnowGolem.h
@@ -20,6 +20,7 @@ public:
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
+ virtual bool Attack(std::chrono::milliseconds a_Dt) override;
} ;
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index e50c70051..edb70e632 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -1064,6 +1064,7 @@ public:
case cProjectileEntity::pkFireCharge:
case cProjectileEntity::pkWitherSkull:
case cProjectileEntity::pkEnderPearl:
+ case cProjectileEntity::pkSnowball:
{
break;
}