summaryrefslogtreecommitdiffstats
path: root/source/items/Item.cpp
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-17 14:02:03 +0200
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-17 14:02:03 +0200
commitf473f13585e1bc901bfeb05cd5a9bb35489595da (patch)
tree48d9f165c1c154ae5baefe9712b990f837edfd37 /source/items/Item.cpp
parentFixed compilation on OS X and maybe *nix as well (diff)
downloadcuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.gz
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.bz2
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.lz
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.xz
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.tar.zst
cuberite-f473f13585e1bc901bfeb05cd5a9bb35489595da.zip
Diffstat (limited to 'source/items/Item.cpp')
-rw-r--r--source/items/Item.cpp55
1 files changed, 45 insertions, 10 deletions
diff --git a/source/items/Item.cpp b/source/items/Item.cpp
index 3dd0a4218..ce72cf8b3 100644
--- a/source/items/Item.cpp
+++ b/source/items/Item.cpp
@@ -23,6 +23,7 @@
#include "ItemShovel.h"
#include "ItemSword.h"
#include "ItemDoor.h"
+#include "ItemFood.h"
#include "../blocks/Block.h"
@@ -109,6 +110,23 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID)
case E_ITEM_WOODEN_DOOR:
return new cItemDoorHandler(a_ItemID);
+ //FOOD:
+ case E_ITEM_BREAD:
+ case E_ITEM_COOKIE:
+ case E_ITEM_MELON_SLICE:
+ case E_ITEM_RAW_CHICKEN:
+ case E_ITEM_COOKED_CHICKEN:
+ case E_ITEM_RAW_BEEF:
+ case E_ITEM_RAW_MEAT:
+ case E_ITEM_STEAK:
+ case E_ITEM_COOKED_MEAT:
+ case E_ITEM_RAW_FISH:
+ case E_ITEM_COOKED_FISH:
+ case E_ITEM_RED_APPLE:
+ case E_ITEM_GOLDEN_APPLE:
+ case E_ITEM_ROTTEN_FLESH:
+ case E_ITEM_SPIDER_EYE:
+ return new cItemFoodHandler(a_ItemID);
default:
return new cItemHandler(a_ItemID);
break;
@@ -159,16 +177,6 @@ void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item
}
-int cItemHandler::GetMaxStackSize()
-{
- return 64;
-}
-
-int cItemHandler::GetMaxDamage()
-{
- return 0;
-}
-
bool cItemHandler::IsTool()
{
return
@@ -230,4 +238,31 @@ void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item,
Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_X, a_Y, a_Z, a_Dir);
if(a_Player->GetGameMode() == eGameMode_Survival)
a_Player->GetInventory().RemoveItem(cItem(a_Item->m_ItemID, 1));
+}
+
+bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item)
+{
+ FoodInfo Info = GetFoodInfo();
+
+ if(Info.FoodLevel > 0 || Info.Saturation > 0.f)
+ {
+ bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
+ if(Success && Info.PoisionChance > 0)
+ {
+ MTRand r1;
+ if((r1.randInt(100) - Info.PoisionChance) <= 0)
+ { //Unlucky guy :D
+ //TODO: Make player ill
+ }
+ }
+
+ return Success;
+ }
+
+ return false;
+}
+
+cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
+{
+ return FoodInfo(0, 0.f);
} \ No newline at end of file