summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemHandler.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-07-31 23:04:00 +0200
committerHowaner <franzi.moos@googlemail.com>2014-07-31 23:04:00 +0200
commit84462ba8b20c28136c6a7923323f7cde28a86d70 (patch)
treea568e3ef01c16deff469dd3612023263603cc2f9 /src/Items/ItemHandler.cpp
parentMerge pull request #1267 from mc-server/RoofedForest (diff)
downloadcuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar.gz
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar.bz2
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar.lz
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar.xz
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.tar.zst
cuberite-84462ba8b20c28136c6a7923323f7cde28a86d70.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemHandler.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index d36b5d663..c7cc682ca 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -25,6 +25,7 @@
#include "ItemFishingRod.h"
#include "ItemFlowerPot.h"
#include "ItemFood.h"
+#include "ItemGoldenApple.h"
#include "ItemItemFrame.h"
#include "ItemHoe.h"
#include "ItemLeaves.h"
@@ -106,7 +107,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_BED: return new cItemBedHandler(a_ItemType);
case E_ITEM_BOAT: return new cItemBoatHandler(a_ItemType);
case E_ITEM_BOTTLE_O_ENCHANTING: return new cItemBottleOEnchantingHandler();
- case E_ITEM_BOW: return new cItemBowHandler;
+ case E_ITEM_BOW: return new cItemBowHandler();
case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType);
case E_ITEM_CAKE: return new cItemCakeHandler(a_ItemType);
case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType);
@@ -120,6 +121,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType);
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
+ case E_ITEM_GOLDEN_APPLE: return new cItemGoldenAppleHandler();
case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_MILK: return new cItemMilkHandler();
@@ -212,7 +214,6 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_COOKED_FISH:
case E_ITEM_COOKED_PORKCHOP:
case E_ITEM_COOKIE:
- case E_ITEM_GOLDEN_APPLE:
case E_ITEM_GOLDEN_CARROT:
case E_ITEM_MELON_SLICE:
case E_ITEM_MUSHROOM_SOUP:
@@ -618,29 +619,39 @@ bool cItemHandler::GetPlacementBlockTypeMeta(
+bool cItemHandler::GetEatEffect(cEntityEffect::eType & a_EffectType, int & a_EffectDurationTicks, short & a_EffectIntensity, float & a_Chance)
+{
+ return false;
+}
+
+
+
+
+
bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
{
UNUSED(a_Item);
-
- FoodInfo Info = GetFoodInfo();
+ FoodInfo Info = GetFoodInfo();
if ((Info.FoodLevel > 0) || (Info.Saturation > 0.f))
{
bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
-
- // If consumed and there's chance of foodpoisoning, do it:
- if (Success && (Info.PoisonChance > 0))
+
+ // Give effects
+ cEntityEffect::eType EffectType;
+ int EffectDurationTicks;
+ short EffectIntensity;
+ float Chance;
+ if (Success && GetEatEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance))
{
cFastRandom r1;
- if ((r1.NextInt(100, a_Player->GetUniqueID()) - Info.PoisonChance) <= 0)
+ if (r1.NextFloat() < Chance)
{
- a_Player->FoodPoison(600); // Give the player food poisoning for 30 seconds.
+ a_Player->AddEntityEffect(EffectType, EffectDurationTicks, EffectIntensity, Chance);
}
}
-
return Success;
}
-
return false;
}