From 396739cc0faf01a099acbe669c5a9def98d3aaae Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 23 Jul 2014 16:32:09 +0200 Subject: Fix item durability. Fixes #1181 --- src/Entities/Entity.cpp | 13 ++++++++----- src/Entities/Player.cpp | 4 ++-- src/Entities/Player.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index db0fd0fd6..6c3d7b40c 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -12,6 +12,7 @@ #include "../Bindings/PluginManager.h" #include "../Tracer.h" #include "Player.h" +#include "Items/ItemHandler.h" @@ -289,11 +290,6 @@ void cEntity::SetPitchFromSpeed(void) bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { - if (cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*this, a_TDI)) - { - return false; - } - if (m_Health <= 0) { // Can't take damage if already dead @@ -306,10 +302,17 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } + if (cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*this, a_TDI)) + { + return false; + } + if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) { cPlayer * Player = (cPlayer *)a_TDI.Attacker; + Player->GetEquippedItem().GetHandler()->OnEntityAttack(Player, this); + // IsOnGround() only is false if the player is moving downwards // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) if (!Player->IsOnGround()) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fcc8eb9a0..afe5965aa 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1929,14 +1929,14 @@ cPlayer::StringList cPlayer::GetResolvedPermissions() -void cPlayer::UseEquippedItem(void) +void cPlayer::UseEquippedItem(int a_Amount) { if (IsGameModeCreative()) // No damage in creative { return; } - if (GetInventory().DamageEquippedItem()) + if (GetInventory().DamageEquippedItem(a_Amount)) { m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 26db2050b..e89d9f48f 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -349,7 +349,7 @@ public: const AString & GetLoadedWorldName() { return m_LoadedWorldName; } - void UseEquippedItem(void); + void UseEquippedItem(int a_Amount = 1); void SendHealth(void); -- cgit v1.2.3 From 4191be7ddba820af4ed0c505a8d62416c2b7a8b4 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 22 Jul 2014 15:36:13 -0700 Subject: Removed redundant semicolons and re-added warning --- src/Entities/ArrowEntity.h | 2 +- src/Entities/Boat.h | 2 +- src/Entities/EnderCrystal.h | 2 +- src/Entities/Entity.h | 2 +- src/Entities/EntityEffect.h | 2 +- src/Entities/ExpBottleEntity.h | 2 +- src/Entities/ExpOrb.h | 2 +- src/Entities/FallingBlock.h | 2 +- src/Entities/FireChargeEntity.h | 2 +- src/Entities/FireworkEntity.h | 2 +- src/Entities/Floater.h | 2 +- src/Entities/GhastFireballEntity.h | 2 +- src/Entities/HangingEntity.h | 4 ++-- src/Entities/ItemFrame.h | 4 ++-- src/Entities/Minecart.h | 12 ++++++------ src/Entities/Painting.h | 2 +- src/Entities/Pawn.h | 2 +- src/Entities/Pickup.h | 2 +- src/Entities/Player.h | 2 +- src/Entities/ProjectileEntity.h | 2 +- src/Entities/SplashPotionEntity.h | 2 +- src/Entities/TNTEntity.h | 2 +- src/Entities/ThrownEggEntity.h | 2 +- src/Entities/ThrownEnderPearlEntity.h | 2 +- src/Entities/ThrownSnowballEntity.h | 2 +- src/Entities/WitherSkullEntity.h | 2 +- 26 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index ad93dba6c..4bfcb1f6d 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -28,7 +28,7 @@ public: // tolua_end - CLASS_PROTODEF(cArrowEntity); + CLASS_PROTODEF(cArrowEntity) /// Creates a new arrow with psNoPickup state and default damage modifier coeff cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h index 0fcfbd602..8de88d165 100644 --- a/src/Entities/Boat.h +++ b/src/Entities/Boat.h @@ -21,7 +21,7 @@ class cBoat : typedef cEntity super; public: - CLASS_PROTODEF(cBoat); + CLASS_PROTODEF(cBoat) // cEntity overrides: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; diff --git a/src/Entities/EnderCrystal.h b/src/Entities/EnderCrystal.h index 30211de13..c98c3b681 100644 --- a/src/Entities/EnderCrystal.h +++ b/src/Entities/EnderCrystal.h @@ -15,7 +15,7 @@ class cEnderCrystal : typedef cEntity super; public: - CLASS_PROTODEF(cEnderCrystal); + CLASS_PROTODEF(cEnderCrystal) cEnderCrystal(double a_X, double a_Y, double a_Z); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 83fe76e7e..efca60a6c 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -428,7 +428,7 @@ public: // tolua_end /// Called when the specified player right-clicks this entity - virtual void OnRightClicked(cPlayer &) {}; + virtual void OnRightClicked(cPlayer &) {} /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index ebd611ff0..396a9bbe0 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -55,7 +55,7 @@ public: @param a_OtherEffect The other effect to copy */ cEntityEffect & operator=(cEntityEffect a_OtherEffect); - virtual ~cEntityEffect(void) {}; + virtual ~cEntityEffect(void) {} /** Creates a pointer to the proper entity effect from the effect type @warning This function creates raw pointers that must be manually managed. diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h index e9536452c..d62a84469 100644 --- a/src/Entities/ExpBottleEntity.h +++ b/src/Entities/ExpBottleEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cExpBottleEntity); + CLASS_PROTODEF(cExpBottleEntity) cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h index 2cd4ef31f..bdb9a5b19 100644 --- a/src/Entities/ExpOrb.h +++ b/src/Entities/ExpOrb.h @@ -16,7 +16,7 @@ class cExpOrb : public: // tolua_end - CLASS_PROTODEF(cExpOrb); + CLASS_PROTODEF(cExpOrb) cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward); cExpOrb(const Vector3d & a_Pos, int a_Reward); diff --git a/src/Entities/FallingBlock.h b/src/Entities/FallingBlock.h index 5ba9909bb..c20fe8eb9 100644 --- a/src/Entities/FallingBlock.h +++ b/src/Entities/FallingBlock.h @@ -20,7 +20,7 @@ class cFallingBlock : typedef cEntity super; public: - CLASS_PROTODEF(cFallingBlock); + CLASS_PROTODEF(cFallingBlock) /// Creates a new falling block. a_BlockPosition is expected in world coords cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h index 42ecc7d74..5df55bec4 100644 --- a/src/Entities/FireChargeEntity.h +++ b/src/Entities/FireChargeEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cFireChargeEntity); + CLASS_PROTODEF(cFireChargeEntity) cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h index 7dbdc49e1..20f18b6dc 100644 --- a/src/Entities/FireworkEntity.h +++ b/src/Entities/FireworkEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cFireworkEntity); + CLASS_PROTODEF(cFireworkEntity) cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); const cItem & GetItem(void) const { return m_FireworkItem; } diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 5d2720b6a..96d77ac82 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -16,7 +16,7 @@ class cFloater : public: // tolua_end - CLASS_PROTODEF(cFloater); + CLASS_PROTODEF(cFloater) cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime); diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h index fa59fa642..3ed72d9ef 100644 --- a/src/Entities/GhastFireballEntity.h +++ b/src/Entities/GhastFireballEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cGhastFireballEntity); + CLASS_PROTODEF(cGhastFireballEntity) cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 6498e4b5b..3593f9ede 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -16,7 +16,7 @@ class cHangingEntity : public: - CLASS_PROTODEF(cHangingEntity); + CLASS_PROTODEF(cHangingEntity) cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); @@ -38,7 +38,7 @@ public: private: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override {} eBlockFace m_BlockFace; diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h index 9261e52cc..a63b78b70 100644 --- a/src/Entities/ItemFrame.h +++ b/src/Entities/ItemFrame.h @@ -16,7 +16,7 @@ class cItemFrame : public: - CLASS_PROTODEF(cItemFrame); + CLASS_PROTODEF(cItemFrame) cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); @@ -24,7 +24,7 @@ public: const cItem & GetItem(void) { return m_Item; } // tolua_export /** Set the item in the frame */ - void SetItem(cItem & a_Item) { m_Item = a_Item; }; // tolua_export + void SetItem(cItem & a_Item) { m_Item = a_Item; } // tolua_export /** Returns the rotation from the item in the frame */ Byte GetRotation(void) const { return m_Rotation; } // tolua_export diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index c585cfab0..410d3c77d 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -21,7 +21,7 @@ class cMinecart : typedef cEntity super; public: - CLASS_PROTODEF(cMinecart); + CLASS_PROTODEF(cMinecart) /** Minecart payload, values correspond to packet subtype */ enum ePayload @@ -89,7 +89,7 @@ class cRideableMinecart : typedef cMinecart super; public: - CLASS_PROTODEF(cRideableMinecart); + CLASS_PROTODEF(cRideableMinecart) cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height); @@ -113,7 +113,7 @@ class cMinecartWithChest : typedef cMinecart super; public: - CLASS_PROTODEF(cMinecartWithChest); + CLASS_PROTODEF(cMinecartWithChest) /// Number of item slots in the chest static const int NumSlots = 9 * 3; @@ -144,7 +144,7 @@ class cMinecartWithFurnace : typedef cMinecart super; public: - CLASS_PROTODEF(cMinecartWithFurnace); + CLASS_PROTODEF(cMinecartWithFurnace) cMinecartWithFurnace(double a_X, double a_Y, double a_Z); @@ -176,7 +176,7 @@ class cMinecartWithTNT : typedef cMinecart super; public: - CLASS_PROTODEF(cMinecartWithTNT); + CLASS_PROTODEF(cMinecartWithTNT) cMinecartWithTNT(double a_X, double a_Y, double a_Z); } ; @@ -191,7 +191,7 @@ class cMinecartWithHopper : typedef cMinecart super; public: - CLASS_PROTODEF(cMinecartWithHopper); + CLASS_PROTODEF(cMinecartWithHopper) cMinecartWithHopper(double a_X, double a_Y, double a_Z); } ; diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index ce7c6f3de..9877c95c5 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -15,7 +15,7 @@ class cPainting : typedef cEntity super; public: - CLASS_PROTODEF(cPainting); + CLASS_PROTODEF(cPainting) cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z); const AString & GetName(void) const { return m_Name; } // tolua_export diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index 63c7cfbb6..d50bcd8af 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -16,7 +16,7 @@ class cPawn : typedef cEntity super; public: - CLASS_PROTODEF(cPawn); + CLASS_PROTODEF(cPawn) cPawn(eEntityType a_EntityType, double a_Width, double a_Height); diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index d7c5d2b26..4d5250819 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -23,7 +23,7 @@ class cPickup : public: // tolua_end - CLASS_PROTODEF(cPickup); + CLASS_PROTODEF(cPickup) cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 26db2050b..488884602 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -48,7 +48,7 @@ public: virtual void Tick(float a_Dt, cChunk & a_Chunk) override; - virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); }; + virtual void HandlePhysics(float a_Dt, cChunk &) override { UNUSED(a_Dt); } /** Returns the curently equipped weapon; empty item if none */ virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index e6b05714e..0ebc32f36 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -41,7 +41,7 @@ public: // tolua_end - CLASS_PROTODEF(cProjectileEntity); + CLASS_PROTODEF(cProjectileEntity) cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height); diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 290dd81d4..dd14ea82f 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -23,7 +23,7 @@ public: // tolua_end - CLASS_PROTODEF(cSplashPotionEntity); + CLASS_PROTODEF(cSplashPotionEntity) cSplashPotionEntity( cEntity * a_Creator, diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index df61b14f5..48503cf76 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -14,7 +14,7 @@ class cTNTEntity : public: // tolua_end - CLASS_PROTODEF(cTNTEntity); + CLASS_PROTODEF(cTNTEntity) cTNTEntity(double a_X, double a_Y, double a_Z, int a_FuseTicks = 80); cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks = 80); diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h index f93731256..a0b7d5340 100644 --- a/src/Entities/ThrownEggEntity.h +++ b/src/Entities/ThrownEggEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cThrownEggEntity); + CLASS_PROTODEF(cThrownEggEntity) cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h index 549d8a3eb..436450013 100644 --- a/src/Entities/ThrownEnderPearlEntity.h +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cThrownEnderPearlEntity); + CLASS_PROTODEF(cThrownEnderPearlEntity) cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h index 6f3efdd7e..8d195ced1 100644 --- a/src/Entities/ThrownSnowballEntity.h +++ b/src/Entities/ThrownSnowballEntity.h @@ -21,7 +21,7 @@ public: // tolua_end - CLASS_PROTODEF(cThrownSnowballEntity); + CLASS_PROTODEF(cThrownSnowballEntity) cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h index ebc1550e3..c59acd807 100644 --- a/src/Entities/WitherSkullEntity.h +++ b/src/Entities/WitherSkullEntity.h @@ -22,7 +22,7 @@ public: // tolua_end - CLASS_PROTODEF(cWitherSkullEntity); + CLASS_PROTODEF(cWitherSkullEntity) cWitherSkullEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); -- cgit v1.2.3 From 0298d34406b1582e882795bf4d9d3fea18fd0135 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 20 Jul 2014 02:56:59 -0700 Subject: Moved potion static functions to EntityEffect to create splash potions through world --- src/Entities/EntityEffect.cpp | 124 ++++++++++++++++++++++++++++++++++++ src/Entities/EntityEffect.h | 19 ++++++ src/Entities/ProjectileEntity.cpp | 2 + src/Entities/SplashPotionEntity.cpp | 16 +++-- src/Entities/SplashPotionEntity.h | 4 +- 5 files changed, 156 insertions(+), 9 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 6c4b13a58..f58738aef 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -7,6 +7,130 @@ + +int cEntityEffect::GetPotionColor(short a_ItemDamage) +{ + // Lowest six bits + return (a_ItemDamage & 0x3f); +} + + + + + +cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage) +{ + // 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 & 0x0f) + { + 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 0x00: + case 0x07: + case 0x0b: // Will be potion of leaping in 1.8 + case 0x0f: + { + break; + } + } + return cEntityEffect::effNoEffect; +} + + + + + +short cEntityEffect::GetPotionEffectIntensity(short a_ItemDamage) +{ + // Level II potion if the fifth lowest bit is set + return ((a_ItemDamage & 0x20) != 0) ? 1 : 0; +} + + + + + +int cEntityEffect::GetPotionEffectDuration(short a_ItemDamage) +{ + // Base duration in ticks + int base = 0; + double TierCoeff = 1, ExtCoeff = 1, SplashCoeff = 1; + + switch (GetPotionEffectType(a_ItemDamage)) + { + case cEntityEffect::effRegeneration: + case cEntityEffect::effPoison: + { + base = 900; + break; + } + + case cEntityEffect::effSpeed: + case cEntityEffect::effFireResistance: + case cEntityEffect::effNightVision: + case cEntityEffect::effStrength: + case cEntityEffect::effWaterBreathing: + case cEntityEffect::effInvisibility: + { + base = 3600; + break; + } + + case cEntityEffect::effWeakness: + case cEntityEffect::effSlowness: + { + base = 1800; + break; + } + } + + // If potion is level II, half the duration. If not, stays the same + TierCoeff = (GetPotionEffectIntensity(a_ItemDamage) > 0) ? 0.5 : 1; + + // If potion is extended, multiply duration by 8/3. If not, stays the same + // 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 = IsPotionDrinkable(a_ItemDamage) ? 1 : 0.75; + + // 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); +} + + + + + +bool cEntityEffect::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); +} + + + + + cEntityEffect::cEntityEffect(): m_Ticks(0), m_Duration(0), diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index 396a9bbe0..04e25e303 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -36,6 +36,25 @@ public: effSaturation = 23, } ; + /** Returns the potion color (used by the client for visuals), based on the potion's damage value */ + static int GetPotionColor(short a_ItemDamage); + + + /** Translates the potion's damage value into the entity effect that the potion gives */ + static cEntityEffect::eType GetPotionEffectType(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 GetPotionEffectIntensity(short a_ItemDamage); + + + /** Returns the effect duration, in ticks, based on the potion's damage value */ + static int GetPotionEffectDuration(short a_ItemDamage); + + /** Returns true if the potion with the given damage is drinkable */ + static bool IsPotionDrinkable(short a_ItemDamage); + // tolua_end /** Creates an empty entity effect */ diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index b5e81bc0c..43023ec28 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -22,6 +22,7 @@ #include "FireworkEntity.h" #include "GhastFireballEntity.h" #include "WitherSkullEntity.h" +#include "SplashPotionEntity.h" #include "Player.h" @@ -263,6 +264,7 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed); + case pkSplashPotion: return new cSplashPotionEntity (a_Creator, a_X, a_Y, a_Z, Speed, *a_Item); case pkWitherSkull: return new cWitherSkullEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFirework: { diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 6d874e957..d874a86e1 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -72,17 +72,21 @@ cSplashPotionEntity::cSplashPotionEntity( cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, - cEntityEffect::eType a_EntityEffectType, - cEntityEffect a_EntityEffect, - int a_PotionColor + cItem a_Item ) : super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), - m_EntityEffectType(a_EntityEffectType), - m_EntityEffect(a_EntityEffect), - m_PotionColor(a_PotionColor), + m_EntityEffectType(cEntityEffect::effNoEffect), + m_EntityEffect(cEntityEffect()), + m_PotionColor(0), m_DestroyTimer(-1) { SetSpeed(a_Speed); + m_EntityEffectType = cEntityEffect::GetPotionEffectType(a_Item.m_ItemDamage); + m_EntityEffect = cEntityEffect( + cEntityEffect::GetPotionEffectDuration(a_Item.m_ItemDamage), + cEntityEffect::GetPotionEffectIntensity(a_Item.m_ItemDamage) + ); + m_PotionColor = cEntityEffect::GetPotionColor(a_Item.m_ItemDamage); } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index dd14ea82f..db1672f9b 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -29,9 +29,7 @@ public: cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, - cEntityEffect::eType a_EntityEffectType, - cEntityEffect a_EntityEffect, - int a_PotionColor + cItem a_Item ); cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; } -- cgit v1.2.3 From 60d4a165140b3b1c5202c21fd197b61cae18077c Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 20 Jul 2014 13:11:06 -0700 Subject: Fixed indentations, removed redundant init code in SplashPotionEntity.cpp --- src/Entities/EntityEffect.cpp | 2 +- src/Entities/EntityEffect.h | 3 +-- src/Entities/SplashPotionEntity.cpp | 3 --- 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index f58738aef..fdcbe822e 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -38,7 +38,7 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage) case 0x0d: return cEntityEffect::effWaterBreathing; case 0x0e: return cEntityEffect::effInvisibility; - // No effect potions + // No effect potions case 0x00: case 0x07: case 0x0b: // Will be potion of leaping in 1.8 diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index 04e25e303..f9c1e4eb2 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -44,8 +44,7 @@ public: static cEntityEffect::eType GetPotionEffectType(short a_ItemDamage); - /** Retrieves the intensity level from the potion's damage value. - Returns 0 for level I potions, 1 for level II potions. */ + /** Retrieves the intensity level from the potion's damage value. Returns 0 for level I potions, 1 for level II potions. */ static short GetPotionEffectIntensity(short a_ItemDamage); diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index d874a86e1..ed16f060d 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -75,9 +75,6 @@ cSplashPotionEntity::cSplashPotionEntity( cItem a_Item ) : super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), - m_EntityEffectType(cEntityEffect::effNoEffect), - m_EntityEffect(cEntityEffect()), - m_PotionColor(0), m_DestroyTimer(-1) { SetSpeed(a_Speed); -- cgit v1.2.3 From 16e0beb5b6f6c4c103acfccc1940585513b5c258 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Jul 2014 03:55:40 -0700 Subject: SplashPotionEntity: Use `const cItem &` instead of a cItem --- src/Entities/SplashPotionEntity.cpp | 2 +- src/Entities/SplashPotionEntity.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index ed16f060d..fd1a0179b 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -72,7 +72,7 @@ cSplashPotionEntity::cSplashPotionEntity( cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, - cItem a_Item + const cItem & a_Item ) : super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), m_DestroyTimer(-1) diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index db1672f9b..4afc5f204 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -29,7 +29,7 @@ public: cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed, - cItem a_Item + const cItem & a_Item ); cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; } -- cgit v1.2.3