Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemFood.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
11  public cItemHandler
12 {
14 
15 public:
16 
17  constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo):
18  Super(a_ItemType),
19  m_FoodInfo(a_FoodInfo)
20  {
21  }
22 
23 
24  virtual bool IsFood(void) const override
25  {
26  return true;
27  }
28 
29  virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
30  {
31  UNUSED(a_Item);
32  return m_FoodInfo;
33  }
34 
35  virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
36  {
37  if (!Super::EatItem(a_Player, a_Item))
38  {
39  return false;
40  }
41 
42  if (!a_Player->IsGameModeCreative())
43  {
44  a_Player->GetInventory().RemoveOneEquippedItem();
45  }
46 
47  return true;
48  }
49 
50 protected:
52 
53  ~cItemFoodHandler() = default;
54 };
55 
57  public cItemFoodHandler
58 {
60 };
#define UNUSED
Definition: Globals.h:72
Definition: Player.h:29
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1025
cInventory & GetInventory(void)
Definition: Player.h:156
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful,...
Definition: Inventory.cpp:232
Definition: Item.h:37
~cItemFoodHandler()=default
constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo)
Definition: ItemFood.h:17
FoodInfo m_FoodInfo
Definition: ItemFood.h:51
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const override
Lets the player eat a selected item.
Definition: ItemFood.h:35
virtual bool IsFood(void) const override
Indicates if this item is food.
Definition: ItemFood.h:24
virtual FoodInfo GetFoodInfo(const cItem *a_Item) const override
Returns the FoodInfo for this item.
Definition: ItemFood.h:29
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const
Lets the player eat a selected item.