summaryrefslogtreecommitdiffstats
path: root/source/cBlockToPickup.cpp
blob: eec75018318bb37005d46c999ca2a55b45a36650 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "cBlockToPickup.h"
#include "Defines.h"
#include "BlockID.h"
#include "MersenneTwister.h"





static void AddRandomDrop(cItems & a_Drops, MTRand & r1, int a_OneInNChance, ENUM_ITEM_ID a_ItemID)
{
	if ((r1.randInt(16 * a_OneInNChance - 1) / 16) != 0)
	{
		return;
	}
	a_Drops.push_back(cItem(a_ItemID, 1));
}





void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cItem & a_UsedItem, cItems & a_Drops)
{
	MTRand r1;

	switch (a_BlockType)
	{
		// Blocks that always drop themselves as the only item, no matter what tool; copy damage from meta:
		case E_BLOCK_LOG:
		case E_BLOCK_PLANKS:
		case E_BLOCK_WOOL:
		{
			a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1, a_BlockMeta));
			return;
		}
		
		
		// Blocks that always drop themselves as the only item, no matter what tool, set damage value zero:
		case E_BLOCK_DIRT:
		case E_BLOCK_SAPLING:
		case E_BLOCK_SAND:
		case E_BLOCK_TORCH:
		case E_BLOCK_YELLOW_FLOWER:
		case E_BLOCK_RED_ROSE:
		case E_BLOCK_BROWN_MUSHROOM:
		case E_BLOCK_RED_MUSHROOM:
		case E_BLOCK_TNT:
		case E_BLOCK_CRAFTING_TABLE:
		case E_BLOCK_FURNACE:
		case E_BLOCK_CACTUS:
		case E_BLOCK_REDSTONE_TORCH_OFF:
		case E_BLOCK_POWERED_RAIL:
		case E_BLOCK_DETECTOR_RAIL:
		case E_BLOCK_RAIL:
		case E_BLOCK_LADDER:
		case E_BLOCK_LEVER:
		case E_BLOCK_WOODEN_PRESSURE_PLATE:
		case E_BLOCK_STONE_BUTTON:
		case E_BLOCK_JUKEBOX:
		case E_BLOCK_FENCE:
		case E_BLOCK_FENCE_GATE:
		case E_BLOCK_PUMPKIN:
		case E_BLOCK_NETHERRACK:
		case E_BLOCK_SOULSAND:
		case E_BLOCK_JACK_O_LANTERN:
		case E_BLOCK_TRAPDOOR:
		{
			a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1, 0));
			return;
		}
		
		
		// Blocks that always drop a single item, no matter what tool:
		case E_BLOCK_SIGN_POST:
		case E_BLOCK_WALLSIGN:              a_Drops.push_back(cItem(E_ITEM_SIGN, 1));              return;
		case E_BLOCK_REDSTONE_WIRE:         a_Drops.push_back(cItem(E_ITEM_REDSTONE_DUST, 1));     return;
		case E_BLOCK_GLOWSTONE:             a_Drops.push_back(cItem(E_ITEM_GLOWSTONE_DUST, 1));    return;
		case E_BLOCK_REDSTONE_REPEATER_OFF:
		case E_BLOCK_REDSTONE_REPEATER_ON:  a_Drops.push_back(cItem(E_ITEM_REDSTONE_REPEATER, 1)); return;
		case E_BLOCK_COBWEB:                a_Drops.push_back(cItem(E_ITEM_STRING, 1));            return;
		case E_BLOCK_FARMLAND:
		case E_BLOCK_GRASS:                 a_Drops.push_back(cItem(E_ITEM_DIRT, 1));              return;
		case E_BLOCK_LIT_FURNACE:           a_Drops.push_back(cItem(E_ITEM_FURNACE, 1));           return;
		case E_BLOCK_SUGARCANE:             a_Drops.push_back(cItem(E_ITEM_SUGARCANE, 1));         return;
		case E_BLOCK_PUMPKIN_STEM:          a_Drops.push_back(cItem(E_ITEM_PUMPKIN_SEEDS, 1));     return;
		case E_BLOCK_MELON_STEM:            a_Drops.push_back(cItem(E_ITEM_MELON_SEEDS, 1));       return;
		
		
		// Doors seem to need their meta set to 1
		case E_BLOCK_WOODEN_DOOR: a_Drops.push_back(cItem(E_ITEM_WOODEN_DOOR, 1, 1)); return;
		case E_BLOCK_IRON_DOOR:   a_Drops.push_back(cItem(E_ITEM_IRON_DOOR,   1, 1)); return;
		

		////////////////////////
		// Ores:
		
		// Coal ore requires a pickaxe:
		case E_BLOCK_COAL_ORE:
		{
			if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
			{
				a_Drops.push_back(cItem(E_ITEM_COAL, 1));
			}
			return;
		}
		
		// Iron ore requires a stone or better pickaxe:
		case E_BLOCK_IRON_ORE:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE)  ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem(E_ITEM_IRON_ORE, 1));
			}
			return;
		}
		
		// Gold and diamond ores require an iron or better pickaxe:
		case E_BLOCK_GOLD_ORE:
		case E_BLOCK_DIAMOND_ORE:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
			}
			return;
		}

		// Obsidian require a diamond pickaxe:
		case E_BLOCK_OBSIDIAN:
		{
			if (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			{
				a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
			}
			return;
		}

		// Redstone requires an iron or better pickaxe:
		case E_BLOCK_REDSTONE_ORE_GLOWING:
		case E_BLOCK_REDSTONE_ORE:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem(E_ITEM_REDSTONE_DUST, 4 + (short)r1.randInt(1)));
			}
			return;
		}
				
		// Lapis ore requires a stone or better pickaxe:
		case E_BLOCK_LAPIS_ORE:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE)  ||
				(a_UsedItem.m_ItemID == E_ITEM_GOLD_PICKAXE)  ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem(E_ITEM_DYE, 4 + (short)r1.randInt(4), E_META_DYE_BLUE));
			}
			return;
		}
		

		////////////////////////
		// Resource blocks:
		
		// Iron and lapis blocks require a stone or better pickaxe:
		case E_BLOCK_IRON_BLOCK:
		case E_BLOCK_LAPIS_BLOCK:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE)  ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
			}
			return;
		}
		
		// Diamond and gold blocks require an iron or better pickaxe:
		case E_BLOCK_DIAMOND_BLOCK:
		{
			if (
				(a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
				(a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
			)
			{
				a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
			}
		}
		
		
		// These blocks require a pickaxe to drop themselves:
		case E_BLOCK_COBBLESTONE:
		case E_BLOCK_BRICK:
		case E_BLOCK_NETHER_BRICK:
		case E_BLOCK_MOSSY_COBBLESTONE:
		case E_BLOCK_STONE_SLAB:
		case E_BLOCK_COBBLESTONE_STAIRS:
		case E_BLOCK_STONE_BRICK_STAIRS:
		case E_BLOCK_NETHER_BRICK_STAIRS:
		case E_BLOCK_SANDSTONE_STAIRS:
		case E_BLOCK_SANDSTONE:
		case E_BLOCK_STONE_PRESSURE_PLATE:
		{
			if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
			{
				a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
			}
			return;
		}
		

		// Stone requires a pickaxe to drop cobblestone:
		case E_BLOCK_STONE:
		{
			if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
			{
				a_Drops.push_back(cItem(E_ITEM_COBBLESTONE, 1));
			}
			return;
		}


		// Snow requires a shovel to harvest:
		case E_BLOCK_SNOW:
		{
			if (ItemCategory::IsShovel(a_UsedItem.m_ItemID))
			{
				a_Drops.push_back(cItem(E_ITEM_SNOWBALL, 1));
			}
			return;
		}
		
		
		// Leaves require shears for harvesting and have a chance of dropping a sapling and a red apple:
		case E_BLOCK_LEAVES:
		{
			if (a_UsedItem.m_ItemID == E_ITEM_SHEARS)
			{
				a_Drops.push_back(cItem(E_ITEM_LEAVES, 1));
			}
			else
			{
				AddRandomDrop(a_Drops, r1, 5,   E_ITEM_SAPLING);
				if (a_BlockMeta == E_META_LEAVES_APPLE)
				{
					AddRandomDrop(a_Drops, r1, 200, E_ITEM_APPLE);
				}
			}
			return;
		}
		
		
		// Crops drop a wheat and possibly another seeds when ripe; always drop at least a single seed
		case E_BLOCK_CROPS:
		{
			if (a_BlockMeta == 7)
			{
				AddRandomDrop(a_Drops, r1, 3, E_ITEM_SEEDS);
				a_Drops.push_back(cItem(E_ITEM_WHEAT, 1));
			}
			a_Drops.push_back(cItem(E_ITEM_SEEDS, 1));
			return;
		}
		
		
		// Vines drop only with shears, otherwise they are destroyed
		case E_BLOCK_VINES:
		{
			if (a_UsedItem.m_ItemID == E_ITEM_SHEARS)
			{
				a_Drops.push_back(cItem(E_ITEM_VINES, 1));
			}
			return;
		}
		
		
		// Snow drops only when using a shovel
		case E_BLOCK_SNOW_BLOCK:
		{
			if (ItemCategory::IsShovel(a_UsedItem.m_ItemID))
			{
				a_Drops.push_back(cItem(E_ITEM_SNOWBALL,   4, 0)); return;
			}
			return;
		}


		// Random multi-drop blocks:
		case E_BLOCK_TALL_GRASS: a_Drops.push_back(cItem(E_ITEM_SEEDS,           (short)r1.randInt(3) / 2, 1)); return;
		case E_BLOCK_MELON:      a_Drops.push_back(cItem(E_ITEM_MELON_SLICE, 3 + (short)r1.randInt(2),     1)); return;
		

		// Fixed multi-drop blocks:
		case E_BLOCK_DOUBLE_STONE_SLAB:  a_Drops.push_back(cItem(E_ITEM_STONE_SLAB, 2, 0)); return;
		case E_BLOCK_DOUBLE_WOODEN_SLAB: a_Drops.push_back(cItem(E_ITEM_STEP,       2, 0)); return;
		
		default:
		{
			return;
		}
	}  // switch (a_BlockType)
}