From 58f35af6e71f11844b9c6c1d1ebd2d7390439cca Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 21:56:01 -0700 Subject: Added splash potion functionality --- src/Items/ItemPotion.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/Items/ItemPotion.h') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index e34b251aa..528268cfe 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -2,12 +2,18 @@ #pragma once #include "../Entities/EntityEffects.h" +#include "../Entities/SplashPotionEntity.h" class cItemPotionHandler: -public cItemHandler + public cItemHandler { typedef cItemHandler super; + int GetPotionName(short a_ItemDamage) + { + return a_ItemDamage & 63; + } + cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) { // Potion effect bits are different from entity effect values @@ -118,6 +124,34 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { + Vector3d Speed = a_Player->GetLookVector() * 10; + + short potion_damage = a_Item.m_ItemDamage; + cProjectileEntity * Projectile = new cSplashPotionEntity(a_Player, + (double)a_BlockX, + (double)a_BlockY, + (double)a_BlockZ, + &Speed, + GetEntityEffectType(potion_damage), + cEntityEffect(GetEntityEffectDuration(potion_damage), + GetEntityEffectIntensity(potion_damage), + a_Player), + GetPotionName(potion_damage)); + if (Projectile == NULL) + { + return false; + } + if (!Projectile->Initialize(*a_World)) + { + delete Projectile; + return false; + } + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + // Called when potion is a splash potion return true; } -- cgit v1.2.3