2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockOreHandler :
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
2015-02-28 10:34:17 -05:00
|
|
|
typedef cBlockHandler super;
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
|
|
|
cBlockOreHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & Random = GetRandomProvider();
|
2014-08-19 16:14:37 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
switch (m_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_LAPIS_ORE:
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
a_Pickups.emplace_back(E_ITEM_DYE, Random.RandInt<char>(4, 8), 4);
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_REDSTONE_ORE:
|
|
|
|
case E_BLOCK_REDSTONE_ORE_GLOWING:
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
a_Pickups.emplace_back(E_ITEM_REDSTONE_DUST, Random.RandInt<char>(4, 5), 0);
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_DIAMOND_ORE:
|
|
|
|
{
|
2014-08-19 16:14:37 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_DIAMOND));
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_EMERALD_ORE:
|
|
|
|
{
|
2014-08-19 16:14:37 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_EMERALD));
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_COAL_ORE:
|
|
|
|
{
|
2014-08-19 16:14:37 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_COAL));
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
2015-04-22 03:37:36 -04:00
|
|
|
case E_BLOCK_NETHER_QUARTZ_ORE:
|
|
|
|
{
|
|
|
|
a_Pickups.push_back(cItem(E_ITEM_NETHER_QUARTZ));
|
|
|
|
break;
|
|
|
|
}
|
2015-04-23 13:38:23 -04:00
|
|
|
case E_BLOCK_CLAY:
|
|
|
|
{
|
|
|
|
a_Pickups.push_back(cItem(E_ITEM_CLAY, 4));
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 16:14:37 -04:00
|
|
|
default:
|
|
|
|
{
|
2014-09-12 08:08:56 -04:00
|
|
|
a_Pickups.push_back(cItem(m_BlockType));
|
|
|
|
break;
|
2014-08-19 16:14:37 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
2015-02-28 10:34:17 -05:00
|
|
|
|
2017-07-31 16:17:52 -04:00
|
|
|
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
|
2015-02-28 10:34:17 -05:00
|
|
|
{
|
|
|
|
super::OnDestroyedByPlayer(a_ChunkInterface, a_WorldInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ);
|
|
|
|
|
2017-07-31 16:17:52 -04:00
|
|
|
if (a_Player.IsGameModeCreative())
|
2015-02-28 10:34:17 -05:00
|
|
|
{
|
|
|
|
// Don't drop XP when the player is in creative mode.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:17:52 -04:00
|
|
|
if (a_Player.GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) != 0)
|
2015-02-28 10:34:17 -05:00
|
|
|
{
|
|
|
|
// Don't drop XP when the ore is mined with the Silk Touch enchantment
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & Random = GetRandomProvider();
|
2015-02-28 10:34:17 -05:00
|
|
|
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
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = Random.RandInt(2, 5);
|
2015-02-28 10:34:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_REDSTONE_ORE:
|
|
|
|
case E_BLOCK_REDSTONE_ORE_GLOWING:
|
|
|
|
{
|
|
|
|
// Redstone gets 1 - 5 experience
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = Random.RandInt(1, 5);
|
2015-02-28 10:34:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_DIAMOND_ORE:
|
|
|
|
case E_BLOCK_EMERALD_ORE:
|
|
|
|
{
|
|
|
|
// Diamond and emerald get 3 - 7 experience
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = Random.RandInt(3, 7);
|
2015-02-28 10:34:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_COAL_ORE:
|
|
|
|
{
|
|
|
|
// Coal gets 0 - 2 experience
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = Random.RandInt(2);
|
2015-02-28 10:34:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Reward != 0)
|
|
|
|
{
|
|
|
|
a_WorldInterface.SpawnExperienceOrb(a_BlockX, a_BlockY, a_BlockZ, Reward);
|
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|