Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockCake.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "BlockHandler.h"
4 
5 
6 
7 
8 
10  public cBlockHandler
11 {
13 public:
15  super(a_BlockType)
16  {
17  }
18 
19 
20 
21 
22 
23  virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
24  {
25  NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ});
26 
27  if (!a_Player.Feed(2, 0.4))
28  {
29  return false;
30  }
31 
32  if (Meta >= 5)
33  {
34  a_ChunkInterface.DigBlock(a_WorldInterface, {a_BlockX, a_BlockY, a_BlockZ});
35  }
36  else
37  {
38  a_ChunkInterface.SetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}, Meta + 1);
39  }
40  return true;
41  }
42 
43 
44 
45 
46 
47  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
48  {
49  // Give nothing
50  return {};
51  }
52 
53 
54 
55 
56 
57  virtual bool IsUseable(void) override
58  {
59  return true;
60  }
61 
62  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
63  {
64  UNUSED(a_Meta);
65  return 14;
66  }
67 } ;
68 
69 
70 
71 
cBlockCakeHandler(BLOCKTYPE a_BlockType)
Definition: BlockCake.h:14
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
Definition: Player.h:27
cBlockHandler(BLOCKTYPE a_BlockType)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockCake.h:47
bool Feed(int a_Food, double a_Saturation)
Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full".
Definition: Player.cpp:656
#define UNUSED
Definition: Globals.h:152
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
Called if the user right clicks the block and the block is useable returns true if the use was succes...
Definition: BlockCake.h:23
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockCake.h:62
Byte ColourID
Definition: Globals.h:118
Definition: Entity.h:73
virtual bool IsUseable(void) override
Checks if the block can be placed at this point.
Definition: BlockCake.h:57
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData, bool a_ShouldMarkDirty=true, bool a_ShouldInformClient=true)
Sets the meta for the specified block, while keeping the blocktype.
bool DigBlock(cWorldInterface &a_WorldInterface, Vector3i a_BlockPos)
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234