Add a few v6-exclusive trades to villagers
[MineClone/MineClone2.git] / mods / ITEMS / mcl_tools / init.lua
blobc60aafe1c7773e1f199886b49c970d03f2edb20f
1 -- mods/default/tools.lua
3 --
4 -- Tool definition
5 --
7 --[[ Maximum drop level definitions:
8 - 0: Hand
9 - 1: Wood / Shears
10 - 2: Gold
11 - 3: Stone
12 - 4: Iron
13 - 5: Diamond
16 -- TODO: Add legacy support for Minetest Game groups like crumbly, snappy, cracky, etc. for all tools
18 -- The hand
19 local groupcaps, hand_range
20 if minetest.settings:get_bool("creative_mode") then
21 -- Instant breaking in creative mode
22 groupcaps = {
23 creative_breakable = {times={[1]=0}, uses=0},
25 -- mcl_autogroup provides the creative digging times for all digging groups
26 for k,v in pairs(mcl_autogroup.creativetimes) do
27 groupcaps[k] = { times = v, uses = 0 }
28 end
29 hand_range = 10
30 else
31 groupcaps = {
32 handy_dig = {times=mcl_autogroup.digtimes.handy_dig, uses=0},
34 hand_range = 4
35 end
36 minetest.register_item(":", {
37 type = "none",
38 _doc_items_longdesc = "You use your bare hand whenever you are not wielding any item. With your hand you can mine the weakest blocks and deal minor damage by punching. Using the hand is often a last resort, as proper mining tools and weapons are better than the hand. When you are wielding an item which is not a mining tool or a weapon, it will behave as if it were the hand when you start mining or punching. In Creative Mode, the hand is able to break all blocks instantly.",
39 wield_image = "wieldhand.png",
40 wield_scale = {x=1.0,y=1.0,z=2.0},
41 -- According to Minecraft Wiki, the exact range is 3.975.
42 -- Minetest seems to only support whole numbers, so we use 4.
43 range = hand_range,
44 tool_capabilities = {
45 full_punch_interval = 0.25,
46 max_drop_level = 0,
47 groupcaps = groupcaps,
48 damage_groups = {fleshy=1},
52 -- Help texts
53 local pickaxe_longdesc = "Pickaxes are mining tools to mine hard blocks, such as stone. A pickaxe can also be used as weapon, but it is rather inefficient."
54 local axe_longdesc = "An axe is your tool of choice to cut down trees, wood-based blocks and other blocks. Axes deal a lot of damage as well, but they are rather slow."
55 local sword_longdesc = "Swords are great in melee combat, as they are fast, deal high damage and can endure countless battles. Swords can also be used to cut down a few particular blocks, such as cobwebs."
56 local shovel_longdesc = "Shovels are tools for digging coarse blocks, such as dirt, sand and gravel. They can also be used to turn grass blocks to grass paths. Shovels can be used as weapons, but they are very weak."
57 local shovel_use = "To turn a grass block into a grass path, hold the shovel in your hand, then use (rightclick) the top or side of a grass block. This only works when there's air above the grass block."
58 local shears_longdesc = "Shears are tools to shear sheep, carve pumpkins and to mine a few block types. Shears are a special mining tool and can be used to obtain the original item from a grass, leaves and similar blocks."
59 local shears_use = "To shear a sheep and obtain its wool, rightclick it. To carve a face into a pumpkin and obtain 4 pumpkin seeds, rightclick it on one of its sides. Mining works are usual, but the drops are different for a few blocks."
61 -- Picks
62 minetest.register_tool("mcl_tools:pick_wood", {
63 description = "Wooden Pickaxe",
64 _doc_items_longdesc = pickaxe_longdesc,
65 _doc_items_hidden = false,
66 inventory_image = "default_tool_woodpick.png",
67 groups = { tool=1 },
68 tool_capabilities = {
69 -- 1/1.2
70 full_punch_interval = 0.83333333,
71 max_drop_level=1,
72 groupcaps={
73 pickaxey_dig_wood = {times=mcl_autogroup.digtimes.pickaxey_dig_wood, uses=60, maxlevel=0},
75 damage_groups = {fleshy=2},
77 sound = { breaks = "default_tool_breaks" },
78 _repair_material = "group:wood",
80 minetest.register_tool("mcl_tools:pick_stone", {
81 description = "Stone Pickaxe",
82 _doc_items_longdesc = pickaxe_longdesc,
83 inventory_image = "default_tool_stonepick.png",
84 groups = { tool=1 },
85 tool_capabilities = {
86 -- 1/1.2
87 full_punch_interval = 0.83333333,
88 max_drop_level=3,
89 groupcaps={
90 pickaxey_dig_stone = {times=mcl_autogroup.digtimes.pickaxey_dig_stone, uses=132, maxlevel=0},
92 damage_groups = {fleshy=3},
94 sound = { breaks = "default_tool_breaks" },
95 _repair_material = "mcl_core:cobble",
97 minetest.register_tool("mcl_tools:pick_iron", {
98 description = "Iron Pickaxe",
99 _doc_items_longdesc = pickaxe_longdesc,
100 inventory_image = "default_tool_steelpick.png",
101 groups = { tool=1 },
102 tool_capabilities = {
103 -- 1/1.2
104 full_punch_interval = 0.83333333,
105 max_drop_level=4,
106 groupcaps={
107 pickaxey_dig_iron = {times=mcl_autogroup.digtimes.pickaxey_dig_iron , uses=251, maxlevel=0},
109 damage_groups = {fleshy=4},
111 sound = { breaks = "default_tool_breaks" },
112 _repair_material = "mcl_core:iron_ingot",
114 minetest.register_tool("mcl_tools:pick_gold", {
115 description = "Golden Pickaxe",
116 _doc_items_longdesc = pickaxe_longdesc,
117 inventory_image = "default_tool_goldpick.png",
118 groups = { tool=1 },
119 tool_capabilities = {
120 -- 1/1.2
121 full_punch_interval = 0.83333333,
122 max_drop_level=2,
123 groupcaps={
124 pickaxey_dig_gold = {times=mcl_autogroup.digtimes.pickaxey_dig_gold , uses=33, maxlevel=0},
126 damage_groups = {fleshy=2},
128 sound = { breaks = "default_tool_breaks" },
129 _repair_material = "mcl_core:gold_ingot",
131 minetest.register_tool("mcl_tools:pick_diamond", {
132 description = "Diamond Pickaxe",
133 _doc_items_longdesc = pickaxe_longdesc,
134 inventory_image = "default_tool_diamondpick.png",
135 groups = { tool=1 },
136 tool_capabilities = {
137 -- 1/1.2
138 full_punch_interval = 0.83333333,
139 max_drop_level=5,
140 groupcaps={
141 pickaxey_dig_diamond = {times=mcl_autogroup.digtimes.pickaxey_dig_diamond, uses=1562, maxlevel=0},
143 damage_groups = {fleshy=5},
145 sound = { breaks = "default_tool_breaks" },
146 _repair_material = "mcl_core:diamond",
149 local get_shovel_dig_group = function(itemstring)
150 local def = minetest.registered_items[itemstring]
151 if itemstring == "mcl_tools:shovel_wood" then
152 return "shovely_dig_wood"
153 elseif itemstring == "mcl_tools:shovel_stone" then
154 return "shovely_dig_stone"
155 elseif itemstring == "mcl_tools:shovel_iron" then
156 return "shovely_dig_iron"
157 elseif itemstring == "mcl_tools:shovel_gold" then
158 return "shovely_dig_gold"
159 elseif itemstring == "mcl_tools:shovel_diamond" then
160 return "shovely_dig_diamond"
161 else
162 -- Fallback
163 return "shovely_dig_wood"
167 local make_grass_path = function(itemstack, placer, pointed_thing)
168 -- Use pointed node's on_rightclick function first, if present
169 local node = minetest.get_node(pointed_thing.under)
170 if placer and not placer:get_player_control().sneak then
171 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
172 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
176 -- Only make grass path if tool used on side or top of target node
177 if pointed_thing.above.y < pointed_thing.under.y then
178 return
180 if (minetest.get_item_group(node.name, "grass_block") == 1) then
181 local above = table.copy(pointed_thing.under)
182 above.y = above.y + 1
183 if minetest.get_node(above).name == "air" then
184 if not minetest.settings:get_bool("creative_mode") then
185 -- Add wear, as if digging a level 0 shovely node
186 local toolname = itemstack:get_name()
187 local def = minetest.registered_items[toolname]
188 local group = get_shovel_dig_group(toolname)
189 local base_uses = def.tool_capabilities.groupcaps[group].uses
190 local maxlevel = def.tool_capabilities.groupcaps[group].maxlevel
191 local uses = base_uses * math.pow(3, maxlevel)
192 local wear = math.ceil(65535 / uses)
193 itemstack:add_wear(wear)
195 minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above})
196 minetest.swap_node(pointed_thing.under, {name="mcl_core:grass_path"})
199 return itemstack
202 local carve_pumpkin
203 if minetest.get_modpath("mcl_farming") then
204 carve_pumpkin = function(itemstack, placer, pointed_thing)
205 -- Use pointed node's on_rightclick function first, if present
206 local node = minetest.get_node(pointed_thing.under)
207 if placer and not placer:get_player_control().sneak then
208 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
209 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
213 -- Only carve pumpkin if used on side
214 if pointed_thing.above.y ~= pointed_thing.under.y then
215 return
217 if node.name == "mcl_farming:pumpkin" then
218 if not minetest.settings:get_bool("creative_mode") then
219 -- Add wear (as if digging a shearsy node)
220 local toolname = itemstack:get_name()
221 local def = minetest.registered_items[toolname]
222 local group = get_shovel_dig_group(toolname)
223 local base_uses = def.tool_capabilities.groupcaps["shearsy_dig"].uses
224 local maxlevel = def.tool_capabilities.groupcaps["shearsy_dig"].maxlevel
225 local uses = base_uses * math.pow(3, maxlevel)
226 local wear = math.ceil(65535 / uses)
227 itemstack:add_wear(wear)
229 minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above})
230 local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
231 local param2 = minetest.dir_to_facedir(dir)
232 minetest.swap_node(pointed_thing.under, {name="mcl_farming:pumpkin_face", param2 = param2})
233 minetest.add_item(pointed_thing.above, "mcl_farming:pumpkin_seeds 4")
235 return itemstack
239 -- Shovels
240 minetest.register_tool("mcl_tools:shovel_wood", {
241 description = "Wooden Shovel",
242 _doc_items_longdesc = shovel_longdesc,
243 _doc_items_usagehelp = shovel_use,
244 _doc_items_hidden = false,
245 inventory_image = "default_tool_woodshovel.png",
246 wield_image = "default_tool_woodshovel.png^[transformR90",
247 groups = { tool=1 },
248 tool_capabilities = {
249 full_punch_interval = 1,
250 max_drop_level=1,
251 groupcaps={
252 shovely_dig_wood = {times=mcl_autogroup.digtimes.shovely_dig_wood, uses=60, maxlevel=0},
254 damage_groups = {fleshy=2},
256 on_place = make_grass_path,
257 sound = { breaks = "default_tool_breaks" },
258 _repair_material = "group:wood",
260 minetest.register_tool("mcl_tools:shovel_stone", {
261 description = "Stone Shovel",
262 _doc_items_longdesc = shovel_longdesc,
263 _doc_items_usagehelp = shovel_use,
264 inventory_image = "default_tool_stoneshovel.png",
265 wield_image = "default_tool_stoneshovel.png^[transformR90",
266 groups = { tool=1 },
267 tool_capabilities = {
268 full_punch_interval = 1,
269 max_drop_level=3,
270 groupcaps={
271 shovely_dig_stone = {times=mcl_autogroup.digtimes.shovely_dig_stone, uses=132, maxlevel=0},
273 damage_groups = {fleshy=3},
275 on_place = make_grass_path,
276 sound = { breaks = "default_tool_breaks" },
277 _repair_material = "mcl_core:cobble",
279 minetest.register_tool("mcl_tools:shovel_iron", {
280 description = "Iron Shovel",
281 _doc_items_longdesc = shovel_longdesc,
282 _doc_items_usagehelp = shovel_use,
283 inventory_image = "default_tool_steelshovel.png",
284 wield_image = "default_tool_steelshovel.png^[transformR90",
285 groups = { tool=1 },
286 tool_capabilities = {
287 full_punch_interval = 1,
288 max_drop_level=4,
289 groupcaps={
290 shovely_dig_iron = {times=mcl_autogroup.digtimes.shovely_dig_iron, uses=251, maxlevel=0},
292 damage_groups = {fleshy=4},
294 on_place = make_grass_path,
295 sound = { breaks = "default_tool_breaks" },
296 _repair_material = "mcl_core:iron_ingot",
298 minetest.register_tool("mcl_tools:shovel_gold", {
299 description = "Golden Shovel",
300 _doc_items_longdesc = shovel_longdesc,
301 _doc_items_usagehelp = shovel_use,
302 inventory_image = "default_tool_goldshovel.png",
303 wield_image = "default_tool_goldshovel.png^[transformR90",
304 groups = { tool=1 },
305 tool_capabilities = {
306 full_punch_interval = 1,
307 max_drop_level=2,
308 groupcaps={
309 shovely_dig_gold = {times=mcl_autogroup.digtimes.shovely_dig_gold, uses=33, maxlevel=0},
311 damage_groups = {fleshy=2},
313 on_place = make_grass_path,
314 sound = { breaks = "default_tool_breaks" },
315 _repair_material = "mcl_core:gold_ingot",
317 minetest.register_tool("mcl_tools:shovel_diamond", {
318 description = "Diamond Shovel",
319 _doc_items_longdesc = shovel_longdesc,
320 _doc_items_usagehelp = shovel_use,
321 inventory_image = "default_tool_diamondshovel.png",
322 wield_image = "default_tool_diamondshovel.png^[transformR90",
323 groups = { tool=1 },
324 tool_capabilities = {
325 full_punch_interval = 1,
326 max_drop_level=5,
327 groupcaps={
328 shovely_dig_diamond = {times=mcl_autogroup.digtimes.shovely_dig_diamond, uses=1562, maxlevel=0},
330 damage_groups = {fleshy=5},
332 on_place = make_grass_path,
333 sound = { breaks = "default_tool_breaks" },
334 _repair_material = "mcl_core:diamond",
337 -- Axes
338 minetest.register_tool("mcl_tools:axe_wood", {
339 description = "Wooden Axe",
340 _doc_items_longdesc = axe_longdesc,
341 _doc_items_hidden = false,
342 inventory_image = "default_tool_woodaxe.png",
343 groups = { tool=1 },
344 tool_capabilities = {
345 full_punch_interval = 1.25,
346 max_drop_level=1,
347 groupcaps={
348 axey_dig_wood = {times=mcl_autogroup.digtimes.axey_dig_wood, uses=60, maxlevel=0},
350 damage_groups = {fleshy=7},
352 sound = { breaks = "default_tool_breaks" },
353 _repair_material = "group:wood",
355 minetest.register_tool("mcl_tools:axe_stone", {
356 description = "Stone Axe",
357 _doc_items_longdesc = axe_longdesc,
358 inventory_image = "default_tool_stoneaxe.png",
359 groups = { tool=1 },
360 tool_capabilities = {
361 full_punch_interval = 1.25,
362 max_drop_level=3,
363 groupcaps={
364 axey_dig_stone = {times=mcl_autogroup.digtimes.axey_dig_stone, uses=132, maxlevel=0},
366 damage_groups = {fleshy=9},
368 sound = { breaks = "default_tool_breaks" },
369 _repair_material = "mcl_core:cobble",
371 minetest.register_tool("mcl_tools:axe_iron", {
372 description = "Iron Axe",
373 _doc_items_longdesc = axe_longdesc,
374 inventory_image = "default_tool_steelaxe.png",
375 groups = { tool=1 },
376 tool_capabilities = {
377 -- 1/0.9
378 full_punch_interval = 1.11111111,
379 max_drop_level=4,
380 groupcaps={
381 axey_dig_iron = {times=mcl_autogroup.digtimes.axey_dig_iron, uses=251, maxlevel=0},
383 damage_groups = {fleshy=9},
385 sound = { breaks = "default_tool_breaks" },
386 _repair_material = "mcl_core:iron_ingot",
388 minetest.register_tool("mcl_tools:axe_gold", {
389 description = "Golden Axe",
390 _doc_items_longdesc = axe_longdesc,
391 inventory_image = "default_tool_goldaxe.png",
392 groups = { tool=1 },
393 tool_capabilities = {
394 full_punch_interval = 1.0,
395 max_drop_level=2,
396 groupcaps={
397 axey_dig_gold= {times=mcl_autogroup.digtimes.axey_dig_gold, uses=33, maxlevel=0},
399 damage_groups = {fleshy=7},
401 sound = { breaks = "default_tool_breaks" },
402 _repair_material = "mcl_core:gold_ingot",
404 minetest.register_tool("mcl_tools:axe_diamond", {
405 description = "Diamond Axe",
406 _doc_items_longdesc = axe_longdesc,
407 inventory_image = "default_tool_diamondaxe.png",
408 groups = { tool=1 },
409 tool_capabilities = {
410 full_punch_interval = 1.0,
411 max_drop_level=5,
412 groupcaps={
413 axey_dig_diamond = {times=mcl_autogroup.digtimes.axey_dig_diamond, uses=1562, maxlevel=0},
415 damage_groups = {fleshy=9},
417 sound = { breaks = "default_tool_breaks" },
418 _repair_material = "mcl_core:diamond",
421 -- Swords
422 minetest.register_tool("mcl_tools:sword_wood", {
423 description = "Wooden Sword",
424 _doc_items_longdesc = sword_longdesc,
425 _doc_items_hidden = false,
426 inventory_image = "default_tool_woodsword.png",
427 groups = { weapon=1 },
428 tool_capabilities = {
429 full_punch_interval = 0.625,
430 max_drop_level=1,
431 groupcaps={
432 swordy_dig = {times=mcl_autogroup.digtimes.swordy_dig , uses=60, maxlevel=0},
433 swordy_cobweb_dig = {times=mcl_autogroup.digtimes.swordy_cobweb_dig , uses=60, maxlevel=0},
435 damage_groups = {fleshy=4},
437 sound = { breaks = "default_tool_breaks" },
438 _repair_material = "group:wood",
440 minetest.register_tool("mcl_tools:sword_stone", {
441 description = "Stone Sword",
442 _doc_items_longdesc = sword_longdesc,
443 inventory_image = "default_tool_stonesword.png",
444 groups = { weapon=1 },
445 tool_capabilities = {
446 full_punch_interval = 0.625,
447 max_drop_level=3,
448 groupcaps={
449 swordy_dig = {times=mcl_autogroup.digtimes.swordy_dig , uses=132, maxlevel=0},
450 swordy_cobweb_dig = {times=mcl_autogroup.digtimes.swordy_cobweb_dig , uses=132, maxlevel=0},
452 damage_groups = {fleshy=5},
454 sound = { breaks = "default_tool_breaks" },
455 _repair_material = "mcl_core:cobble",
457 minetest.register_tool("mcl_tools:sword_iron", {
458 description = "Iron Sword",
459 _doc_items_longdesc = sword_longdesc,
460 inventory_image = "default_tool_steelsword.png",
461 groups = { weapon=1 },
462 tool_capabilities = {
463 full_punch_interval = 0.625,
464 max_drop_level=4,
465 groupcaps={
466 swordy_dig = {times=mcl_autogroup.digtimes.swordy_dig, uses=251, maxlevel=0},
467 swordy_cobweb_dig = {times=mcl_autogroup.digtimes.swordy_cobweb_dig , uses=251, maxlevel=0},
469 damage_groups = {fleshy=6},
471 sound = { breaks = "default_tool_breaks" },
472 _repair_material = "mcl_core:iron_ingot",
474 minetest.register_tool("mcl_tools:sword_gold", {
475 description = "Golden Sword",
476 _doc_items_longdesc = sword_longdesc,
477 inventory_image = "default_tool_goldsword.png",
478 groups = { weapon=1 },
479 tool_capabilities = {
480 full_punch_interval = 0.625,
481 max_drop_level=2,
482 groupcaps={
483 swordy_dig = {times=mcl_autogroup.digtimes.swordy_dig, uses=33, maxlevel=0},
484 swordy_cobweb_dig = {times=mcl_autogroup.digtimes.swordy_cobweb_dig, uses=33, maxlevel=0},
486 damage_groups = {fleshy=4},
488 sound = { breaks = "default_tool_breaks" },
489 _repair_material = "mcl_core:gold_ingot",
491 minetest.register_tool("mcl_tools:sword_diamond", {
492 description = "Diamond Sword",
493 _doc_items_longdesc = sword_longdesc,
494 inventory_image = "default_tool_diamondsword.png",
495 groups = { weapon=1 },
496 tool_capabilities = {
497 full_punch_interval = 0.625,
498 max_drop_level=5,
499 groupcaps={
500 swordy_dig = {times=mcl_autogroup.digtimes.swordy_dig, uses=1562, maxlevel=0},
501 swordy_cobweb_dig = {times=mcl_autogroup.digtimes.swordy_cobweb_dig, uses=1562, maxlevel=0},
503 damage_groups = {fleshy=7},
505 sound = { breaks = "default_tool_breaks" },
506 _repair_material = "mcl_core:diamond",
509 --Shears
510 minetest.register_tool("mcl_tools:shears", {
511 description = "Shears",
512 _doc_items_longdesc = shears_longdesc,
513 _doc_items_usagehelp = shears_use,
514 inventory_image = "default_tool_shears.png",
515 wield_image = "default_tool_shears.png",
516 stack_max = 1,
517 groups = { tool=1 },
518 tool_capabilities = {
519 full_punch_interval = 0.5,
520 max_drop_level=1,
521 groupcaps={
522 shearsy_dig = {times=mcl_autogroup.digtimes.shearsy_dig, uses=238, maxlevel=0},
523 shearsy_wool_dig = {times=mcl_autogroup.digtimes.shearsy_wool_dig, uses=238, maxlevel=0},
526 on_place = carve_pumpkin,
527 sound = { breaks = "default_tool_breaks" },
531 dofile(minetest.get_modpath("mcl_tools").."/crafting.lua")
532 dofile(minetest.get_modpath("mcl_tools").."/aliases.lua")