1
0
cuberite-2a/src/Items/ItemPotion.h

84 lines
1.8 KiB
C
Raw Normal View History

#pragma once
#include "../Entities/EntityEffect.h"
2014-06-08 00:56:01 -04:00
#include "../Entities/SplashPotionEntity.h"
class cItemPotionHandler:
2014-06-08 00:56:01 -04:00
public cItemHandler
{
typedef cItemHandler super;
2014-07-17 04:51:44 -04:00
public:
cItemPotionHandler():
super(E_ITEM_POTION)
{
}
// cItemHandler overrides:
virtual bool IsDrinkable(short a_ItemDamage) override
{
2014-07-17 04:51:44 -04:00
// Drinkable potion if 13th lowest bit is set
// Ref.: http://minecraft.gamepedia.com/Potions#Data_value_table
return cEntityEffect::IsPotionDrinkable(a_ItemDamage);
}
2014-07-17 04:51:44 -04:00
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
{
2014-07-14 16:46:15 -04:00
short PotionDamage = a_Item.m_ItemDamage;
2014-07-17 04:51:44 -04:00
// Do not throw non-splash potions:
if (cEntityEffect::IsPotionDrinkable(PotionDamage))
2014-07-14 16:46:15 -04:00
{
return false;
}
Vector3d Pos = a_Player->GetThrowStartPos();
Vector3d Speed = a_Player->GetLookVector() * 7;
2014-06-08 00:56:01 -04:00
if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, cProjectileEntity::pkSplashPotion, a_Player, &a_Player->GetEquippedItem(), &Speed) < 0)
2014-06-08 00:56:01 -04:00
{
return false;
}
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
return true;
}
2014-07-17 04:51:44 -04:00
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
{
2014-07-14 16:46:15 -04:00
short PotionDamage = a_Item->m_ItemDamage;
2014-07-17 04:51:44 -04:00
// Do not drink undrinkable potions:
if (!cEntityEffect::IsPotionDrinkable(a_Item->m_ItemDamage))
2014-07-14 16:46:15 -04:00
{
return false;
}
a_Player->AddEntityEffect(
cEntityEffect::GetPotionEffectType(PotionDamage),
cEntityEffect::GetPotionEffectDuration(PotionDamage),
cEntityEffect::GetPotionEffectIntensity(PotionDamage)
);
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE);
}
return true;
}
};
2014-07-17 04:51:44 -04:00