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

99 lines
2.0 KiB
C
Raw Normal View History

#pragma once
#include "../Entities/EntityEffect.h"
2017-08-06 19:57:44 +00:00
class cItemPotionHandler final:
2014-06-08 04:56:01 +00:00
public cItemHandler
{
2020-04-13 16:38:06 +00:00
using Super = cItemHandler;
2016-02-05 21:45:45 +00:00
2014-07-17 08:51:44 +00:00
public:
using Super::Super;
2016-02-05 21:45:45 +00:00
2014-07-17 08:51:44 +00:00
2014-07-17 08:51:44 +00:00
// cItemHandler overrides:
virtual bool IsDrinkable(short a_ItemDamage) const override
{
2014-07-17 08:51:44 +00:00
// Drinkable potion if 13th lowest bit is set
2017-08-24 09:19:40 +00:00
// Ref.: https://minecraft.gamepedia.com/Potions#Data_value_table
return cEntityEffect::IsPotionDrinkable(a_ItemDamage);
}
2014-07-17 08:51:44 +00:00
2016-02-05 21:45:45 +00:00
virtual bool OnItemUse(
cWorld * a_World,
cPlayer * a_Player,
cBlockPluginInterface & a_PluginInterface,
const cItem & a_HeldItem,
const Vector3i a_ClickedBlockPos,
eBlockFace a_ClickedBlockFace
) const override
{
short PotionDamage = a_HeldItem.m_ItemDamage;
2016-02-05 21:45:45 +00:00
2014-07-17 08:51:44 +00:00
// Do not throw non-splash potions:
if (cEntityEffect::IsPotionDrinkable(PotionDamage))
2014-07-14 20:46:15 +00:00
{
return false;
}
2016-02-05 21:45:45 +00:00
Vector3d Pos = a_Player->GetThrowStartPos();
Vector3d Speed = a_Player->GetLookVector() * 14;
// 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));
2016-02-05 21:45:45 +00:00
2015-03-21 14:18:17 +00:00
if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, cProjectileEntity::pkSplashPotion, a_Player, &a_Player->GetEquippedItem(), &Speed) == cEntity::INVALID_ID)
2014-06-08 04:56:01 +00:00
{
return false;
}
2016-02-05 21:45:45 +00:00
2014-06-08 04:56:01 +00:00
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
2016-02-05 21:45:45 +00:00
return true;
}
2016-02-05 21:45:45 +00:00
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
{
2014-07-14 20:46:15 +00:00
short PotionDamage = a_Item->m_ItemDamage;
2016-02-05 21:45:45 +00:00
2014-07-17 08:51:44 +00:00
// Do not drink undrinkable potions:
if (!cEntityEffect::IsPotionDrinkable(a_Item->m_ItemDamage))
2014-07-14 20:46:15 +00:00
{
return false;
}
2016-02-05 21:45:45 +00:00
a_Player->AddEntityEffect(
cEntityEffect::GetPotionEffectType(PotionDamage),
cEntityEffect::GetPotionEffectDuration(PotionDamage),
cEntityEffect::GetPotionEffectIntensity(PotionDamage)
);
if (!a_Player->IsGameModeCreative())
{
a_Player->ReplaceOneEquippedItemTossRest(cItem(E_ITEM_GLASS_BOTTLE));
}
return true;
}
};
2014-07-17 08:51:44 +00:00