Cuberite
A lightweight, fast and extensible game server for Minecraft
FlowerPotEntity.cpp
Go to the documentation of this file.
1 
2 // FlowerPotEntity.cpp
3 
4 // Implements the cFlowerPotEntity class representing a single flower pot in the world
5 
6 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
7 #include "FlowerPotEntity.h"
8 #include "../Entities/Player.h"
9 #include "../ClientHandle.h"
10 #include "../Item.h"
11 
12 
13 
14 
15 
16 cFlowerPotEntity::cFlowerPotEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World):
17  Super(a_BlockType, a_BlockMeta, a_Pos, a_World)
18 {
19  ASSERT(a_BlockType == E_BLOCK_FLOWER_POT);
20 }
21 
22 
23 
24 
25 
27 {
28  return cItem(m_Item);
29 }
30 
31 
32 
33 
34 
36 {
37  Super::CopyFrom(a_Src);
38  auto & src = static_cast<const cFlowerPotEntity &>(a_Src);
39  m_Item = src.m_Item;
40 }
41 
42 
43 
44 
45 
47 {
48  if (IsItemInPot())
49  {
50  return false;
51  }
52 
54 
55  cItem SelectedItem = a_Player->GetInventory().GetEquippedItem();
56  if (IsFlower(SelectedItem.m_ItemType, SelectedItem.m_ItemDamage))
57  {
58  m_Item = SelectedItem.CopyOne();
59  if (!a_Player->IsGameModeCreative())
60  {
61  a_Player->GetInventory().RemoveOneEquippedItem();
62  }
64  }
65  return true;
66 }
67 
68 
69 
70 
71 
73 {
74  a_Client.SendUpdateBlockEntity(*this);
75 }
76 
77 
78 
79 
80 
81 bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData)
82 {
83  switch (m_ItemType)
84  {
85  case E_BLOCK_DANDELION:
86  case E_BLOCK_FLOWER:
87  case E_BLOCK_CACTUS:
90  case E_BLOCK_SAPLING:
91  case E_BLOCK_DEAD_BUSH:
92  {
93  return true;
94  }
95  case E_BLOCK_TALL_GRASS:
96  {
97  return (m_ItemData == static_cast<short>(2));
98  }
99  default:
100  {
101  return false;
102  }
103  }
104 }
@ E_BLOCK_DEAD_BUSH
Definition: BlockType.h:42
@ E_BLOCK_FLOWER
Definition: BlockType.h:48
@ E_BLOCK_CACTUS
Definition: BlockType.h:95
@ E_BLOCK_DANDELION
Definition: BlockType.h:47
@ E_BLOCK_BROWN_MUSHROOM
Definition: BlockType.h:49
@ E_BLOCK_RED_MUSHROOM
Definition: BlockType.h:50
@ E_BLOCK_SAPLING
Definition: BlockType.h:16
@ E_BLOCK_FLOWER_POT
Definition: BlockType.h:155
@ E_BLOCK_TALL_GRASS
Definition: BlockType.h:41
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define ASSERT(x)
Definition: Globals.h:276
Vector3i GetPos() const
Definition: BlockEntity.h:90
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: BlockEntity.cpp:66
cWorld * m_World
Definition: BlockEntity.h:126
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
bool IsItemInPot(void)
Is a flower in the pot?
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
cFlowerPotEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Creates a new flowerpot entity at the specified block coords.
static bool IsFlower(short m_ItemType, short m_ItemData)
virtual cItems ConvertToPickups() const override
Returns the contents of this block entity that it would drop if broken.
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
Definition: Player.h:237
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
const cItem & GetEquippedItem(void) const
Returns current equiped item.
Definition: Inventory.cpp:463
Definition: Item.h:37
short m_ItemType
Definition: Item.h:163
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
Definition: Item.cpp:93
short m_ItemDamage
Definition: Item.h:165
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
std::unordered_map< CustomStatistic, StatValue > Custom
Definition: World.h:53
virtual void BroadcastBlockEntity(Vector3i a_BlockPos, const cClientHandle *a_Exclude=nullptr) override
If there is a block entity at the specified coods, sends it to all clients except a_Exclude.