summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authormohe2015 <mohe2015@users.noreply.github.com>2016-11-06 19:30:19 +0100
committerMattes D <github@xoft.cz>2016-11-06 19:30:19 +0100
commit32b38fb2649fb282b6446c4e544866c0161aa7da (patch)
tree51d2fd4d507b9f46e80d90f357a6fee78d2f5ffa /src/Entities
parentMerge pull request #3416 from cuberite/JsonSerializerErrorReport (diff)
downloadcuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.gz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.bz2
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.lz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.xz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.zst
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Pawn.cpp21
-rw-r--r--src/Entities/Pawn.h6
-rw-r--r--src/Entities/Player.cpp92
-rw-r--r--src/Entities/Player.h21
4 files changed, 140 insertions, 0 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 4b42dbb57..a073dc9a7 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -441,3 +441,24 @@ void cPawn::StopEveryoneFromTargetingMe()
}
ASSERT(m_TargetingMe.size() == 0);
}
+
+
+
+
+
+std::map<cEntityEffect::eType, cEntityEffect *> cPawn::GetEntityEffects()
+{
+ return m_EntityEffects;
+}
+
+
+
+
+
+cEntityEffect *cPawn::GetEntityEffect(cEntityEffect::eType a_EffectType)
+{
+ return m_EntityEffects.at(a_EffectType);
+}
+
+
+
diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h
index 6a7035ee6..e2444e9a0 100644
--- a/src/Entities/Pawn.h
+++ b/src/Entities/Pawn.h
@@ -63,6 +63,12 @@ public:
/** Add the monster to the list of monsters targeting this pawn. (Does not check if already in list!) */
void TargetingMe(cMonster * a_Monster);
+ /** Returns all entity effects */
+ std::map<cEntityEffect::eType, cEntityEffect *> GetEntityEffects();
+
+ /** Returns the entity effect, if it is currently applied. */
+ cEntityEffect *GetEntityEffect(cEntityEffect::eType a_EffectType);
+
protected:
typedef std::map<cEntityEffect::eType, cEntityEffect *> tEffectMap;
tEffectMap m_EntityEffects;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index db4b07553..009f1e829 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -2636,3 +2636,95 @@ void cPlayer::FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen)
m_FlyingMaxSpeed = FlyingMaxpeed;
m_IsFlying = IsFlying;
}
+
+
+
+
+float cPlayer::GetLiquidHeightPercent(NIBBLETYPE a_Meta)
+{
+ if (a_Meta >= 8)
+ {
+ a_Meta = 0;
+ }
+ return static_cast<float>(a_Meta + 1) / 9.0f;
+}
+
+
+
+
+
+bool cPlayer::IsInsideWater()
+{
+ BLOCKTYPE Block = m_World->GetBlock(FloorC(GetPosX()), FloorC(m_Stance), FloorC(GetPosZ()));
+ if ((Block != E_BLOCK_WATER) && (Block != E_BLOCK_STATIONARY_WATER))
+ {
+ return false;
+ }
+ NIBBLETYPE Meta = GetWorld()->GetBlockMeta(FloorC(GetPosX()), FloorC(m_Stance), FloorC(GetPosZ()));
+ float f = GetLiquidHeightPercent(Meta) - 0.11111111f;
+ float f1 = static_cast<float>(m_Stance + 1) - f;
+ bool flag = (m_Stance < f1);
+ return flag;
+}
+
+
+
+
+
+float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
+{
+ float f = GetEquippedItem().GetHandler()->GetBlockBreakingStrength(a_Block);
+ if (f > 1.0f)
+ {
+ unsigned int efficiencyModifier = GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
+ if (efficiencyModifier > 0)
+ {
+ f += (efficiencyModifier * efficiencyModifier) + 1;
+ }
+ }
+
+ if (HasEntityEffect(cEntityEffect::effHaste))
+ {
+ int intensity = GetEntityEffect(cEntityEffect::effHaste)->GetIntensity() + 1;
+ f *= 1.0f + (intensity * 0.2f);
+ }
+
+ if (HasEntityEffect(cEntityEffect::effMiningFatigue))
+ {
+ int intensity = GetEntityEffect(cEntityEffect::effMiningFatigue)->GetIntensity();
+ switch (intensity)
+ {
+ case 0: f *= 0.3f; break;
+ case 1: f *= 0.09f; break;
+ case 2: f *= 0.0027f; break;
+ default: f *= 0.00081f; break;
+
+ }
+ }
+
+ if (IsInsideWater() && !(GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchAquaAffinity) > 0))
+ {
+ f /= 5.0f;
+ }
+
+ if (!IsOnGround())
+ {
+ f /= 5.0f;
+ }
+
+ return f;
+}
+
+
+
+
+
+float cPlayer::GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block)
+{
+ float blockHardness = cBlockInfo::GetHardness(a_Block);
+ float digSpeed = GetDigSpeed(a_Block);
+ float canHarvestBlockDivisor = GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block) ? 30.0f : 100.0f;
+ // LOGD("blockHardness: %f, digSpeed: %f, canHarvestBlockDivisor: %f\n", blockHardness, digSpeed, canHarvestBlockDivisor);
+ return (blockHardness < 0) ? 0 : ((digSpeed / blockHardness) / canHarvestBlockDivisor);
+}
+
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index cc83b1ca2..3de1a4cb5 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -529,6 +529,12 @@ public:
The player removes its m_ClientHandle ownership so that the ClientHandle gets deleted. */
void RemoveClientHandle(void);
+ /** Returns the relative block hardness for the block a_Block.
+ The bigger it is the faster the player can break the block.
+ Returns zero if the block is instant breakable.
+ Otherwise it returns the dig speed (float GetDigSpeed(BLOCKTYPE a_Block)) divided by the block hardness (cBlockInfo::GetHardness(BLOCKTYPE a_Block)) divided by 30 if the player can harvest the block and divided by 100 if he can't. */
+ float GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block);
+
protected:
typedef std::vector<std::vector<AString> > AStringVectorVector;
@@ -710,4 +716,19 @@ private:
/** Pins the player to a_Location until Unfreeze() is called.
If ManuallyFrozen is false, the player will unfreeze when the chunk is loaded. */
void FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen);
+
+ /** Returns how high the liquid is in percent. Used by IsInsideWater */
+ float GetLiquidHeightPercent(NIBBLETYPE a_Meta);
+
+ /** Checks if the player is inside of water */
+ bool IsInsideWater();
+
+ /** Returns the dig speed using the current tool on the block a_Block.
+ Returns one if using hand.
+ If the player is using a tool that is good to break the block the value is higher.
+ If he has an enchanted tool with efficiency or he has a haste or mining fatique effect it gets multiplied by a specific factor depending on the strength of the effect or enchantment.
+ In he is in water it gets divided by 5 except his tool is enchanted with aqa affinity.
+ If he is not on ground it also gets divided by 5. */
+ float GetDigSpeed(BLOCKTYPE a_Block);
+
} ; // tolua_export