Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
cItemHandler Class Reference

#include <ItemHandler.h>

Inheritance diagram for cItemHandler:
Inheritance graph
[legend]

Classes

struct  FoodInfo
 

Public Types

enum  eDurabilityLostAction { dlaAttackEntity , dlaBreakBlock , dlaBreakBlockInstant }
 Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on the specific item used to perform the action. More...
 

Public Member Functions

virtual bool CanHarvestBlock (BLOCKTYPE a_BlockType) const
 Returns whether this tool / item can harvest a specific block (e.g. More...
 
virtual bool CanRepairWithRawMaterial (short a_ItemType) const
 Can the anvil repair this item, when a_Item is the second input? More...
 
constexpr cItemHandler (int a_ItemType)
 
virtual bool EatItem (cPlayer *a_Player, cItem *a_Item) const
 Lets the player eat a selected item. More...
 
virtual float GetBlockBreakingStrength (BLOCKTYPE a_Block) const
 Returns the strength to break a specific block. More...
 
virtual short GetDurabilityLossByAction (eDurabilityLostAction a_Action) const
 Get the durability lost which the item will get, when a specified action was performed. More...
 
virtual FoodInfo GetFoodInfo (const cItem *a_Item) const
 Returns the FoodInfo for this item. More...
 
virtual char GetMaxStackSize (void) const
 Returns the maximum stack size for a given item. More...
 
virtual bool IsDrinkable (short a_ItemDamage) const
 Indicates if this item is drinkable. More...
 
virtual bool IsFood (void) const
 Indicates if this item is food. More...
 
virtual bool IsPlaceable (void) const
 Blocks simply get placed. More...
 
virtual bool OnDiggingBlock (cWorld *a_World, cPlayer *a_Player, const cItem &a_HeldItem, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace) const
 Called while the player digs a block using this item. More...
 
virtual void OnEntityAttack (cPlayer *a_Attacker, cEntity *a_AttackedEntity) const
 Called when a player attacks an entity with this item in hand. More...
 
virtual void OnFoodEaten (cWorld *a_World, cPlayer *a_Player, cItem *a_Item) const
 Called after the player has eaten this item. More...
 
virtual void OnItemShoot (cPlayer *, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const
 Called when the client sends the SHOOT status in the lclk packet (releasing the bow). More...
 
virtual bool OnItemUse (cWorld *a_World, cPlayer *a_Player, cBlockPluginInterface &a_PluginInterface, const cItem &a_HeldItem, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace) const
 Called when the player tries to use the item (right mouse button). More...
 
void OnPlayerPlace (cPlayer &a_Player, const cItem &a_HeldItem, Vector3i a_ClickedPosition, BLOCKTYPE a_ClickedBlockType, NIBBLETYPE a_ClickedBlockMeta, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const
 Called when the player tries to place the item (right mouse button, IsPlaceable() == true). More...
 
virtual void OnUpdate (cWorld *a_World, cPlayer *a_Player, const cItem &a_Item) const
 Called every tick while the item is on the player's inventory (used by maps, for example) - For now, called only for equipped items. More...
 

Protected Member Functions

virtual bool CommitPlacement (cPlayer &a_Player, const cItem &a_HeldItem, Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const
 Performs the actual placement of this placeable item. More...
 
 ~cItemHandler ()=default
 

Static Protected Member Functions

static const cItemHandlerFor (int a_ItemType)
 

Protected Attributes

const int m_ItemType
 

Friends

class cItem
 

Detailed Description

Definition at line 21 of file ItemHandler.h.

Member Enumeration Documentation

◆ eDurabilityLostAction

Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on the specific item used to perform the action.

Enumerator
dlaAttackEntity 
dlaBreakBlock 
dlaBreakBlockInstant 

Definition at line 30 of file ItemHandler.h.

Constructor & Destructor Documentation

◆ cItemHandler()

constexpr cItemHandler::cItemHandler ( int  a_ItemType)
inlineconstexpr

Definition at line 37 of file ItemHandler.h.

◆ ~cItemHandler()

cItemHandler::~cItemHandler ( )
protecteddefault

Member Function Documentation

◆ CanHarvestBlock()

bool cItemHandler::CanHarvestBlock ( BLOCKTYPE  a_BlockType) const
virtual

Returns whether this tool / item can harvest a specific block (e.g.

iron pickaxe can harvest diamond ore, but wooden one can't). Defaults to false unless overridden.

Reimplemented in cItemSwordHandler, cItemShovelHandler, cItemShearsHandler, and cItemPickaxeHandler.

Definition at line 1343 of file ItemHandler.cpp.

◆ CanRepairWithRawMaterial()

bool cItemHandler::CanRepairWithRawMaterial ( short  a_ItemType) const
virtual

Can the anvil repair this item, when a_Item is the second input?

Reimplemented in cItemSwordHandler, cItemShovelHandler, cItemPickaxeHandler, and cItemArmorHandler.

Definition at line 1333 of file ItemHandler.cpp.

◆ CommitPlacement()

bool cItemHandler::CommitPlacement ( cPlayer a_Player,
const cItem a_HeldItem,
Vector3i  a_PlacePosition,
eBlockFace  a_ClickedBlockFace,
Vector3i  a_CursorPosition 
) const
protectedvirtual

◆ EatItem()

bool cItemHandler::EatItem ( cPlayer a_Player,
cItem a_Item 
) const
virtual

◆ For()

const cItemHandler & cItemHandler::For ( int  a_ItemType)
staticprotected

Definition at line 569 of file ItemHandler.cpp.

◆ GetBlockBreakingStrength()

float cItemHandler::GetBlockBreakingStrength ( BLOCKTYPE  a_Block) const
virtual

Returns the strength to break a specific block.

Defaults to 1 unless overriden.

Reimplemented in cItemSwordHandler, cItemShovelHandler, cItemShearsHandler, cItemPickaxeHandler, and cItemAxeHandler.

Definition at line 1466 of file ItemHandler.cpp.

◆ GetDurabilityLossByAction()

short cItemHandler::GetDurabilityLossByAction ( eDurabilityLostAction  a_Action) const
virtual

Get the durability lost which the item will get, when a specified action was performed.

This is only relevant for uses where the damage taken may depend on the item used.

Reimplemented in cItemSwordHandler, cItemShovelHandler, cItemShearsHandler, cItemPickaxeHandler, cItemHoeHandler, and cItemAxeHandler.

Definition at line 1164 of file ItemHandler.cpp.

◆ GetFoodInfo()

cItemHandler::FoodInfo cItemHandler::GetFoodInfo ( const cItem a_Item) const
virtual

Returns the FoodInfo for this item.

(FoodRecovery and Saturation)

Reimplemented in cItemRawFishHandler, cItemFoodSeedsHandler, cItemFoodHandler, and cItemCookedFishHandler.

Definition at line 1456 of file ItemHandler.cpp.

◆ GetMaxStackSize()

char cItemHandler::GetMaxStackSize ( void  ) const
virtual

Returns the maximum stack size for a given item.

Definition at line 1175 of file ItemHandler.cpp.

◆ IsDrinkable()

bool cItemHandler::IsDrinkable ( short  a_ItemDamage) const
virtual

Indicates if this item is drinkable.

Reimplemented in cItemPotionHandler, and cItemMilkHandler.

Definition at line 1312 of file ItemHandler.cpp.

◆ IsFood()

bool cItemHandler::IsFood ( void  ) const
virtual

Indicates if this item is food.

Reimplemented in cItemFoodSeedsHandler, and cItemFoodHandler.

Definition at line 1303 of file ItemHandler.cpp.

◆ IsPlaceable()

bool cItemHandler::IsPlaceable ( void  ) const
virtual

◆ OnDiggingBlock()

bool cItemHandler::OnDiggingBlock ( cWorld a_World,
cPlayer a_Player,
const cItem a_HeldItem,
const Vector3i  a_ClickedBlockPos,
eBlockFace  a_ClickedBlockFace 
) const
virtual

Called while the player digs a block using this item.

Reimplemented in cItemShearsHandler.

Definition at line 1122 of file ItemHandler.cpp.

◆ OnEntityAttack()

void cItemHandler::OnEntityAttack ( cPlayer a_Attacker,
cEntity a_AttackedEntity 
) const
virtual

Called when a player attacks an entity with this item in hand.

Definition at line 1143 of file ItemHandler.cpp.

◆ OnFoodEaten()

void cItemHandler::OnFoodEaten ( cWorld a_World,
cPlayer a_Player,
cItem a_Item 
) const
virtual

Called after the player has eaten this item.

Definition at line 1153 of file ItemHandler.cpp.

◆ OnItemShoot()

virtual void cItemHandler::OnItemShoot ( cPlayer ,
const Vector3i  a_BlockPos,
eBlockFace  a_BlockFace 
) const
inlinevirtual

Called when the client sends the SHOOT status in the lclk packet (releasing the bow).

Reimplemented in cItemBowHandler.

Definition at line 61 of file ItemHandler.h.

◆ OnItemUse()

bool cItemHandler::OnItemUse ( cWorld a_World,
cPlayer a_Player,
cBlockPluginInterface a_PluginInterface,
const cItem a_HeldItem,
const Vector3i  a_ClickedBlockPos,
eBlockFace  a_ClickedBlockFace 
) const
virtual

◆ OnPlayerPlace()

void cItemHandler::OnPlayerPlace ( cPlayer a_Player,
const cItem a_HeldItem,
Vector3i  a_ClickedPosition,
BLOCKTYPE  a_ClickedBlockType,
NIBBLETYPE  a_ClickedBlockMeta,
eBlockFace  a_ClickedBlockFace,
Vector3i  a_CursorPosition 
) const

Called when the player tries to place the item (right mouse button, IsPlaceable() == true).

a_ClickedPosition is the block that has been clicked to place this item. a_ClickedBlockFace is the face has been clicked to place this item. a_CursorPosition is the position of the player's cursor within a_ClickedBlockFace. If the block placement is refused inside this call, it will automatically revert the client-side changes.

Definition at line 1045 of file ItemHandler.cpp.

◆ OnUpdate()

virtual void cItemHandler::OnUpdate ( cWorld a_World,
cPlayer a_Player,
const cItem a_Item 
) const
inlinevirtual

Called every tick while the item is on the player's inventory (used by maps, for example) - For now, called only for equipped items.

Reimplemented in cItemMapHandler.

Definition at line 68 of file ItemHandler.h.

Friends And Related Function Documentation

◆ cItem

friend class cItem
friend

Definition at line 25 of file ItemHandler.h.

Member Data Documentation

◆ m_ItemType

const int cItemHandler::m_ItemType
protected

Definition at line 141 of file ItemHandler.h.


The documentation for this class was generated from the following files: