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 {
15 
16 public:
17 
18  constexpr cItemSeedsHandler(int a_ItemType):
19  Super(a_ItemType)
20  {
21 
22  }
23 
24 
25 
26 
27 
28  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
29  {
30  // Only allow planting seeds from the top side of the block:
31  if (a_ClickedBlockFace != BLOCK_FACE_TOP)
32  {
33  return false;
34  }
35 
37 
38  // Get the produce block based on the seed item:
39  switch (m_ItemType)
40  {
46  case E_ITEM_SEEDS: BlockType = E_BLOCK_CROPS; break;
47  default: UNREACHABLE("Unsupported seed type");
48  }
49 
50  return a_Player.PlaceBlock(a_PlacePosition, BlockType, 0);
51  }
52 
53 
54 
55 
56 
57  virtual bool IsPlaceable(void) const override
58  {
59  return true;
60  }
61 
62 protected:
63  ~cItemSeedsHandler() = default;
64 } ;
65 
67  public cItemSeedsHandler
68 {
70 };
71 
72 
73 
@ E_BLOCK_CARROTS
Definition: BlockType.h:156
@ E_BLOCK_POTATOES
Definition: BlockType.h:157
@ E_BLOCK_MELON_STEM
Definition: BlockType.h:120
@ E_BLOCK_CROPS
Definition: BlockType.h:71
@ E_BLOCK_BEETROOTS
Definition: BlockType.h:226
@ E_BLOCK_PUMPKIN_STEM
Definition: BlockType.h:119
@ E_ITEM_MELON_SEEDS
Definition: BlockType.h:407
@ E_ITEM_CARROT
Definition: BlockType.h:437
@ E_ITEM_BEETROOT_SEEDS
Definition: BlockType.h:482
@ E_ITEM_SEEDS
Definition: BlockType.h:339
@ E_ITEM_PUMPKIN_SEEDS
Definition: BlockType.h:406
@ E_ITEM_POTATO
Definition: BlockType.h:438
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
@ BLOCK_FACE_TOP
Definition: Defines.h:49
#define UNREACHABLE(x)
Definition: Globals.h:288
BlockType
Definition: BlockTypes.h:4
Definition: Player.h:29
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Attempts to place the block in the world with a call to PlaceBlocks.
Definition: Player.cpp:2440
Definition: Item.h:37
const int m_ItemType
Definition: ItemHandler.h:141
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
constexpr cItemSeedsHandler(int a_ItemType)
Definition: ItemSeeds.h:18
~cItemSeedsHandler()=default
virtual bool CommitPlacement(cPlayer &a_Player, const cItem &a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
Performs the actual placement of this placeable item.
Definition: ItemSeeds.h:28
virtual bool IsPlaceable(void) const override
Blocks simply get placed.
Definition: ItemSeeds.h:57