Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemSnow.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
10 class cItemSnowHandler final :
11  public cItemHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
21  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
22  {
24  NIBBLETYPE Meta;
25  a_Player.GetWorld()->GetBlockTypeMeta(a_PlacePosition, Block, Meta);
26 
27  // Check if incrementing existing snow height:
28  if (Block == E_BLOCK_SNOW)
29  {
30  ASSERT(Meta < 7); // BlockSnow.h ensures that if we replace a snow layer, it won't be at max height.
31  Meta++;
32  }
33  else
34  {
35  // First time placement:
36  Meta = 0;
37  }
38 
39  return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_SNOW, Meta);
40  }
41 };
@ E_BLOCK_SNOW
Definition: BlockType.h:92
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
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
#define ASSERT(x)
Definition: Globals.h:276
cWorld * GetWorld(void) const
Definition: Entity.h:190
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
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
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: ItemSnow.h:21
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Retrieves the block type and meta at the specified coords.
Definition: World.cpp:1779