Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockCauldron.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "../Entities/Player.h"
6 #include "../ClientHandle.h"
7 
8 
9 
10 
11 class cBlockCauldronHandler final :
12  public cBlockHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
23  {
24  return cItem(E_ITEM_CAULDRON, 1, 0);
25  }
26 
27 
28 
29 
30 
31  virtual bool OnUse(
32  cChunkInterface & a_ChunkInterface,
33  cWorldInterface & a_WorldInterface,
34  cPlayer & a_Player,
35  const Vector3i a_BlockPos,
36  eBlockFace a_BlockFace,
37  const Vector3i a_CursorPos
38  ) const override
39  {
40  NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
41  auto EquippedItem = a_Player.GetEquippedItem();
42 
43  switch (EquippedItem.m_ItemType)
44  {
45  case E_ITEM_BUCKET:
46  {
47  if (Meta == 3)
48  {
49  a_ChunkInterface.SetBlockMeta(a_BlockPos, 0);
50  // Give new bucket, filled with fluid when the gamemode is not creative:
51  if (!a_Player.IsGameModeCreative())
52  {
54  }
55  }
56  break;
57  }
59  {
60  if (Meta < 3)
61  {
62  a_ChunkInterface.SetBlockMeta(a_BlockPos, 3);
63  // Give empty bucket back when the gamemode is not creative:
64  if (!a_Player.IsGameModeCreative())
65  {
67  }
69  }
70  break;
71  }
73  {
74  if (Meta > 0)
75  {
76  a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
77  // Give new potion when the gamemode is not creative:
78  if (!a_Player.IsGameModeCreative())
79  {
81  }
83  }
84  break;
85  }
86  case E_ITEM_POTION:
87  {
88  // Refill cauldron with water bottles.
89  if ((Meta < 3) && (EquippedItem.m_ItemDamage == 0))
90  {
91  a_ChunkInterface.SetBlockMeta(Vector3i(a_BlockPos), ++Meta);
92  // Give back an empty bottle when the gamemode is not creative:
93  if (!a_Player.IsGameModeCreative())
94  {
96  }
97  }
98  break;
99  }
101  case E_ITEM_LEATHER_CAP:
104  {
105  // Resets any color to default:
106  if ((Meta > 0) && ((EquippedItem.m_ItemColor.GetRed() != 255) || (EquippedItem.m_ItemColor.GetBlue() != 255) || (EquippedItem.m_ItemColor.GetGreen() != 255)))
107  {
108  a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
109  auto NewItem = cItem(EquippedItem);
110  NewItem.m_ItemColor.Clear();
111  a_Player.ReplaceOneEquippedItemTossRest(NewItem);
112  }
113  break;
114  }
129  {
130  // Resets shulker box color.
131 
132  // TODO: When there is an actual default shulker box add the appropriate changes here! - 19.09.2020 - 12xx12
133  if (Meta == 0)
134  {
135  // The cauldron is empty:
136  break;
137  }
138 
139  // Proceed with normal cleaning:
140  a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
141  auto NewShulker = cItem(EquippedItem);
142  NewShulker.m_ItemType = E_BLOCK_PURPLE_SHULKER_BOX;
143  a_Player.ReplaceOneEquippedItemTossRest(NewShulker);
144 
145  break;
146  }
147  }
148 
149  if (!EquippedItem.GetHandler().IsPlaceable())
150  {
151  // Item not placeable in the first place, our work is done:
152  return true;
153  }
154 
155  // This is a workaround for versions < 1.13, where rclking a cauldron with a block, places a block.
156  // Using cauldrons with blocks was added in 1.13 as part of shulker cleaning.
157  const auto ResendPosition = AddFaceDirection(a_BlockPos, a_BlockFace);
158  a_Player.GetClientHandle()->SendBlockChange(
159  ResendPosition,
160  a_ChunkInterface.GetBlock(ResendPosition),
161  a_ChunkInterface.GetBlockMeta(ResendPosition)
162  );
163 
164  return true;
165  }
166 
167 
168 
169 
170 
171  virtual bool IsUseable() const override
172  {
173  return true;
174  }
175 
176 
177 
178 
179 
180  virtual void OnUpdate(
181  cChunkInterface & a_ChunkInterface,
182  cWorldInterface & a_WorldInterface,
183  cBlockPluginInterface & a_PluginInterface,
184  cChunk & a_Chunk,
185  const Vector3i a_RelPos
186  ) const override
187  {
188  auto WorldPos = a_Chunk.RelativeToAbsolute(a_RelPos);
189  if (!a_WorldInterface.IsWeatherWetAtXYZ(WorldPos.addedY(1)))
190  {
191  // It's not raining at our current location or we do not have a direct view of the sky
192  return;
193  }
194 
195  auto Meta = a_Chunk.GetMeta(a_RelPos);
196  if (Meta < 3)
197  {
198  a_Chunk.SetMeta(a_RelPos, Meta + 1);
199  }
200  }
201 
202 
203 
204 
205 
206  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
207  {
208  UNUSED(a_Meta);
209  return 21;
210  }
211 } ;
212 
213 
214 
215 
@ E_BLOCK_PINK_SHULKER_BOX
Definition: BlockType.h:244
@ E_BLOCK_BLUE_SHULKER_BOX
Definition: BlockType.h:249
@ E_BLOCK_BROWN_SHULKER_BOX
Definition: BlockType.h:250
@ E_BLOCK_LIGHT_BLUE_SHULKER_BOX
Definition: BlockType.h:241
@ E_BLOCK_MAGENTA_SHULKER_BOX
Definition: BlockType.h:240
@ E_BLOCK_CYAN_SHULKER_BOX
Definition: BlockType.h:247
@ E_BLOCK_LIME_SHULKER_BOX
Definition: BlockType.h:243
@ E_BLOCK_PURPLE_SHULKER_BOX
Definition: BlockType.h:248
@ E_BLOCK_ORANGE_SHULKER_BOX
Definition: BlockType.h:239
@ E_BLOCK_GRAY_SHULKER_BOX
Definition: BlockType.h:245
@ E_BLOCK_YELLOW_SHULKER_BOX
Definition: BlockType.h:242
@ E_BLOCK_GREEN_SHULKER_BOX
Definition: BlockType.h:251
@ E_BLOCK_BLACK_SHULKER_BOX
Definition: BlockType.h:253
@ E_BLOCK_LIGHT_GRAY_SHULKER_BOX
Definition: BlockType.h:246
@ E_BLOCK_RED_SHULKER_BOX
Definition: BlockType.h:252
@ E_ITEM_POTION
Definition: BlockType.h:418
@ E_ITEM_LEATHER_PANTS
Definition: BlockType.h:344
@ E_ITEM_GLASS_BOTTLE
Definition: BlockType.h:420
@ E_ITEM_WATER_BUCKET
Definition: BlockType.h:370
@ E_ITEM_LEATHER_TUNIC
Definition: BlockType.h:343
@ E_ITEM_LEATHER_CAP
Definition: BlockType.h:342
@ E_ITEM_BUCKET
Definition: BlockType.h:369
@ E_ITEM_CAULDRON
Definition: BlockType.h:426
@ E_ITEM_LEATHER_BOOTS
Definition: BlockType.h:345
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse)
Modifies the specified coords so that they point to the block adjacent to the one specified through i...
Definition: Defines.cpp:378
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
Vector3< int > Vector3i
Definition: Vector3.h:487
virtual bool IsUseable() const override
Called to check whether this block supports a rclk action.
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Called when the user right clicks the block and the block is useable.
Definition: BlockCauldron.h:31
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockCauldron.h:22
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
virtual void OnUpdate(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_PluginInterface, cChunk &a_Chunk, const Vector3i a_RelPos) const override
Called when the block gets ticked either by a random tick or by a queued tick.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld.
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
BLOCKTYPE GetBlock(Vector3i a_Pos)
virtual bool IsWeatherWetAtXYZ(Vector3i a_Pos)=0
Returns true if it is raining or storming at the specified location, and the rain reaches the specifi...
Definition: Chunk.h:36
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:279
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
Definition: Chunk.h:450
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
Definition: Chunk.h:286
void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
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
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
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
void ReplaceOneEquippedItemTossRest(const cItem &)
Removes one item from the the current equipped item stack, and attempts to add the specified item sta...
Definition: Player.cpp:1745
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
std::unordered_map< CustomStatistic, StatValue > Custom