summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockOre.h
blob: 08d79f4358fcf706442889c67aed05e82c3c5cc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

#pragma once

#include "BlockHandler.h"
#include "../World.h"





class cBlockOreHandler :
	public cBlockHandler
{
	typedef cBlockHandler super;
public:
	cBlockOreHandler(BLOCKTYPE a_BlockType)
		: cBlockHandler(a_BlockType)
	{
	}

	virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
	{
		cFastRandom Random;

		switch (m_BlockType)
		{
			case E_BLOCK_LAPIS_ORE:
			{
				a_Pickups.push_back(cItem(E_ITEM_DYE, (char)(4 + Random.NextInt(5)), 4));
				break;
			}
			case E_BLOCK_REDSTONE_ORE:
			case E_BLOCK_REDSTONE_ORE_GLOWING:
			{
				a_Pickups.push_back(cItem(E_ITEM_REDSTONE_DUST, (char)(4 + Random.NextInt(2)), 0));
				break;
			}
			case E_BLOCK_DIAMOND_ORE:
			{
				a_Pickups.push_back(cItem(E_ITEM_DIAMOND));
				break;
			}
			case E_BLOCK_EMERALD_ORE:
			{
				a_Pickups.push_back(cItem(E_ITEM_EMERALD));
				break;
			}
			case E_BLOCK_COAL_ORE:
			{
				a_Pickups.push_back(cItem(E_ITEM_COAL));
				break;
			}
			default:
			{
				a_Pickups.push_back(cItem(m_BlockType));
				break;
			}
		}
	}

	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);
		}
	}
} ;