Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemSeeds.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../World.h"
6 
7 
8 
9 
10 
12  public cItemHandler
13 {
14 public:
15  cItemSeedsHandler(int a_ItemType) :
16  cItemHandler(a_ItemType)
17  {
18 
19  }
20 
21  virtual bool IsPlaceable(void) override
22  {
23  return true;
24  }
25 
26  virtual bool IsFood(void) override
27  {
28  switch (m_ItemType) // Special cases, both a seed and food
29  {
30  case E_ITEM_CARROT:
31  case E_ITEM_POTATO: return true;
32  default: return false;
33  }
34  }
35 
36  virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
37  {
38  UNUSED(a_Item);
39  switch (m_ItemType)
40  {
41  case E_ITEM_CARROT: return FoodInfo(3, 3.6);
42  case E_ITEM_POTATO: return FoodInfo(1, 0.6);
43  default: return FoodInfo(0, 0);
44  }
45  }
46 
48  cWorld * a_World, cPlayer * a_Player,
49  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
50  int a_CursorX, int a_CursorY, int a_CursorZ,
51  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
52  ) override
53  {
54  if (a_BlockFace != BLOCK_FACE_TOP)
55  {
56  // Only allow planting seeds from the top side of the block
57  return false;
58  }
59 
60  // Only allow placement on farmland
61  int X = a_BlockX;
62  int Y = a_BlockY;
63  int Z = a_BlockZ;
64  AddFaceDirection(X, Y, Z, a_BlockFace, true);
65  if (a_World->GetBlock(X, Y, Z) != E_BLOCK_FARMLAND)
66  {
67  return false;
68  }
69 
70  a_BlockMeta = 0;
71  switch (m_ItemType)
72  {
73  case E_ITEM_BEETROOT_SEEDS: a_BlockType = E_BLOCK_BEETROOTS; return true;
74  case E_ITEM_CARROT: a_BlockType = E_BLOCK_CARROTS; return true;
75  case E_ITEM_MELON_SEEDS: a_BlockType = E_BLOCK_MELON_STEM; return true;
76  case E_ITEM_POTATO: a_BlockType = E_BLOCK_POTATOES; return true;
77  case E_ITEM_PUMPKIN_SEEDS: a_BlockType = E_BLOCK_PUMPKIN_STEM; return true;
78  case E_ITEM_SEEDS: a_BlockType = E_BLOCK_CROPS; return true;
79  default: a_BlockType = E_BLOCK_AIR; return true;
80  }
81  }
82 } ;
83 
84 
85 
86 
BLOCKTYPE GetBlock(Vector3i a_BlockPos)
Returns the block type at the specified position.
Definition: World.h:416
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
virtual FoodInfo GetFoodInfo(const cItem *a_Item) override
Returns the FoodInfo for this item.
Definition: ItemSeeds.h:36
Definition: Player.h:27
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
Definition: Defines.h:859
Definition: World.h:65
cItemSeedsHandler(int a_ItemType)
Definition: ItemSeeds.h:15
virtual bool IsPlaceable(void) override
Blocks simply get placed.
Definition: ItemSeeds.h:21
#define UNUSED
Definition: Globals.h:152
virtual bool IsFood(void) override
Indicates if this item is food.
Definition: ItemSeeds.h:26
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
virtual bool GetPlacementBlockTypeMeta(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called when the player right-clicks with this item and IsPlaceable() == true, and OnPlayerPlace() is ...
Definition: ItemSeeds.h:47
Definition: Item.h:36