summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemThrowable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Items/ItemThrowable.h')
-rw-r--r--src/Items/ItemThrowable.h40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h
index daae7658c..606f655e9 100644
--- a/src/Items/ItemThrowable.h
+++ b/src/Items/ItemThrowable.h
@@ -23,22 +23,30 @@ public:
+
+
virtual bool OnItemUse(
- cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
- int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
+ cWorld * a_World,
+ cPlayer * a_Player,
+ cBlockPluginInterface & a_PluginInterface,
+ const cItem & a_HeldItem,
+ const Vector3i a_ClickedBlockPos,
+ eBlockFace a_ClickedBlockFace
) override
{
- Vector3d Pos = a_Player->GetThrowStartPos();
- Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff;
-
- // Play sound
- a_World->BroadcastSoundEffect("entity.arrow.shoot", a_Player->GetPosition() - Vector3d(0, a_Player->GetHeight(), 0), 0.5f, 0.4f / GetRandomProvider().RandReal(0.8f, 1.2f));
+ auto Pos = a_Player->GetThrowStartPos();
+ auto Speed = a_Player->GetLookVector() * m_SpeedCoeff;
+ // Create the projectile:
if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem(), &Speed) == cEntity::INVALID_ID)
{
return false;
}
+ // Play sound:
+ a_World->BroadcastSoundEffect("entity.arrow.shoot", a_Player->GetPosition() - Vector3d(0, a_Player->GetHeight(), 0), 0.5f, 0.4f / GetRandomProvider().RandReal(0.8f, 1.2f));
+
+ // Remove from inventory
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
@@ -48,7 +56,11 @@ public:
}
protected:
+
+ /** The kind of projectile to create when shooting */
cProjectileEntity::eKind m_ProjectileKind;
+
+ /** The speed multiplier (to the player's normalized look vector) to set for the new projectile. */
double m_SpeedCoeff;
} ;
@@ -137,17 +149,23 @@ public:
+
+
virtual bool OnItemUse(
- cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
- int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
+ cWorld * a_World,
+ cPlayer * a_Player,
+ cBlockPluginInterface & a_PluginInterface,
+ const cItem & a_HeldItem,
+ const Vector3i a_ClickedBlockPos,
+ eBlockFace a_ClickedBlockFace
) override
{
- if (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR)
+ if (a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_AIR)
{
return false;
}
- if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem()) == 0)
+ if (a_World->CreateProjectile(Vector3d(a_ClickedBlockPos) + Vector3d(0.5, 1, 0.5), m_ProjectileKind, a_Player, &a_Player->GetEquippedItem()) == 0)
{
return false;
}