Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemFoodSeeds.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemSeeds.h"
5 #include "../World.h"
6 
7 
8 
9 
10 
12  public cItemSeedsHandler
13 {
15 
16 public:
17 
18  constexpr cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo):
19  Super(a_ItemType),
20  m_FoodInfo(a_FoodInfo)
21  {
22 
23  }
24 
25 
26  virtual bool IsFood(void) const override
27  {
28  return true;
29  }
30 
31  virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
32  {
33  UNUSED(a_Item);
34  return m_FoodInfo;
35  }
36 
37  virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
38  {
39  if (!Super::EatItem(a_Player, a_Item))
40  {
41  return false;
42  }
43 
44  if (!a_Player->IsGameModeCreative())
45  {
46  a_Player->GetInventory().RemoveOneEquippedItem();
47  }
48 
49  return true;
50  }
51 
52 protected:
54 
55 };
#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
virtual bool IsFood(void) const override
Indicates if this item is food.
Definition: ItemFoodSeeds.h:26
virtual FoodInfo GetFoodInfo(const cItem *a_Item) const override
Returns the FoodInfo for this item.
Definition: ItemFoodSeeds.h:31
constexpr cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo)
Definition: ItemFoodSeeds.h:18
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const override
Lets the player eat a selected item.
Definition: ItemFoodSeeds.h:37
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const
Lets the player eat a selected item.
constexpr cItemSeedsHandler(int a_ItemType)
Definition: ItemSeeds.h:18