2012-08-11 08:46:09 -04:00
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "../Defines.h"
|
|
|
|
|
|
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);
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False
|
2012-10-18 15:41:29 -04:00
|
|
|
|
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); //eg for fishing or hoes
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Called while the player diggs a block using this item
|
2012-08-18 05:56:28 -04:00
|
|
|
|
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
|
2012-07-15 16:36:34 -04:00
|
|
|
|
virtual void OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z);
|
2012-08-22 12:31:13 -04: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
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
|
2012-07-17 08:02:03 -04:00
|
|
|
|
virtual FoodInfo GetFoodInfo();
|
|
|
|
|
|
2012-08-22 12:31:13 -04: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
|
|
|
|
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Places the current block and removes the item from the player inventory
|
2012-10-18 15:41:29 -04:00
|
|
|
|
virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Indicates if this item is a tool
|
2012-07-15 16:36:34 -04:00
|
|
|
|
virtual bool IsTool();
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Indicates if this item is food
|
2012-07-15 16:36:34 -04:00
|
|
|
|
virtual bool IsFood();
|
|
|
|
|
//Blocks simply get placed
|
|
|
|
|
virtual bool IsPlaceable();
|
|
|
|
|
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// Returns the block type on placement
|
2012-07-15 16:36:34 -04:00
|
|
|
|
virtual BLOCKTYPE GetBlockType();
|
2012-08-22 12:31:13 -04:00
|
|
|
|
//Returns the block meta on placement
|
2012-07-29 08:07:22 -04:00
|
|
|
|
virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage);
|
2012-08-22 12:31:13 -04:00
|
|
|
|
// 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
|
|
|
|
|
2012-10-18 15:41:29 -04:00
|
|
|
|
static cItemHandler *GetItemHandler(int a_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); }
|