Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemRawFish.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemFood.h"
5 
6 
7 
8 
9 
10 class cItemRawFishHandler final:
11  public cItemFoodHandler
12 {
14 
15 public:
16 
17  constexpr cItemRawFishHandler(int a_ItemType):
18  Super(a_ItemType, FoodInfo(0, 0))
19  {
20  }
21 
22  virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
23  {
24  static const FoodInfo RawFishInfos[] =
25  {
26  FoodInfo(2, 0.4), // Raw fish
27  FoodInfo(2, 0.2), // Raw salmon
28  FoodInfo(1, 0.2), // Clownfish
29  FoodInfo(1, 0.2), // Pufferfish
30  };
31 
32  if (a_Item->m_ItemDamage >= static_cast<short>(ARRAYCOUNT(RawFishInfos)))
33  {
34  LOGWARNING("Unknown raw fish type '%d'", a_Item->m_ItemDamage);
35  return FoodInfo(0, 0);
36  }
37  return RawFishInfos[a_Item->m_ItemDamage];
38  }
39 
40  virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
41  {
42  if (!Super::EatItem(a_Player, a_Item))
43  {
44  return false;
45  }
46 
48  {
49  a_Player->AddEntityEffect(cEntityEffect::effHunger, 20 * 15, 2);
50  a_Player->AddEntityEffect(cEntityEffect::effNausea, 20 * 15, 1);
51  a_Player->AddEntityEffect(cEntityEffect::effPoison, 20 * 60, 3);
52  }
53 
54 
55  return true;
56  }
57 
58 };
@ E_META_RAW_FISH_PUFFERFISH
Definition: BlockType.h:1078
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:231
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier=1)
Applies an entity effect.
Definition: Pawn.cpp:186
Definition: Player.h:29
Definition: Item.h:37
short m_ItemDamage
Definition: Item.h:165
constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo)
Definition: ItemFood.h:17
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const override
Lets the player eat a selected item.
Definition: ItemFood.h:35
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const override
Lets the player eat a selected item.
Definition: ItemRawFish.h:40
virtual FoodInfo GetFoodInfo(const cItem *a_Item) const override
Returns the FoodInfo for this item.
Definition: ItemRawFish.h:22
constexpr cItemRawFishHandler(int a_ItemType)
Definition: ItemRawFish.h:17