From 3381c0f6d6671a485283c889b036c0a431e2a2b9 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Thu, 8 Oct 2020 21:13:44 +0200 Subject: Merged OnBreak with OnPlayerBreak (#4967) Co-authored-by: 12xx12 <12xx12100@gmail.com> Co-authored-by: Tiger Wang --- src/Blocks/BlockOre.h | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/Blocks/BlockOre.h') diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h index 023e149d9..6d6c2a097 100644 --- a/src/Blocks/BlockOre.h +++ b/src/Blocks/BlockOre.h @@ -64,26 +64,33 @@ private: - virtual void OnPlayerBrokeBlock( + virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - cPlayer & a_Player, Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + Vector3i a_BlockPos, + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, + const cEntity * a_Digger ) const override { - if (!a_Player.IsGameModeSurvival()) + if (!a_Digger->IsPlayer()) + { + return; + } + + const auto Player = static_cast(a_Digger); + if (!Player->IsGameModeSurvival()) { // Don't drop XP unless the player is in survival mode. return; } - if (a_Player.GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0) + if (Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0) { // Don't drop XP when the ore is mined with the Silk Touch enchantment return; } - auto & random = GetRandomProvider(); - int reward = 0; + auto & Random = GetRandomProvider(); + int Reward = 0; switch (a_OldBlockType) { @@ -91,36 +98,36 @@ private: case E_BLOCK_LAPIS_ORE: { // Lapis and nether quartz get 2 - 5 experience - reward = random.RandInt(2, 5); + Reward = Random.RandInt(2, 5); break; } case E_BLOCK_REDSTONE_ORE: case E_BLOCK_REDSTONE_ORE_GLOWING: { // Redstone gets 1 - 5 experience - reward = random.RandInt(1, 5); + Reward = Random.RandInt(1, 5); break; } case E_BLOCK_DIAMOND_ORE: case E_BLOCK_EMERALD_ORE: { // Diamond and emerald get 3 - 7 experience - reward = random.RandInt(3, 7); + Reward = Random.RandInt(3, 7); break; } case E_BLOCK_COAL_ORE: { // Coal gets 0 - 2 experience - reward = random.RandInt(2); + Reward = Random.RandInt(2); break; } default: break; } - if (reward > 0) + if (Reward > 0) { - a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, reward); + a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, Reward); } } } ; -- cgit v1.2.3