From 2123173202554487386697625342b7ba21744960 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 6 Jun 2014 21:55:23 -0700 Subject: Player: Removed food-poisoning-specific code, set duration to 30 seconds http://minecraft.gamepedia.com/Hunger#Behavior --- src/Items/ItemHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index d97f986ba..67740e860 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -577,7 +577,7 @@ bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item) cFastRandom r1; if ((r1.NextInt(100, a_Player->GetUniqueID()) - Info.PoisonChance) <= 0) { - a_Player->FoodPoison(300); + a_Player->FoodPoison(600); // Give the player food poisoning for 30 seconds. } } -- cgit v1.2.3 From 1eb04a48ee3ec4114adc4334e6fbcc7561834025 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 13:45:00 -0700 Subject: Implemented milk, added documentation to Pawn.h --- src/Items/ItemHandler.cpp | 19 ++++++++++++++++++- src/Items/ItemHandler.h | 3 +++ src/Items/ItemMilk.h | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Items/ItemMilk.h (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 67740e860..83be87b9e 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -19,6 +19,7 @@ #include "ItemCloth.h" #include "ItemComparator.h" #include "ItemDoor.h" +#include "ItemMilk.h" #include "ItemDye.h" #include "ItemEmptyMap.h" #include "ItemFishingRod.h" @@ -119,6 +120,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType); case E_ITEM_MAP: return new cItemMapHandler(); + case E_ITEM_MILK: return new cItemMilkHandler(); case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType); @@ -475,7 +477,6 @@ bool cItemHandler::IsFood(void) case E_ITEM_BREAD: case E_ITEM_RAW_PORKCHOP: case E_ITEM_COOKED_PORKCHOP: - case E_ITEM_MILK: case E_ITEM_RAW_FISH: case E_ITEM_COOKED_FISH: case E_ITEM_COOKIE: @@ -501,6 +502,22 @@ bool cItemHandler::IsFood(void) +bool cItemHandler::IsDrinkable(void) +{ + switch (m_ItemType) + { + case E_ITEM_MILK: + { + return true; + } + } // switch (m_ItemType) + return false; +} + + + + + bool cItemHandler::IsPlaceable(void) { // We can place any block that has a corresponding E_BLOCK_TYPE: diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index e13198cd7..3a25a3f9d 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -82,6 +82,9 @@ public: /** Indicates if this item is food */ virtual bool IsFood(void); + /** Indicates if this item is drinkable */ + virtual bool IsDrinkable(void); + /** Blocks simply get placed */ virtual bool IsPlaceable(void); diff --git a/src/Items/ItemMilk.h b/src/Items/ItemMilk.h new file mode 100644 index 000000000..8569c8cbe --- /dev/null +++ b/src/Items/ItemMilk.h @@ -0,0 +1,26 @@ + +#pragma once + +class cItemMilkHandler: + public cItemHandler +{ + typedef cItemHandler super; +public: + cItemMilkHandler(): + super(E_ITEM_MILK) + { + } + + virtual bool IsDrinkable(void) override + { + return true; + } + + virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override + { + a_Player->ClearEntityEffects(); + a_Player->GetInventory().RemoveOneEquippedItem(); + a_Player->GetInventory().AddItem(E_ITEM_BUCKET); + return true; + } +}; -- cgit v1.2.3 From 2185c72c2ca2d66b238d7d3234c173bd820d32ac Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 16:32:37 -0700 Subject: Implemented drinkable potions, noeffect entity effect, Clears entity effects on death --- src/Items/ItemHandler.cpp | 6 +- src/Items/ItemHandler.h | 2 +- src/Items/ItemMilk.h | 4 +- src/Items/ItemPotion.h | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 src/Items/ItemPotion.h (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 83be87b9e..f847c8ffa 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -35,6 +35,7 @@ #include "ItemNetherWart.h" #include "ItemPainting.h" #include "ItemPickaxe.h" +#include "ItemPotion.h" #include "ItemThrowable.h" #include "ItemRedstoneDust.h" #include "ItemRedstoneRepeater.h" @@ -124,6 +125,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType); case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType); + case E_ITEM_POTIONS: return new cItemPotionHandler(); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); @@ -502,8 +504,10 @@ bool cItemHandler::IsFood(void) -bool cItemHandler::IsDrinkable(void) +bool cItemHandler::IsDrinkable(const cItem * a_Item) { + UNUSED(a_Item); + switch (m_ItemType) { case E_ITEM_MILK: diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 3a25a3f9d..ead2c9769 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -83,7 +83,7 @@ public: virtual bool IsFood(void); /** Indicates if this item is drinkable */ - virtual bool IsDrinkable(void); + virtual bool IsDrinkable(const cItem * a_Item); /** Blocks simply get placed */ virtual bool IsPlaceable(void); diff --git a/src/Items/ItemMilk.h b/src/Items/ItemMilk.h index 8569c8cbe..62506a223 100644 --- a/src/Items/ItemMilk.h +++ b/src/Items/ItemMilk.h @@ -11,13 +11,15 @@ public: { } - virtual bool IsDrinkable(void) override + virtual bool IsDrinkable(const cItem * a_Item) override { + UNUSED(a_Item); return true; } virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { + UNUSED(a_Item); a_Player->ClearEntityEffects(); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_BUCKET); diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h new file mode 100644 index 000000000..e34b251aa --- /dev/null +++ b/src/Items/ItemPotion.h @@ -0,0 +1,137 @@ + +#pragma once + +#include "../Entities/EntityEffects.h" + +class cItemPotionHandler: +public cItemHandler +{ + typedef cItemHandler super; + + cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) + { + // Potion effect bits are different from entity effect values + // For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits + switch (a_ItemDamage & 15) + { + case 1: return cEntityEffect::efRegeneration; + case 2: return cEntityEffect::efSpeed; + case 3: return cEntityEffect::efFireResistance; + case 4: return cEntityEffect::efPoison; + case 5: return cEntityEffect::efInstantHealth; + case 6: return cEntityEffect::efNightVision; + case 8: return cEntityEffect::efWeakness; + case 9: return cEntityEffect::efStrength; + case 10: return cEntityEffect::efSlowness; + case 12: return cEntityEffect::efInstantDamage; + case 13: return cEntityEffect::efWaterBreathing; + case 14: return cEntityEffect::efInvisibility; + + // No effect potions + case 0: + case 7: + case 11: + case 15: + { + break; + } + } + + return cEntityEffect::efNoEffect; + } + + short GetEntityEffectIntensity(short a_ItemDamage) + { + // Level II potion if fifth bit is set + if (a_ItemDamage & 32) return 1; + else return 0; + } + + int GetEntityEffectDuration(short a_ItemDamage) + { + // Base duration in ticks + int base = 0; + double tier_multi = 1, ext_multi = 1, splash_multi = 1; + + switch (GetEntityEffectType(a_ItemDamage)) + { + case cEntityEffect::efRegeneration: + case cEntityEffect::efPoison: + { + base = 900; + break; + } + + case cEntityEffect::efSpeed: + case cEntityEffect::efFireResistance: + case cEntityEffect::efNightVision: + case cEntityEffect::efStrength: + case cEntityEffect::efWaterBreathing: + case cEntityEffect::efInvisibility: + { + base = 3600; + break; + } + + case cEntityEffect::efWeakness: + case cEntityEffect::efSlowness: + { + base = 1800; + break; + } + } + + // If potion is level 2, half the duration. If not, stays the same + tier_multi = GetEntityEffectIntensity(a_ItemDamage) > 0 ? 0.5 : 1; + + // If potion is extended, multiply duration by 8/3. If not, stays the same + // Extended potion if sixth bit is set + ext_multi = a_ItemDamage & 64 ? (8.0/3.0) : 1; + + // If potion is splash potion, multiply duration by 3/4. If not, stays the same + splash_multi = !IsDrinkable(a_ItemDamage) ? 0.75 : 1; + + // For reference: http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit + // http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit + // http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit + + return base * tier_multi * ext_multi * splash_multi; + } + + bool IsDrinkable(short a_ItemDamage) + { + // Drinkable potion if 13th bit is set + // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table + return a_ItemDamage & 8192; + } + +public: + cItemPotionHandler(): + super(E_ITEM_POTIONS) + { + } + + virtual bool IsDrinkable(const cItem * a_Item) override + { + return IsDrinkable(a_Item->m_ItemDamage); + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + // Called when potion is a splash potion + return true; + } + + virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override + { + // Called when potion is a drinkable potion + short potion_damage = a_Item->m_ItemDamage; + a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), + cEntityEffect(GetEntityEffectDuration(potion_damage), + GetEntityEffectIntensity(potion_damage), + a_Player)); + a_Player->GetInventory().RemoveOneEquippedItem(); + a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); + return true; + } +}; -- cgit v1.2.3 From 58f35af6e71f11844b9c6c1d1ebd2d7390439cca Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 7 Jun 2014 21:56:01 -0700 Subject: Added splash potion functionality --- src/Items/ItemPotion.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index e34b251aa..528268cfe 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -2,12 +2,18 @@ #pragma once #include "../Entities/EntityEffects.h" +#include "../Entities/SplashPotionEntity.h" class cItemPotionHandler: -public cItemHandler + public cItemHandler { typedef cItemHandler super; + int GetPotionName(short a_ItemDamage) + { + return a_ItemDamage & 63; + } + cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) { // Potion effect bits are different from entity effect values @@ -118,6 +124,34 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { + Vector3d Speed = a_Player->GetLookVector() * 10; + + short potion_damage = a_Item.m_ItemDamage; + cProjectileEntity * Projectile = new cSplashPotionEntity(a_Player, + (double)a_BlockX, + (double)a_BlockY, + (double)a_BlockZ, + &Speed, + GetEntityEffectType(potion_damage), + cEntityEffect(GetEntityEffectDuration(potion_damage), + GetEntityEffectIntensity(potion_damage), + a_Player), + GetPotionName(potion_damage)); + if (Projectile == NULL) + { + return false; + } + if (!Projectile->Initialize(*a_World)) + { + delete Projectile; + return false; + } + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + // Called when potion is a splash potion return true; } -- cgit v1.2.3 From 73cea7065db458da7704917788ac80b75e042d6e Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 03:27:22 -0700 Subject: Entity effect type: use 'eff' as a prefix instead of 'ef' --- src/Items/ItemPotion.h | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 528268cfe..4c67e9dc7 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -20,18 +20,18 @@ class cItemPotionHandler: // For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits switch (a_ItemDamage & 15) { - case 1: return cEntityEffect::efRegeneration; - case 2: return cEntityEffect::efSpeed; - case 3: return cEntityEffect::efFireResistance; - case 4: return cEntityEffect::efPoison; - case 5: return cEntityEffect::efInstantHealth; - case 6: return cEntityEffect::efNightVision; - case 8: return cEntityEffect::efWeakness; - case 9: return cEntityEffect::efStrength; - case 10: return cEntityEffect::efSlowness; - case 12: return cEntityEffect::efInstantDamage; - case 13: return cEntityEffect::efWaterBreathing; - case 14: return cEntityEffect::efInvisibility; + case 1: return cEntityEffect::effRegeneration; + case 2: return cEntityEffect::effSpeed; + case 3: return cEntityEffect::effFireResistance; + case 4: return cEntityEffect::effPoison; + case 5: return cEntityEffect::effInstantHealth; + case 6: return cEntityEffect::effNightVision; + case 8: return cEntityEffect::effWeakness; + case 9: return cEntityEffect::effStrength; + case 10: return cEntityEffect::effSlowness; + case 12: return cEntityEffect::effInstantDamage; + case 13: return cEntityEffect::effWaterBreathing; + case 14: return cEntityEffect::effInvisibility; // No effect potions case 0: @@ -43,7 +43,7 @@ class cItemPotionHandler: } } - return cEntityEffect::efNoEffect; + return cEntityEffect::effNoEffect; } short GetEntityEffectIntensity(short a_ItemDamage) @@ -61,26 +61,26 @@ class cItemPotionHandler: switch (GetEntityEffectType(a_ItemDamage)) { - case cEntityEffect::efRegeneration: - case cEntityEffect::efPoison: + case cEntityEffect::effRegeneration: + case cEntityEffect::effPoison: { base = 900; break; } - case cEntityEffect::efSpeed: - case cEntityEffect::efFireResistance: - case cEntityEffect::efNightVision: - case cEntityEffect::efStrength: - case cEntityEffect::efWaterBreathing: - case cEntityEffect::efInvisibility: + case cEntityEffect::effSpeed: + case cEntityEffect::effFireResistance: + case cEntityEffect::effNightVision: + case cEntityEffect::effStrength: + case cEntityEffect::effWaterBreathing: + case cEntityEffect::effInvisibility: { base = 3600; break; } - case cEntityEffect::efWeakness: - case cEntityEffect::efSlowness: + case cEntityEffect::effWeakness: + case cEntityEffect::effSlowness: { base = 1800; break; @@ -127,16 +127,16 @@ public: Vector3d Speed = a_Player->GetLookVector() * 10; short potion_damage = a_Item.m_ItemDamage; - cProjectileEntity * Projectile = new cSplashPotionEntity(a_Player, - (double)a_BlockX, - (double)a_BlockY, - (double)a_BlockZ, - &Speed, - GetEntityEffectType(potion_damage), - cEntityEffect(GetEntityEffectDuration(potion_damage), - GetEntityEffectIntensity(potion_damage), - a_Player), - GetPotionName(potion_damage)); + cSplashPotionEntity * Projectile = new cSplashPotionEntity(a_Player, + (double)a_BlockX, + (double)a_BlockY, + (double)a_BlockZ, + &Speed, + GetEntityEffectType(potion_damage), + cEntityEffect(GetEntityEffectDuration(potion_damage), + GetEntityEffectIntensity(potion_damage), + a_Player), + GetPotionName(potion_damage)); if (Projectile == NULL) { return false; -- cgit v1.2.3 From a1a8b7c0eee2189dfc129eb366edb43a315749f9 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 16:31:18 -0700 Subject: Splash potion: Adjusted speed, fixed spawn position --- src/Items/ItemPotion.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 4c67e9dc7..029bb52cd 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -124,14 +124,11 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - Vector3d Speed = a_Player->GetLookVector() * 10; + Vector3d Pos = a_Player->GetThrowStartPos(); + Vector3d Speed = a_Player->GetLookVector() * 7; short potion_damage = a_Item.m_ItemDamage; - cSplashPotionEntity * Projectile = new cSplashPotionEntity(a_Player, - (double)a_BlockX, - (double)a_BlockY, - (double)a_BlockZ, - &Speed, + cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), -- cgit v1.2.3 From 3766ac96d77329c679d01d1ab1a846384acab42f Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 17:06:15 -0700 Subject: ItemHandler: changed IsDrinkable() to take a short argument --- src/Items/ItemHandler.cpp | 4 ++-- src/Items/ItemHandler.h | 4 ++-- src/Items/ItemMilk.h | 4 ++-- src/Items/ItemPotion.h | 13 ++++--------- 4 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index f847c8ffa..3d13af3a7 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -504,9 +504,9 @@ bool cItemHandler::IsFood(void) -bool cItemHandler::IsDrinkable(const cItem * a_Item) +bool cItemHandler::IsDrinkable(short a_ItemDamage) { - UNUSED(a_Item); + UNUSED(a_ItemDamage); switch (m_ItemType) { diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index ead2c9769..cffca11ab 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -83,7 +83,7 @@ public: virtual bool IsFood(void); /** Indicates if this item is drinkable */ - virtual bool IsDrinkable(const cItem * a_Item); + virtual bool IsDrinkable(short a_ItemDamage); /** Blocks simply get placed */ virtual bool IsPlaceable(void); @@ -102,7 +102,7 @@ public: 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�t) DEFAULT: False */ + /** Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can't) DEFAULT: False */ virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType); static cItemHandler * GetItemHandler(int a_ItemType); diff --git a/src/Items/ItemMilk.h b/src/Items/ItemMilk.h index 62506a223..db7bc13be 100644 --- a/src/Items/ItemMilk.h +++ b/src/Items/ItemMilk.h @@ -11,9 +11,9 @@ public: { } - virtual bool IsDrinkable(const cItem * a_Item) override + virtual bool IsDrinkable(short a_ItemDamage) override { - UNUSED(a_Item); + UNUSED(a_ItemDamage); return true; } diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 029bb52cd..c2441fa48 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -104,22 +104,17 @@ class cItemPotionHandler: return base * tier_multi * ext_multi * splash_multi; } - bool IsDrinkable(short a_ItemDamage) - { - // Drinkable potion if 13th bit is set - // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table - return a_ItemDamage & 8192; - } - public: cItemPotionHandler(): super(E_ITEM_POTIONS) { } - virtual bool IsDrinkable(const cItem * a_Item) override + virtual bool IsDrinkable(short a_ItemDamage) override { - return IsDrinkable(a_Item->m_ItemDamage); + // Drinkable potion if 13th bit is set + // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table + return a_ItemDamage & 8192; } virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override -- cgit v1.2.3 From 68011a004a83adc793f0df563cc924c5a2b7dddc Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 8 Jun 2014 17:17:30 -0700 Subject: Removed long function wrapping --- src/Items/ItemPotion.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index c2441fa48..40748d71c 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -123,12 +123,7 @@ public: Vector3d Speed = a_Player->GetLookVector() * 7; short potion_damage = a_Item.m_ItemDamage; - cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, - GetEntityEffectType(potion_damage), - cEntityEffect(GetEntityEffectDuration(potion_damage), - GetEntityEffectIntensity(potion_damage), - a_Player), - GetPotionName(potion_damage)); + cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player), GetPotionName(potion_damage)); if (Projectile == NULL) { return false; @@ -152,10 +147,7 @@ public: { // Called when potion is a drinkable potion short potion_damage = a_Item->m_ItemDamage; - a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), - cEntityEffect(GetEntityEffectDuration(potion_damage), - GetEntityEffectIntensity(potion_damage), - a_Player)); + a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player)); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; -- cgit v1.2.3 From 5b2b6e06150b6299d1e19374be092c0858b0e3a8 Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 12 Jun 2014 19:50:02 -0700 Subject: Pawn: renamed HandleEntityEffects to HandleEntityEffect Exported entity effect functions for ToLua and documented them in APIDesc.lua --- src/Items/ItemPotion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 40748d71c..2c5760e34 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -128,7 +128,7 @@ public: { return false; } - if (!Projectile->Initialize(*a_World)) + if (!Projectile->Initialize(a_World)) { delete Projectile; return false; -- cgit v1.2.3 From 045ae2ef2c0d72b4902fa5151aad095823da9300 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 09:49:42 +0200 Subject: Fixed MSVC compilation. --- src/Items/ItemPotion.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 2c5760e34..200c13cab 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -57,7 +57,7 @@ class cItemPotionHandler: { // Base duration in ticks int base = 0; - double tier_multi = 1, ext_multi = 1, splash_multi = 1; + double TierCoeff = 1, ExtCoeff = 1, SplashCoeff = 1; switch (GetEntityEffectType(a_ItemDamage)) { @@ -88,20 +88,20 @@ class cItemPotionHandler: } // If potion is level 2, half the duration. If not, stays the same - tier_multi = GetEntityEffectIntensity(a_ItemDamage) > 0 ? 0.5 : 1; + TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1; // If potion is extended, multiply duration by 8/3. If not, stays the same // Extended potion if sixth bit is set - ext_multi = a_ItemDamage & 64 ? (8.0/3.0) : 1; + ExtCoeff = (a_ItemDamage & 64) ? (8.0/3.0) : 1; // If potion is splash potion, multiply duration by 3/4. If not, stays the same - splash_multi = !IsDrinkable(a_ItemDamage) ? 0.75 : 1; + SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75; // For reference: http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit // http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit // http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit - return base * tier_multi * ext_multi * splash_multi; + return (int)(base * TierCoeff * ExtCoeff * SplashCoeff); } public: @@ -114,7 +114,7 @@ public: { // Drinkable potion if 13th bit is set // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table - return a_ItemDamage & 8192; + return ((a_ItemDamage & 8192) != 0); } virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override @@ -128,7 +128,7 @@ public: { return false; } - if (!Projectile->Initialize(a_World)) + if (!Projectile->Initialize(*a_World)) { delete Projectile; return false; -- cgit v1.2.3 From e289fe4dd7372a029ba85722e3ce99991e9d1d6b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 11:04:16 +0200 Subject: Changed the AddEntityEffect() params for easier calls. --- src/Items/ItemPotion.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 200c13cab..70a926cad 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -146,8 +146,7 @@ public: virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { // Called when potion is a drinkable potion - short potion_damage = a_Item->m_ItemDamage; - a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player)); + a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage)); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; -- cgit v1.2.3 From 9e8361976b6b0dc4c62ef48a4744ba1f59fe4346 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 13 Jun 2014 02:41:43 -0700 Subject: Entity Effects: Clarified user, added it to AddEntityEffect Added second AddEntityEffect with a pass-by-value of the class. --- src/Items/ItemPotion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 70a926cad..853ed53a8 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -146,7 +146,7 @@ public: virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { // Called when potion is a drinkable potion - a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage)); + a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage), a_Player); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; -- cgit v1.2.3 From f5529e544cf8350daf8a20bb8d997f85ee2824f7 Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 16 Jun 2014 20:22:17 -0700 Subject: EntityEffects.x -> EntityEffect.x, Object-Oriented effects Changed effect map to take a pointer of the effect as a result. --- src/Items/ItemPotion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 853ed53a8..43b9f280d 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -1,7 +1,7 @@ #pragma once -#include "../Entities/EntityEffects.h" +#include "../Entities/EntityEffect.h" #include "../Entities/SplashPotionEntity.h" class cItemPotionHandler: -- cgit v1.2.3 From 4e6395d6ff9f34edb4dd36dc1f8e845c56b499f4 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 11 Jul 2014 17:27:29 -0700 Subject: For now, removed creator member from Entity Effect for pointer safety --- src/Items/ItemPotion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 43b9f280d..5badeda94 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -123,7 +123,7 @@ public: Vector3d Speed = a_Player->GetLookVector() * 7; short potion_damage = a_Item.m_ItemDamage; - cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player), GetPotionName(potion_damage)); + cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage)), GetPotionName(potion_damage)); if (Projectile == NULL) { return false; @@ -146,7 +146,7 @@ public: virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { // Called when potion is a drinkable potion - a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage), a_Player); + a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage)); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; -- cgit v1.2.3 From 061010288a99fd11f91bf713ac68068c57f79be7 Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 14 Jul 2014 13:46:15 -0700 Subject: Readability and clarity changes --- src/Items/ItemPotion.h | 75 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 30 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 5badeda94..b72499431 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -11,33 +11,35 @@ class cItemPotionHandler: int GetPotionName(short a_ItemDamage) { - return a_ItemDamage & 63; + // First six bits (least significant) + return a_ItemDamage & 0x3F; } cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) { + // First four bits (least significant) // Potion effect bits are different from entity effect values // For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits - switch (a_ItemDamage & 15) + switch (a_ItemDamage & 0xF) { - case 1: return cEntityEffect::effRegeneration; - case 2: return cEntityEffect::effSpeed; - case 3: return cEntityEffect::effFireResistance; - case 4: return cEntityEffect::effPoison; - case 5: return cEntityEffect::effInstantHealth; - case 6: return cEntityEffect::effNightVision; - case 8: return cEntityEffect::effWeakness; - case 9: return cEntityEffect::effStrength; - case 10: return cEntityEffect::effSlowness; - case 12: return cEntityEffect::effInstantDamage; - case 13: return cEntityEffect::effWaterBreathing; - case 14: return cEntityEffect::effInvisibility; + case 0x1: return cEntityEffect::effRegeneration; + case 0x2: return cEntityEffect::effSpeed; + case 0x3: return cEntityEffect::effFireResistance; + case 0x4: return cEntityEffect::effPoison; + case 0x5: return cEntityEffect::effInstantHealth; + case 0x6: return cEntityEffect::effNightVision; + case 0x8: return cEntityEffect::effWeakness; + case 0x9: return cEntityEffect::effStrength; + case 0xA: return cEntityEffect::effSlowness; + case 0xC: return cEntityEffect::effInstantDamage; + case 0xD: return cEntityEffect::effWaterBreathing; + case 0xE: return cEntityEffect::effInvisibility; // No effect potions - case 0: - case 7: - case 11: - case 15: + case 0x0: + case 0x7: + case 0xB: // Will be potion of leaping in 1.8 + case 0xF: { break; } @@ -48,9 +50,8 @@ class cItemPotionHandler: short GetEntityEffectIntensity(short a_ItemDamage) { - // Level II potion if fifth bit is set - if (a_ItemDamage & 32) return 1; - else return 0; + // Level II potion if fifth bit (from zero) is set + return (a_ItemDamage & 0x20) ? 1 : 0; } int GetEntityEffectDuration(short a_ItemDamage) @@ -91,8 +92,8 @@ class cItemPotionHandler: TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1; // If potion is extended, multiply duration by 8/3. If not, stays the same - // Extended potion if sixth bit is set - ExtCoeff = (a_ItemDamage & 64) ? (8.0/3.0) : 1; + // Extended potion if sixth bit (from zero) is set + ExtCoeff = (a_ItemDamage & 0x40) ? (8.0/3.0) : 1; // If potion is splash potion, multiply duration by 3/4. If not, stays the same SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75; @@ -112,18 +113,26 @@ public: virtual bool IsDrinkable(short a_ItemDamage) override { - // Drinkable potion if 13th bit is set + // Drinkable potion if 13th bit (from zero) is set // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table - return ((a_ItemDamage & 8192) != 0); + return ((a_ItemDamage & 0x2000) != 0); } virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { + short PotionDamage = a_Item.m_ItemDamage; + + // Only called when potion is a splash potion + if (IsDrinkable(PotionDamage)) + { + return false; + } + Vector3d Pos = a_Player->GetThrowStartPos(); Vector3d Speed = a_Player->GetLookVector() * 7; - short potion_damage = a_Item.m_ItemDamage; - cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage)), GetPotionName(potion_damage)); + cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage)), GetPotionName(PotionDamage)); + if (Projectile == NULL) { return false; @@ -139,14 +148,20 @@ public: a_Player->GetInventory().RemoveOneEquippedItem(); } - // Called when potion is a splash potion return true; } virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { - // Called when potion is a drinkable potion - a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage)); + short PotionDamage = a_Item->m_ItemDamage; + + // Only called when potion is a drinkable potion + if (!IsDrinkable(a_Item->m_ItemDamage)) + { + return false; + } + + a_Player->AddEntityEffect(GetEntityEffectType(PotionDamage), GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage)); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; -- cgit v1.2.3 From 40bb98510a820469184e4947db3de22088b55fc7 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 13 Jul 2014 16:54:42 -0700 Subject: ItemHandler.cpp: removed redundant food and drink checks --- src/Items/ItemHandler.cpp | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 7fae2d395..85406c826 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -474,32 +474,6 @@ bool cItemHandler::IsTool() bool cItemHandler::IsFood(void) { - switch (m_ItemType) - { - case E_ITEM_RED_APPLE: - case E_ITEM_GOLDEN_APPLE: - case E_ITEM_MUSHROOM_SOUP: - case E_ITEM_BREAD: - case E_ITEM_RAW_PORKCHOP: - case E_ITEM_COOKED_PORKCHOP: - case E_ITEM_RAW_FISH: - case E_ITEM_COOKED_FISH: - case E_ITEM_COOKIE: - case E_ITEM_MELON_SLICE: - case E_ITEM_RAW_BEEF: - case E_ITEM_STEAK: - case E_ITEM_RAW_CHICKEN: - case E_ITEM_COOKED_CHICKEN: - case E_ITEM_ROTTEN_FLESH: - case E_ITEM_SPIDER_EYE: - case E_ITEM_CARROT: - case E_ITEM_POTATO: - case E_ITEM_BAKED_POTATO: - case E_ITEM_POISONOUS_POTATO: - { - return true; - } - } // switch (m_ItemType) return false; } @@ -511,13 +485,6 @@ bool cItemHandler::IsDrinkable(short a_ItemDamage) { UNUSED(a_ItemDamage); - switch (m_ItemType) - { - case E_ITEM_MILK: - { - return true; - } - } // switch (m_ItemType) return false; } -- cgit v1.2.3 From 64c8b0d51b0ee8323dded6d22ac3b4754daa15d2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 10:51:44 +0200 Subject: Reformatted cItemPotionHandler. --- src/Items/ItemPotion.h | 124 ++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 47 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index b72499431..f3afbf99b 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -9,52 +9,67 @@ class cItemPotionHandler: { typedef cItemHandler super; - int GetPotionName(short a_ItemDamage) +public: + + cItemPotionHandler(): + super(E_ITEM_POTION) + { + } + + + /** Returns the potion particle type (used by the client for visuals), based on the potion's damage value */ + static int GetPotionParticleType(short a_ItemDamage) { - // First six bits (least significant) - return a_ItemDamage & 0x3F; + // Lowest six bits + return (a_ItemDamage & 0x3f); } - cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) + + /** Translates the potion's damage value into the entity effect that the potion gives */ + static cEntityEffect::eType GetEntityEffectType(short a_ItemDamage) { - // First four bits (least significant) + // Lowest four bits // Potion effect bits are different from entity effect values // For reference: http://minecraft.gamepedia.com/Data_values#.22Potion_effect.22_bits - switch (a_ItemDamage & 0xF) + switch (a_ItemDamage & 0x0f) { - case 0x1: return cEntityEffect::effRegeneration; - case 0x2: return cEntityEffect::effSpeed; - case 0x3: return cEntityEffect::effFireResistance; - case 0x4: return cEntityEffect::effPoison; - case 0x5: return cEntityEffect::effInstantHealth; - case 0x6: return cEntityEffect::effNightVision; - case 0x8: return cEntityEffect::effWeakness; - case 0x9: return cEntityEffect::effStrength; - case 0xA: return cEntityEffect::effSlowness; - case 0xC: return cEntityEffect::effInstantDamage; - case 0xD: return cEntityEffect::effWaterBreathing; - case 0xE: return cEntityEffect::effInvisibility; + case 0x01: return cEntityEffect::effRegeneration; + case 0x02: return cEntityEffect::effSpeed; + case 0x03: return cEntityEffect::effFireResistance; + case 0x04: return cEntityEffect::effPoison; + case 0x05: return cEntityEffect::effInstantHealth; + case 0x06: return cEntityEffect::effNightVision; + case 0x08: return cEntityEffect::effWeakness; + case 0x09: return cEntityEffect::effStrength; + case 0x0a: return cEntityEffect::effSlowness; + case 0x0c: return cEntityEffect::effInstantDamage; + case 0x0d: return cEntityEffect::effWaterBreathing; + case 0x0e: return cEntityEffect::effInvisibility; // No effect potions - case 0x0: - case 0x7: - case 0xB: // Will be potion of leaping in 1.8 - case 0xF: + case 0x00: + case 0x07: + case 0x0b: // Will be potion of leaping in 1.8 + case 0x0f: { break; } } - return cEntityEffect::effNoEffect; } - - short GetEntityEffectIntensity(short a_ItemDamage) + + + /** Retrieves the intensity level from the potion's damage value. + Returns 0 for level I potions, 1 for level II potions. */ + static short GetEntityEffectIntensity(short a_ItemDamage) { - // Level II potion if fifth bit (from zero) is set - return (a_ItemDamage & 0x20) ? 1 : 0; + // Level II potion if the fifth lowest bit is set + return ((a_ItemDamage & 0x20) != 0) ? 1 : 0; } - int GetEntityEffectDuration(short a_ItemDamage) + + /** Returns the effect duration, in ticks, based on the potion's damage value */ + static int GetEntityEffectDuration(short a_ItemDamage) { // Base duration in ticks int base = 0; @@ -88,42 +103,49 @@ class cItemPotionHandler: } } - // If potion is level 2, half the duration. If not, stays the same + // If potion is level II, half the duration. If not, stays the same TierCoeff = (GetEntityEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1; // If potion is extended, multiply duration by 8/3. If not, stays the same - // Extended potion if sixth bit (from zero) is set - ExtCoeff = (a_ItemDamage & 0x40) ? (8.0/3.0) : 1; + // Extended potion if sixth lowest bit is set + ExtCoeff = (a_ItemDamage & 0x40) ? (8.0 / 3.0) : 1; // If potion is splash potion, multiply duration by 3/4. If not, stays the same - SplashCoeff = IsDrinkable(a_ItemDamage) ? 1 : 0.75; + SplashCoeff = IsPotionDrinkable(a_ItemDamage) ? 1 : 0.75; - // For reference: http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit - // http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit - // http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit + // Ref.: + // http://minecraft.gamepedia.com/Data_values#.22Tier.22_bit + // http://minecraft.gamepedia.com/Data_values#.22Extended_duration.22_bit + // http://minecraft.gamepedia.com/Data_values#.22Splash_potion.22_bit return (int)(base * TierCoeff * ExtCoeff * SplashCoeff); } - -public: - cItemPotionHandler(): - super(E_ITEM_POTIONS) + + + /** Returns true if the potion with the given damage is drinkable */ + static bool IsPotionDrinkable(short a_ItemDamage) { + // Drinkable potion if 13th lowest bit is set + // Ref.: http://minecraft.gamepedia.com/Potions#Data_value_table + return ((a_ItemDamage & 0x2000) != 0); } + + // cItemHandler overrides: virtual bool IsDrinkable(short a_ItemDamage) override { - // Drinkable potion if 13th bit (from zero) is set - // For reference: http://minecraft.gamepedia.com/Potions#Data_value_table - return ((a_ItemDamage & 0x2000) != 0); + // Drinkable potion if 13th lowest bit is set + // Ref.: http://minecraft.gamepedia.com/Potions#Data_value_table + return IsPotionDrinkable(a_ItemDamage); } + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { short PotionDamage = a_Item.m_ItemDamage; - // Only called when potion is a splash potion - if (IsDrinkable(PotionDamage)) + // Do not throw non-splash potions: + if (IsPotionDrinkable(PotionDamage)) { return false; } @@ -131,8 +153,11 @@ public: Vector3d Pos = a_Player->GetThrowStartPos(); Vector3d Speed = a_Player->GetLookVector() * 7; - cSplashPotionEntity *Projectile = new cSplashPotionEntity(a_Player, Pos.x, Pos.y, Pos.z, &Speed, GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage), GetEntityEffectIntensity(PotionDamage)), GetPotionName(PotionDamage)); - + cSplashPotionEntity * Projectile = new cSplashPotionEntity( + a_Player, Pos.x, Pos.y, Pos.z, Speed, + GetEntityEffectType(PotionDamage), cEntityEffect(GetEntityEffectDuration(PotionDamage), + GetEntityEffectIntensity(PotionDamage)), GetPotionParticleType(PotionDamage) + ); if (Projectile == NULL) { return false; @@ -151,11 +176,12 @@ public: return true; } + virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { short PotionDamage = a_Item->m_ItemDamage; - // Only called when potion is a drinkable potion + // Do not drink undrinkable potions: if (!IsDrinkable(a_Item->m_ItemDamage)) { return false; @@ -167,3 +193,7 @@ public: return true; } }; + + + + -- cgit v1.2.3