diff options
author | Mattes D <github@xoft.cz> | 2014-08-01 17:43:18 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-08-01 17:43:18 +0200 |
commit | d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8 (patch) | |
tree | 20fd08c3d16c6e21bfec17b3252b8cd48c923e59 /src/Items/ItemHandler.cpp | |
parent | Merge pull request #1269 from Howaner/BlockEntitys (diff) | |
parent | Compile fix. (diff) | |
download | cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar.gz cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar.bz2 cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar.lz cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar.xz cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.tar.zst cuberite-d2744713bb69ca7c6211fe9b7bdf6fcadd2cadc8.zip |
Diffstat (limited to 'src/Items/ItemHandler.cpp')
-rw-r--r-- | src/Items/ItemHandler.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index acfd1e648..1c1e3b5b9 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: @@ -619,29 +620,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; } |