summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorKingCol13 <48412633+KingCol13@users.noreply.github.com>2020-10-02 22:57:17 +0200
committerGitHub <noreply@github.com>2020-10-02 22:57:17 +0200
commitcd1b50774512e09736b78df025163ab9b26bd528 (patch)
tree082bbf03758f8fe6e32711fbbf2104efdcb13994 /src/Entities
parentUpdate issue templates (#4960) (diff)
downloadcuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar.gz
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar.bz2
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar.lz
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar.xz
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.tar.zst
cuberite-cd1b50774512e09736b78df025163ab9b26bd528.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Player.cpp86
-rw-r--r--src/Entities/Player.h21
2 files changed, 81 insertions, 26 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index d7455f371..d0d729567 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -3156,61 +3156,109 @@ bool cPlayer::IsInsideWater()
float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
{
- float f = GetEquippedItem().GetHandler()->GetBlockBreakingStrength(a_Block);
- if (f > 1.0f)
+ // Based on: https://minecraft.gamepedia.com/Breaking#Speed
+
+ // Get the base speed multiplier of the equipped tool for the mined block
+ float MiningSpeed = GetEquippedItem().GetHandler()->GetBlockBreakingStrength(a_Block);
+
+ // If we can harvest the block then we can apply material and enchantment bonuses
+ if (GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block))
{
- unsigned int efficiencyModifier = GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
- if (efficiencyModifier > 0)
+ if (MiningSpeed > 1.0f) // If the base multiplier for this block is greater than 1, now we can check enchantments
{
- f += (efficiencyModifier * efficiencyModifier) + 1;
+ unsigned int EfficiencyModifier = GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
+ if (EfficiencyModifier > 0) // If an efficiency enchantment is present, apply formula as on wiki
+ {
+ MiningSpeed += (EfficiencyModifier * EfficiencyModifier) + 1;
+ }
}
}
+ else // If we can't harvest the block then no bonuses:
+ {
+ MiningSpeed = 1;
+ }
+ // Haste increases speed by 20% per level
auto Haste = GetEntityEffect(cEntityEffect::effHaste);
if (Haste != nullptr)
{
int intensity = Haste->GetIntensity() + 1;
- f *= 1.0f + (intensity * 0.2f);
+ MiningSpeed *= 1.0f + (intensity * 0.2f);
}
+ // Mining fatigue decreases speed a lot
auto MiningFatigue = GetEntityEffect(cEntityEffect::effMiningFatigue);
if (MiningFatigue != nullptr)
{
int intensity = MiningFatigue->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;
+ case 0: MiningSpeed *= 0.3f; break;
+ case 1: MiningSpeed *= 0.09f; break;
+ case 2: MiningSpeed *= 0.0027f; break;
+ default: MiningSpeed *= 0.00081f; break;
}
}
+ // 5x speed loss for being in water
if (IsInsideWater() && !(GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchAquaAffinity) > 0))
{
- f /= 5.0f;
+ MiningSpeed /= 5.0f;
}
+ // 5x speed loss for not touching ground
if (!IsOnGround())
{
- f /= 5.0f;
+ MiningSpeed /= 5.0f;
}
- return f;
+ return MiningSpeed;
}
-float cPlayer::GetPlayerRelativeBlockHardness(BLOCKTYPE a_Block)
+float cPlayer::GetMiningProgressPerTick(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);
+ // Based on https://minecraft.gamepedia.com/Breaking#Calculation
+ // If we know it's instantly breakable then quit here:
+ if (cBlockInfo::IsOneHitDig(a_Block))
+ {
+ return 1;
+ }
+ float BlockHardness = cBlockInfo::GetHardness(a_Block);
+ ASSERT(BlockHardness > 0); // Can't divide by 0 or less, IsOneHitDig should have returned true
+ if (GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block))
+ {
+ BlockHardness*=1.5;
+ }
+ else
+ {
+ BlockHardness*=5;
+ }
+ float DigSpeed = GetDigSpeed(a_Block);
+ // LOGD("Time to mine block = %f", BlockHardness/DigSpeed);
+ // Number of ticks to mine = (20 * BlockHardness)/DigSpeed;
+ // Therefore take inverse to get fraction mined per tick:
+ return DigSpeed / (20 * BlockHardness);
+}
+
+
+
+
+
+bool cPlayer::CanInstantlyMine(BLOCKTYPE a_Block)
+{
+ // Based on: https://minecraft.gamepedia.com/Breaking#Calculation
+ // Check it has non-zero hardness
+ if (cBlockInfo::IsOneHitDig(a_Block))
+ {
+ return true;
+ }
+ // If the dig speed is greater than 30 times the hardness, then the wiki says we can instantly mine
+ return GetDigSpeed(a_Block) > 30 * cBlockInfo::GetHardness(a_Block);
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 568929f44..791b583bd 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -597,11 +597,17 @@ 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);
+ /** Returns the progress mined per tick for the block a_Block as a fraction
+ (1 would be completely mined)
+ Depends on hardness values so check those are correct.
+ Source: https://minecraft.gamepedia.com/Breaking#Calculation */
+ float GetMiningProgressPerTick(BLOCKTYPE a_Block);
+
+ /** Given tool, enchantments, status effects, and world position
+ returns whether a_Block would be instantly mined.
+ Depends on hardness values so check those are correct.
+ Source: https://minecraft.gamepedia.com/Breaking#Instant_breaking */
+ bool CanInstantlyMine(BLOCKTYPE a_Block);
/** get player explosion exposure rate */
virtual float GetExplosionExposureRate(Vector3d a_ExplosionPosition, float a_ExlosionPower) override;
@@ -805,8 +811,9 @@ private:
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. */
+ In he is in water it gets divided by 5 except if his tool is enchanted with aqua affinity.
+ If he is not on ground it also gets divided by 5.
+ Source: https://minecraft.gamepedia.com/Breaking#Calculation */
float GetDigSpeed(BLOCKTYPE a_Block);
/** Add the recipe Id to the known recipes.