2012-08-11 08:46:09 -04:00
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
#pragma once
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
#include "../Defines.h"
|
2013-01-11 23:46:01 -05:00
|
|
|
|
#include "../Item.h"
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2012-08-11 08:46:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd:
|
2012-07-15 16:36:34 -04:00
|
|
|
|
class cWorld;
|
|
|
|
|
class cPlayer;
|
|
|
|
|
|
|
|
|
|
|
2012-08-11 08:46:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
class cItemHandler
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-10-18 15:41:29 -04:00
|
|
|
|
cItemHandler(int a_ItemType);
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
/// Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False
|
2013-05-19 14:22:37 -04:00
|
|
|
|
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); //eg for fishing or hoes
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
/// Called while the player diggs a block using this item
|
2013-05-19 14:22:37 -04:00
|
|
|
|
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
/// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
|
2013-05-19 14:22:37 -04:00
|
|
|
|
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z);
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
/// Called after the player has eaten this item.
|
2012-07-15 16:36:34 -04:00
|
|
|
|
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
|
2012-08-11 08:46:09 -04:00
|
|
|
|
|
|
|
|
|
/// Returns the maximum stack size for a given item
|
|
|
|
|
virtual char GetMaxStackSize(void);
|
2012-07-17 08:02:03 -04:00
|
|
|
|
|
|
|
|
|
struct FoodInfo
|
|
|
|
|
{
|
|
|
|
|
FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0)
|
|
|
|
|
{
|
|
|
|
|
FoodLevel = a_FoodLevel;
|
|
|
|
|
Saturation = a_Saturation;
|
|
|
|
|
PoisionChance = a_PoisionChance;
|
|
|
|
|
}
|
|
|
|
|
short FoodLevel;
|
|
|
|
|
float Saturation;
|
|
|
|
|
char PoisionChance; //0 - 100
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
/// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
|
2012-07-17 08:02:03 -04:00
|
|
|
|
virtual FoodInfo GetFoodInfo();
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
/// Lets the player eat a selected item. Returns true if the player ate the item
|
2012-07-17 08:02:03 -04:00
|
|
|
|
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item);
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
/// Indicates if this item is a tool
|
|
|
|
|
virtual bool IsTool(void);
|
|
|
|
|
|
|
|
|
|
/// Indicates if this item is food
|
|
|
|
|
virtual bool IsFood(void);
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
/// Blocks simply get placed
|
|
|
|
|
virtual bool IsPlaceable(void);
|
|
|
|
|
|
|
|
|
|
/** Called before a block is placed into a world.
|
|
|
|
|
The handler should return true to allow placement, false to refuse.
|
|
|
|
|
Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
|
|
|
|
cWorld * a_World, cPlayer * a_Player,
|
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
|
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can<61>t) DEFAULT: False
|
2012-10-03 04:52:11 -04:00
|
|
|
|
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
static cItemHandler * GetItemHandler(int a_ItemType);
|
|
|
|
|
static cItemHandler * GetItemHandler(const cItem & a_Item) { return GetItemHandler(a_Item.m_ItemType); }
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
|
|
|
|
static void Deinit();
|
|
|
|
|
|
|
|
|
|
protected:
|
2012-10-18 15:41:29 -04:00
|
|
|
|
int m_ItemType;
|
|
|
|
|
static cItemHandler *CreateItemHandler(int m_ItemType);
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2012-11-15 13:57:47 -05:00
|
|
|
|
static cItemHandler *m_ItemHandler[2268];
|
2012-07-15 16:36:34 -04:00
|
|
|
|
static bool m_HandlerInitialized; //used to detect if the itemhandlers are initialized
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Short function
|
2012-10-18 15:41:29 -04:00
|
|
|
|
inline cItemHandler *ItemHandler(int a_ItemType) { return cItemHandler::GetItemHandler(a_ItemType); }
|