Cuberite
A lightweight, fast and extensible game server for Minecraft
SlotArea.h
Go to the documentation of this file.
1 
2 // SlotArea.h
3 
4 // Interfaces to the cSlotArea class representing a contiguous area of slots in a UI window
5 
6 
7 
8 
9 #pragma once
10 
11 #include "../Inventory.h"
12 
13 
14 
15 
16 
17 class cHorse;
18 class cWindow;
19 class cPlayer;
20 class cBeaconEntity;
22 class cChestEntity;
23 class cEnderChestEntity;
24 class cFurnaceEntity;
25 class cMinecartWithChest;
26 class cCraftingRecipe;
27 class cWorld;
28 
29 
30 
31 
32 
33 class cSlotArea
34 {
35 public:
36  cSlotArea(int a_NumSlots, cWindow & a_ParentWindow);
37  virtual ~cSlotArea() {} // force a virtual destructor in all subclasses
38 
39  int GetNumSlots(void) const { return m_NumSlots; }
40 
42  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const = 0;
43 
45  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) = 0;
46 
48  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem);
49 
51  virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem);
52 
54  virtual void DblClicked(cPlayer & a_Player, int a_SlotNum);
55 
57  virtual void MiddleClicked(cPlayer & a_Player, int a_SlotNum);
58 
60  virtual void DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack);
61 
63  virtual void NumberClicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction);
64 
66  virtual void OnPlayerAdded(cPlayer & a_Player);
67 
69  virtual void OnPlayerRemoved(cPlayer & a_Player);
70 
76  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill);
77 
82  virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks);
83 
84 protected:
87 } ;
88 
89 
90 
91 
92 
95  public cSlotArea
96 {
97  typedef cSlotArea super;
98 
99 public:
100  cSlotAreaInventoryBase(int a_NumSlots, int a_SlotOffset, cWindow & a_ParentWindow);
101 
102  // Creative inventory's click handling is somewhat different from survival inventory's, handle that here:
103  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
104 
105  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
106  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
107 
108 protected:
109  int m_SlotOffset; // Index that this area's slot 0 has in the underlying cInventory
110 } ;
111 
112 
113 
114 
115 
119 {
121 
122 public:
123  cSlotAreaInventory(cWindow & a_ParentWindow) :
124  cSlotAreaInventoryBase(cInventory::invInventoryCount, cInventory::invInventoryOffset, a_ParentWindow)
125  {
126  }
127 } ;
128 
129 
130 
131 
132 
136 {
138 
139 public:
140  cSlotAreaHotBar(cWindow & a_ParentWindow) :
141  cSlotAreaInventoryBase(cInventory::invHotbarCount, cInventory::invHotbarOffset, a_ParentWindow)
142  {
143  }
144 } ;
145 
146 
147 
148 
149 
153 {
155 
156 public:
157  cSlotAreaShield(cWindow & a_ParentWindow) :
158  cSlotAreaInventoryBase(cInventory::invShieldCount, cInventory::invShieldOffset, a_ParentWindow)
159  {
160  }
161 };
162 
163 
164 
165 
166 
170 {
171 public:
172  cSlotAreaArmor(cWindow & a_ParentWindow) :
173  cSlotAreaInventoryBase(cInventory::invArmorCount, cInventory::invArmorOffset, a_ParentWindow)
174  {
175  }
176 
178  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
179 
181  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
182 
183  static bool CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item);
184 } ;
185 
186 
187 
188 
189 
192  public cSlotArea,
193  public cItemGrid::cListener
194 {
195  typedef cSlotArea super;
196 
197 public:
198  cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow);
199 
200  virtual ~cSlotAreaItemGrid() override;
201 
202  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
203  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
204 
205 protected:
207 
208  // cItemGrid::cListener overrides:
209  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
210 } ;
211 
212 
213 
214 
215 
220  public cSlotArea
221 {
222  typedef cSlotArea super;
223 
224 public:
225  cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow);
226 
227  // cSlotArea overrides:
228  virtual const cItem * GetSlot (int a_SlotNum, cPlayer & a_Player) const override;
229  virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
230  virtual void OnPlayerAdded (cPlayer & a_Player) override;
231  virtual void OnPlayerRemoved(cPlayer & a_Player) override;
232 
234  void TossItems(cPlayer & a_Player, int a_Begin, int a_End);
235 
236 protected:
237  typedef std::map<UInt32, std::vector<cItem> > cItemMap; // Maps EntityID -> items
238 
239  cItemMap m_Items;
240 
242  cItem * GetPlayerSlots(cPlayer & a_Player);
243 } ;
244 
245 
246 
247 
248 
250  public cSlotAreaTemporary
251 {
253 
254 public:
256  cSlotAreaCrafting(int a_GridSize, cWindow & a_ParentWindow);
257 
258  // cSlotAreaTemporary overrides:
259  virtual void Clicked (cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
260  virtual void DblClicked (cPlayer & a_Player, int a_SlotNum) override;
261  virtual void OnPlayerRemoved(cPlayer & a_Player) override;
262  virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
263 
264  // Distributing items into this area is completely disabled
265  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
266 
267 
268 protected:
271  typedef std::list<std::pair<UInt32, cCraftingRecipe> > cRecipeMap;
272 
274  cRecipeMap m_Recipes;
275 
278  void ClickedResult(cPlayer & a_Player);
279 
282  void ShiftClickedResult(cPlayer & a_Player);
283 
285  void DropClickedResult(cPlayer & a_Player);
286 
288  void UpdateRecipe(cPlayer & a_Player);
289 
291  cCraftingRecipe & GetRecipeForPlayer(cPlayer & a_Player);
292 
294  void HandleCraftItem(const cItem & a_Result, cPlayer & a_Player);
295 } ;
296 
297 
298 
299 
300 
302  public cSlotAreaTemporary
303 {
305 
306 public:
307  cSlotAreaAnvil(cWindow & a_ParentWindow);
308 
309  // cSlotArea overrides:
310  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
311  virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) override;
312  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
313 
314  // cSlotAreaTemporary overrides:
315  virtual void OnPlayerRemoved(cPlayer & a_Player) override;
316 
318  bool CanTakeResultItem(cPlayer & a_Player);
319 
321  void OnTakeResult(cPlayer & a_Player);
322 
324  void UpdateResult(cPlayer & a_Player);
325 
326 protected:
329 
332 } ;
333 
334 
335 
336 
337 
339  public cSlotArea,
340  public cItemGrid::cListener
341 {
342  typedef cSlotArea super;
343 
344 public:
345  cSlotAreaBeacon(cBeaconEntity * a_Beacon, cWindow & a_ParentWindow);
346  virtual ~cSlotAreaBeacon() override;
347 
348  static bool IsPlaceableItem(short a_ItemType);
349 
350  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
351  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
352  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
353  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
354 
355 protected:
357 
358  // cItemGrid::cListener overrides:
359  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
360 } ;
361 
362 
363 
364 
365 
367  public cSlotAreaTemporary
368 {
370 
371 public:
372  cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ);
373 
374  // cSlotArea overrides:
375  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
376  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
377  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
378 
379  // cSlotAreaTemporary overrides:
380  virtual void OnPlayerAdded (cPlayer & a_Player) override;
381  virtual void OnPlayerRemoved(cPlayer & a_Player) override;
382 
383  /* Get the count of bookshelves who stand in the near of the enchanting table */
384  int GetBookshelvesCount(cWorld & a_World);
385 
386 protected:
388  void UpdateResult(cPlayer & a_Player);
389 
390  int m_BlockX, m_BlockY, m_BlockZ;
391 };
392 
393 
394 
395 
396 
398  public cSlotArea
399 {
400 public:
401  cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow);
402 
403  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
404  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
405 
406 protected:
408 } ;
409 
410 
411 
412 
413 
415  public cSlotArea
416 {
417 public:
418  cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow);
419 
420  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
421  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
422 
423 protected:
426 } ;
427 
428 
429 
430 
431 
433  public cSlotArea
434 {
435 public:
436  cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow);
437 
438  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
439  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
440 
441 protected:
443 };
444 
445 
446 
447 
448 
450  public cSlotArea,
451  public cItemGrid::cListener
452 {
453  typedef cSlotArea super;
454 
455 public:
456  cSlotAreaFurnace(cFurnaceEntity * a_Furnace, cWindow & a_ParentWindow);
457 
458  virtual ~cSlotAreaFurnace() override;
459 
460  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
461  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
462  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
463  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
464 
465 protected:
467 
468  // cItemGrid::cListener overrides:
469  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
470 
472  void HandleSmeltItem(const cItem & a_Result, cPlayer & a_Player);
473 } ;
474 
475 
476 
477 
478 
480  public cSlotArea,
481  public cItemGrid::cListener
482 {
483  typedef cSlotArea super;
484 
485 public:
486  cSlotAreaBrewingstand(cBrewingstandEntity * a_Brewingstand, cWindow & a_ParentWindow);
487 
488  virtual ~cSlotAreaBrewingstand() override;
489 
490  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
491  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
492  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
493  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
494 protected:
496 
497  // cItemGrid::cListener overrides:
498  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
499 
501  void HandleBrewedItem(cPlayer & a_Player, const cItem & a_ClickedItem);
502 } ;
503 
504 
505 
506 
507 
509  public cSlotArea
510 {
511 public:
512  cSlotAreaMinecartWithChest(cMinecartWithChest * a_ChestCart, cWindow & a_ParentWindow);
513 
514  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
515  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
516 
517 protected:
519 };
520 
521 
522 
523 
524 
527  public cSlotArea
528 {
529 public:
530  enum
531  {
533  ArmorSlot
534  };
535 
536  cSlotAreaHorse(cHorse & a_Horse, cWindow & a_ParentWindow);
537  virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
538  virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
539  virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
540  virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
541 private:
543 };
544 
545 
546 
547 
cSlotAreaInventoryBase super
Definition: SlotArea.h:137
cSlotArea super
Definition: SlotArea.h:195
virtual void MiddleClicked(cPlayer &a_Player, int a_SlotNum)
Called from Clicked when the action is a middleclick.
Definition: SlotArea.cpp:267
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:117
Slot area holding horse saddle and armor.
Definition: SlotArea.h:526
cChestEntity * m_Chest
Definition: SlotArea.h:407
virtual void Clicked(cPlayer &a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem &a_ClickedItem)
Called when a player clicks in the window.
Definition: SlotArea.cpp:43
cRecipeMap m_Recipes
Definition: SlotArea.h:274
cSlotAreaArmor(cWindow &a_ParentWindow)
Definition: SlotArea.h:172
cChestEntity * m_TopChest
Definition: SlotArea.h:424
Definition: Player.h:27
cChestEntity * m_BottomChest
Definition: SlotArea.h:425
cSlotAreaInventoryBase super
Definition: SlotArea.h:154
virtual void ShiftClicked(cPlayer &a_Player, int a_SlotNum, const cItem &a_ClickedItem)
Called from Clicked when the action is a shiftclick (left or right)
Definition: SlotArea.cpp:217
cSlotAreaInventory(cWindow &a_ParentWindow)
Definition: SlotArea.h:123
cWindow & m_ParentWindow
Definition: SlotArea.h:86
char m_StackSizeToBeUsedInRepair
The stack size of the second item where was used for repair.
Definition: SlotArea.h:331
virtual void OnPlayerAdded(cPlayer &a_Player)
Called when a new player opens the same parent window.
Definition: SlotArea.cpp:338
Definition: Horse.h:11
cSlotAreaTemporary super
Definition: SlotArea.h:369
Handles the armor area of the player&#39;s inventory.
Definition: SlotArea.h:168
cEnderChestEntity * m_EnderChest
Definition: SlotArea.h:442
virtual ~cSlotArea()
Definition: SlotArea.h:37
This class is used as a callback for when a slot changes.
Definition: ItemGrid.h:25
cSlotAreaTemporary super
Definition: SlotArea.h:252
virtual void NumberClicked(cPlayer &a_Player, int a_SlotNum, eClickAction a_ClickAction)
Called from Clicked when the action is a number click.
Definition: SlotArea.cpp:313
int m_NumSlots
Definition: SlotArea.h:85
virtual void DblClicked(cPlayer &a_Player, int a_SlotNum)
Called from Clicked when the action is a caDblClick.
Definition: SlotArea.cpp:237
eClickAction
Individual actions sent in the WindowClick packet.
Definition: Defines.h:73
virtual void DropClicked(cPlayer &a_Player, int a_SlotNum, bool a_DropStack)
Called from Clicked when the action is a drop click.
Definition: SlotArea.cpp:285
cSlotArea super
Definition: SlotArea.h:453
Definition: World.h:65
Handles any slot area that is representing a cItemGrid; same items for all the players.
Definition: SlotArea.h:191
cSlotArea(int a_NumSlots, cWindow &a_ParentWindow)
Definition: SlotArea.cpp:33
std::list< std::pair< UInt32, cCraftingRecipe > > cRecipeMap
Maps player&#39;s EntityID -> current recipe.
Definition: SlotArea.h:271
virtual void DistributeStack(cItem &a_ItemStack, cPlayer &a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill)
Called to store as much of a_ItemStack in the area as possible.
Definition: SlotArea.cpp:356
cBrewingstandEntity * m_Brewingstand
Definition: SlotArea.h:495
cSlotAreaTemporary super
Definition: SlotArea.h:304
int m_MaximumCost
The maximum cost of repairing / renaming in the anvil.
Definition: SlotArea.h:328
cBeaconEntity * m_Beacon
Definition: SlotArea.h:356
int GetNumSlots(void) const
Definition: SlotArea.h:39
cSlotArea super
Definition: SlotArea.h:342
cMinecartWithChest * m_Chest
Definition: SlotArea.h:518
A cSlotArea with items layout that is private to each player and is temporary, such as a crafting gri...
Definition: SlotArea.h:219
virtual void OnPlayerRemoved(cPlayer &a_Player)
Called when one of the players closes the parent window.
Definition: SlotArea.cpp:347
cSlotAreaShield(cWindow &a_ParentWindow)
Definition: SlotArea.h:157
std::map< UInt32, std::vector< cItem > > cItemMap
Definition: SlotArea.h:237
cItemGrid & m_ItemGrid
Definition: SlotArea.h:206
cSlotAreaInventoryBase super
Definition: SlotArea.h:120
Represents a UI window.
Definition: Window.h:53
virtual const cItem * GetSlot(int a_SlotNum, cPlayer &a_Player) const =0
Called to retrieve an item in the specified slot for the specified player.
cSlotAreaHotBar(cWindow &a_ParentWindow)
Definition: SlotArea.h:140
Handles any part of the inventory, using parameters in constructor to distinguish between the parts...
Definition: SlotArea.h:94
Handles the hotbar of each player.
Definition: SlotArea.h:134
virtual void SetSlot(int a_SlotNum, cPlayer &a_Player, const cItem &a_Item)=0
Called to set an item in the specified slot for the specified player.
cFurnaceEntity * m_Furnace
Definition: SlotArea.h:466
cSlotArea super
Definition: SlotArea.h:222
cHorse & m_Horse
Definition: SlotArea.h:542
This class represents the player&#39;s inventory The slots are divided into three areas: ...
Definition: Inventory.h:32
Handles the shield of each player.
Definition: SlotArea.h:151
Definition: Item.h:36
cItemMap m_Items
Definition: SlotArea.h:239
virtual bool CollectItemsToHand(cItem &a_Dragging, cPlayer &a_Player, bool a_CollectFullStacks)
Called on DblClicking to collect all stackable items into hand.
Definition: SlotArea.cpp:394