summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockOre.h
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2015-02-28 16:57:50 +0100
committerAlexander Harkness <me@bearbin.net>2015-02-28 16:57:50 +0100
commit958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba (patch)
tree0c5311aef8cb2aad5f641003c151acdbdccd61c8 /src/Blocks/BlockOre.h
parentMerge pull request #1771 from Raekye/master (diff)
parentAdded experience drops when mining ores (diff)
downloadcuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar.gz
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar.bz2
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar.lz
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar.xz
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.tar.zst
cuberite-958834f5e9eeb2b9f08b8d9c0ac0f4a4ceefdaba.zip
Diffstat (limited to 'src/Blocks/BlockOre.h')
-rw-r--r--src/Blocks/BlockOre.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h
index f6ea3aa3c..08d79f435 100644
--- a/src/Blocks/BlockOre.h
+++ b/src/Blocks/BlockOre.h
@@ -11,6 +11,7 @@
class cBlockOreHandler :
public cBlockHandler
{
+ typedef cBlockHandler super;
public:
cBlockOreHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
@@ -56,6 +57,64 @@ public:
}
}
}
+
+ virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ super::OnDestroyedByPlayer(a_ChunkInterface, a_WorldInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ);
+
+ if (a_Player->IsGameModeCreative())
+ {
+ // Don't drop XP when the player is in creative mode.
+ return;
+ }
+
+ if (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0)
+ {
+ // Don't drop XP when the ore is mined with the Silk Touch enchantment
+ return;
+ }
+
+ cFastRandom Random;
+ int Reward = 0;
+
+ switch (m_BlockType)
+ {
+ case E_BLOCK_NETHER_QUARTZ_ORE:
+ case E_BLOCK_LAPIS_ORE:
+ {
+ // Lapis and nether quartz get 2 - 5 experience
+ Reward = Random.NextInt(4) + 2;
+ break;
+ }
+ case E_BLOCK_REDSTONE_ORE:
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ {
+ // Redstone gets 1 - 5 experience
+ Reward = Random.NextInt(5) + 1;
+ break;
+ }
+ case E_BLOCK_DIAMOND_ORE:
+ case E_BLOCK_EMERALD_ORE:
+ {
+ // Diamond and emerald get 3 - 7 experience
+ Reward = Random.NextInt(5) + 3;
+ break;
+ }
+ case E_BLOCK_COAL_ORE:
+ {
+ // Coal gets 0 - 2 experience
+ Reward = Random.NextInt(3);
+ break;
+ }
+
+ default: break;
+ }
+
+ if (Reward != 0)
+ {
+ a_WorldInterface.SpawnExperienceOrb(a_BlockX, a_BlockY, a_BlockZ, Reward);
+ }
+ }
} ;