Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemChorusFruit.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemFood.h"
5 #include "../Entities/Pawn.h"
6 
7 
8 
9 
10 
12  public cItemFoodHandler
13 {
15 
16 public:
17 
18  constexpr cItemChorusFruitHandler(int a_ItemType) :
19  Super(a_ItemType, FoodInfo(4, 2.4))
20  {
21  }
22 
23  virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
24  {
25  cItemHandler::EatItem(a_Player, a_Item);
26 
27  if (!a_Player->IsGameModeCreative())
28  {
29  a_Player->GetInventory().RemoveOneEquippedItem();
30  }
31 
32  // Attempt to find a teleport destination
33  Vector3d Destination;
34  cWorld * World = a_Player->GetWorld();
35  if (cPawn::FindTeleportDestination(*World, 2, 16, Destination, a_Player->GetPosition(), 8))
36  {
37  // Broadcast sound effect to _pre-teleport_ location, then teleport player.
38  World->BroadcastSoundEffect("item.chorus_fruit.teleport", a_Player->GetPosition(), 1, 1);
39  a_Player->TeleportToCoords(Destination.x, Destination.y, Destination.z);
40  }
41  return true;
42  }
43 
44 };
Utilities to allow casting a cWorld to one of its interfaces without including World....
Definition: OpaqueWorld.h:13
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
cWorld * GetWorld(void) const
Definition: Entity.h:190
static bool FindTeleportDestination(cWorld &a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d &a_Destination, const Vector3i a_MinBoxCorner, const Vector3i a_MaxBoxCorner)
Definition: Pawn.cpp:652
Definition: Player.h:29
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
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override
Teleports to the coordinates specified.
Definition: Player.cpp:1404
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful,...
Definition: Inventory.cpp:232
Definition: Item.h:37
constexpr cItemChorusFruitHandler(int a_ItemType)
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const override
Lets the player eat a selected item.
constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo)
Definition: ItemFood.h:17
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item) const
Lets the player eat a selected item.
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
Definition: World.h:53