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