player_api: Prevent knockback when player is set as attached
[oweals/minetest_game.git] / mods / default / tools.lua
1 -- mods/default/tools.lua
2
3 -- support for MT game translation.
4 local S = default.get_translator
5
6 -- The hand
7 minetest.register_item(":", {
8         type = "none",
9         wield_image = "wieldhand.png",
10         wield_scale = {x=1,y=1,z=2.5},
11         tool_capabilities = {
12                 full_punch_interval = 0.9,
13                 max_drop_level = 0,
14                 groupcaps = {
15                         crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
16                         snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
17                         oddly_breakable_by_hand = {times={[1]=3.50,[2]=2.00,[3]=0.70}, uses=0}
18                 },
19                 damage_groups = {fleshy=1},
20         }
21 })
22
23 --
24 -- Picks
25 --
26
27 minetest.register_tool("default:pick_wood", {
28         description = S("Wooden Pickaxe"),
29         inventory_image = "default_tool_woodpick.png",
30         tool_capabilities = {
31                 full_punch_interval = 1.2,
32                 max_drop_level=0,
33                 groupcaps={
34                         cracky = {times={[3]=1.60}, uses=10, maxlevel=1},
35                 },
36                 damage_groups = {fleshy=2},
37         },
38         sound = {breaks = "default_tool_breaks"},
39         groups = {pickaxe = 1, flammable = 2}
40 })
41
42 minetest.register_tool("default:pick_stone", {
43         description = S("Stone Pickaxe"),
44         inventory_image = "default_tool_stonepick.png",
45         tool_capabilities = {
46                 full_punch_interval = 1.3,
47                 max_drop_level=0,
48                 groupcaps={
49                         cracky = {times={[2]=2.0, [3]=1.00}, uses=20, maxlevel=1},
50                 },
51                 damage_groups = {fleshy=3},
52         },
53         sound = {breaks = "default_tool_breaks"},
54         groups = {pickaxe = 1}
55 })
56
57 minetest.register_tool("default:pick_bronze", {
58         description = S("Bronze Pickaxe"),
59         inventory_image = "default_tool_bronzepick.png",
60         tool_capabilities = {
61                 full_punch_interval = 1.0,
62                 max_drop_level=1,
63                 groupcaps={
64                         cracky = {times={[1]=4.50, [2]=1.80, [3]=0.90}, uses=20, maxlevel=2},
65                 },
66                 damage_groups = {fleshy=4},
67         },
68         sound = {breaks = "default_tool_breaks"},
69         groups = {pickaxe = 1}
70 })
71
72 minetest.register_tool("default:pick_steel", {
73         description = S("Steel Pickaxe"),
74         inventory_image = "default_tool_steelpick.png",
75         tool_capabilities = {
76                 full_punch_interval = 1.0,
77                 max_drop_level=1,
78                 groupcaps={
79                         cracky = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=20, maxlevel=2},
80                 },
81                 damage_groups = {fleshy=4},
82         },
83         sound = {breaks = "default_tool_breaks"},
84         groups = {pickaxe = 1}
85 })
86
87 minetest.register_tool("default:pick_mese", {
88         description = S("Mese Pickaxe"),
89         inventory_image = "default_tool_mesepick.png",
90         tool_capabilities = {
91                 full_punch_interval = 0.9,
92                 max_drop_level=3,
93                 groupcaps={
94                         cracky = {times={[1]=2.4, [2]=1.2, [3]=0.60}, uses=20, maxlevel=3},
95                 },
96                 damage_groups = {fleshy=5},
97         },
98         sound = {breaks = "default_tool_breaks"},
99         groups = {pickaxe = 1}
100 })
101
102 minetest.register_tool("default:pick_diamond", {
103         description = S("Diamond Pickaxe"),
104         inventory_image = "default_tool_diamondpick.png",
105         tool_capabilities = {
106                 full_punch_interval = 0.9,
107                 max_drop_level=3,
108                 groupcaps={
109                         cracky = {times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=30, maxlevel=3},
110                 },
111                 damage_groups = {fleshy=5},
112         },
113         sound = {breaks = "default_tool_breaks"},
114         groups = {pickaxe = 1}
115 })
116
117 --
118 -- Shovels
119 --
120
121 minetest.register_tool("default:shovel_wood", {
122         description = S("Wooden Shovel"),
123         inventory_image = "default_tool_woodshovel.png",
124         wield_image = "default_tool_woodshovel.png^[transformR90",
125         tool_capabilities = {
126                 full_punch_interval = 1.2,
127                 max_drop_level=0,
128                 groupcaps={
129                         crumbly = {times={[1]=3.00, [2]=1.60, [3]=0.60}, uses=10, maxlevel=1},
130                 },
131                 damage_groups = {fleshy=2},
132         },
133         sound = {breaks = "default_tool_breaks"},
134         groups = {shovel = 1, flammable = 2}
135 })
136
137 minetest.register_tool("default:shovel_stone", {
138         description = S("Stone Shovel"),
139         inventory_image = "default_tool_stoneshovel.png",
140         wield_image = "default_tool_stoneshovel.png^[transformR90",
141         tool_capabilities = {
142                 full_punch_interval = 1.4,
143                 max_drop_level=0,
144                 groupcaps={
145                         crumbly = {times={[1]=1.80, [2]=1.20, [3]=0.50}, uses=20, maxlevel=1},
146                 },
147                 damage_groups = {fleshy=2},
148         },
149         sound = {breaks = "default_tool_breaks"},
150         groups = {shovel = 1}
151 })
152
153 minetest.register_tool("default:shovel_bronze", {
154         description = S("Bronze Shovel"),
155         inventory_image = "default_tool_bronzeshovel.png",
156         wield_image = "default_tool_bronzeshovel.png^[transformR90",
157         tool_capabilities = {
158                 full_punch_interval = 1.1,
159                 max_drop_level=1,
160                 groupcaps={
161                         crumbly = {times={[1]=1.65, [2]=1.05, [3]=0.45}, uses=25, maxlevel=2},
162                 },
163                 damage_groups = {fleshy=3},
164         },
165         sound = {breaks = "default_tool_breaks"},
166         groups = {shovel = 1}
167 })
168
169 minetest.register_tool("default:shovel_steel", {
170         description = S("Steel Shovel"),
171         inventory_image = "default_tool_steelshovel.png",
172         wield_image = "default_tool_steelshovel.png^[transformR90",
173         tool_capabilities = {
174                 full_punch_interval = 1.1,
175                 max_drop_level=1,
176                 groupcaps={
177                         crumbly = {times={[1]=1.50, [2]=0.90, [3]=0.40}, uses=30, maxlevel=2},
178                 },
179                 damage_groups = {fleshy=3},
180         },
181         sound = {breaks = "default_tool_breaks"},
182         groups = {shovel = 1}
183 })
184
185 minetest.register_tool("default:shovel_mese", {
186         description = S("Mese Shovel"),
187         inventory_image = "default_tool_meseshovel.png",
188         wield_image = "default_tool_meseshovel.png^[transformR90",
189         tool_capabilities = {
190                 full_punch_interval = 1.0,
191                 max_drop_level=3,
192                 groupcaps={
193                         crumbly = {times={[1]=1.20, [2]=0.60, [3]=0.30}, uses=20, maxlevel=3},
194                 },
195                 damage_groups = {fleshy=4},
196         },
197         sound = {breaks = "default_tool_breaks"},
198         groups = {shovel = 1}
199 })
200
201 minetest.register_tool("default:shovel_diamond", {
202         description = S("Diamond Shovel"),
203         inventory_image = "default_tool_diamondshovel.png",
204         wield_image = "default_tool_diamondshovel.png^[transformR90",
205         tool_capabilities = {
206                 full_punch_interval = 1.0,
207                 max_drop_level=1,
208                 groupcaps={
209                         crumbly = {times={[1]=1.10, [2]=0.50, [3]=0.30}, uses=30, maxlevel=3},
210                 },
211                 damage_groups = {fleshy=4},
212         },
213         sound = {breaks = "default_tool_breaks"},
214         groups = {shovel = 1}
215 })
216
217 --
218 -- Axes
219 --
220
221 minetest.register_tool("default:axe_wood", {
222         description = S("Wooden Axe"),
223         inventory_image = "default_tool_woodaxe.png",
224         tool_capabilities = {
225                 full_punch_interval = 1.0,
226                 max_drop_level=0,
227                 groupcaps={
228                         choppy = {times={[2]=3.00, [3]=1.60}, uses=10, maxlevel=1},
229                 },
230                 damage_groups = {fleshy=2},
231         },
232         sound = {breaks = "default_tool_breaks"},
233         groups = {axe = 1, flammable = 2}
234 })
235
236 minetest.register_tool("default:axe_stone", {
237         description = S("Stone Axe"),
238         inventory_image = "default_tool_stoneaxe.png",
239         tool_capabilities = {
240                 full_punch_interval = 1.2,
241                 max_drop_level=0,
242                 groupcaps={
243                         choppy={times={[1]=3.00, [2]=2.00, [3]=1.30}, uses=20, maxlevel=1},
244                 },
245                 damage_groups = {fleshy=3},
246         },
247         sound = {breaks = "default_tool_breaks"},
248         groups = {axe = 1}
249 })
250
251 minetest.register_tool("default:axe_bronze", {
252         description = S("Bronze Axe"),
253         inventory_image = "default_tool_bronzeaxe.png",
254         tool_capabilities = {
255                 full_punch_interval = 1.0,
256                 max_drop_level=1,
257                 groupcaps={
258                         choppy={times={[1]=2.75, [2]=1.70, [3]=1.15}, uses=20, maxlevel=2},
259                 },
260                 damage_groups = {fleshy=4},
261         },
262         sound = {breaks = "default_tool_breaks"},
263         groups = {axe = 1}
264 })
265
266 minetest.register_tool("default:axe_steel", {
267         description = S("Steel Axe"),
268         inventory_image = "default_tool_steelaxe.png",
269         tool_capabilities = {
270                 full_punch_interval = 1.0,
271                 max_drop_level=1,
272                 groupcaps={
273                         choppy={times={[1]=2.50, [2]=1.40, [3]=1.00}, uses=20, maxlevel=2},
274                 },
275                 damage_groups = {fleshy=4},
276         },
277         sound = {breaks = "default_tool_breaks"},
278         groups = {axe = 1}
279 })
280
281 minetest.register_tool("default:axe_mese", {
282         description = S("Mese Axe"),
283         inventory_image = "default_tool_meseaxe.png",
284         tool_capabilities = {
285                 full_punch_interval = 0.9,
286                 max_drop_level=1,
287                 groupcaps={
288                         choppy={times={[1]=2.20, [2]=1.00, [3]=0.60}, uses=20, maxlevel=3},
289                 },
290                 damage_groups = {fleshy=6},
291         },
292         sound = {breaks = "default_tool_breaks"},
293         groups = {axe = 1}
294 })
295
296 minetest.register_tool("default:axe_diamond", {
297         description = S("Diamond Axe"),
298         inventory_image = "default_tool_diamondaxe.png",
299         tool_capabilities = {
300                 full_punch_interval = 0.9,
301                 max_drop_level=1,
302                 groupcaps={
303                         choppy={times={[1]=2.10, [2]=0.90, [3]=0.50}, uses=30, maxlevel=3},
304                 },
305                 damage_groups = {fleshy=7},
306         },
307         sound = {breaks = "default_tool_breaks"},
308         groups = {axe = 1}
309 })
310
311 --
312 -- Swords
313 --
314
315 minetest.register_tool("default:sword_wood", {
316         description = S("Wooden Sword"),
317         inventory_image = "default_tool_woodsword.png",
318         tool_capabilities = {
319                 full_punch_interval = 1,
320                 max_drop_level=0,
321                 groupcaps={
322                         snappy={times={[2]=1.6, [3]=0.40}, uses=10, maxlevel=1},
323                 },
324                 damage_groups = {fleshy=2},
325         },
326         sound = {breaks = "default_tool_breaks"},
327         groups = {sword = 1, flammable = 2}
328 })
329
330 minetest.register_tool("default:sword_stone", {
331         description = S("Stone Sword"),
332         inventory_image = "default_tool_stonesword.png",
333         tool_capabilities = {
334                 full_punch_interval = 1.2,
335                 max_drop_level=0,
336                 groupcaps={
337                         snappy={times={[2]=1.4, [3]=0.40}, uses=20, maxlevel=1},
338                 },
339                 damage_groups = {fleshy=4},
340         },
341         sound = {breaks = "default_tool_breaks"},
342         groups = {sword = 1}
343 })
344
345 minetest.register_tool("default:sword_bronze", {
346         description = S("Bronze Sword"),
347         inventory_image = "default_tool_bronzesword.png",
348         tool_capabilities = {
349                 full_punch_interval = 0.8,
350                 max_drop_level=1,
351                 groupcaps={
352                         snappy={times={[1]=2.75, [2]=1.30, [3]=0.375}, uses=25, maxlevel=2},
353                 },
354                 damage_groups = {fleshy=6},
355         },
356         sound = {breaks = "default_tool_breaks"},
357         groups = {sword = 1}
358 })
359
360 minetest.register_tool("default:sword_steel", {
361         description = S("Steel Sword"),
362         inventory_image = "default_tool_steelsword.png",
363         tool_capabilities = {
364                 full_punch_interval = 0.8,
365                 max_drop_level=1,
366                 groupcaps={
367                         snappy={times={[1]=2.5, [2]=1.20, [3]=0.35}, uses=30, maxlevel=2},
368                 },
369                 damage_groups = {fleshy=6},
370         },
371         sound = {breaks = "default_tool_breaks"},
372         groups = {sword = 1}
373 })
374
375 minetest.register_tool("default:sword_mese", {
376         description = S("Mese Sword"),
377         inventory_image = "default_tool_mesesword.png",
378         tool_capabilities = {
379                 full_punch_interval = 0.7,
380                 max_drop_level=1,
381                 groupcaps={
382                         snappy={times={[1]=2.0, [2]=1.00, [3]=0.35}, uses=30, maxlevel=3},
383                 },
384                 damage_groups = {fleshy=7},
385         },
386         sound = {breaks = "default_tool_breaks"},
387         groups = {sword = 1}
388 })
389
390 minetest.register_tool("default:sword_diamond", {
391         description = S("Diamond Sword"),
392         inventory_image = "default_tool_diamondsword.png",
393         tool_capabilities = {
394                 full_punch_interval = 0.7,
395                 max_drop_level=1,
396                 groupcaps={
397                         snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=40, maxlevel=3},
398                 },
399                 damage_groups = {fleshy=8},
400         },
401         sound = {breaks = "default_tool_breaks"},
402         groups = {sword = 1}
403 })
404
405 --
406 -- Register Craft Recipies
407 --
408
409 local craft_ingreds = {
410         wood = "group:wood",
411         stone = "group:stone",
412         steel = "default:steel_ingot",
413         bronze = "default:bronze_ingot",
414         mese = "default:mese_crystal",
415         diamond = "default:diamond"
416 }
417
418 for name, mat in pairs(craft_ingreds) do
419         minetest.register_craft({
420                 output = "default:pick_".. name,
421                 recipe = {
422                         {mat, mat, mat},
423                         {"", "group:stick", ""},
424                         {"", "group:stick", ""}
425                 }
426         })
427
428         minetest.register_craft({
429                 output = "default:shovel_".. name,
430                 recipe = {
431                         {mat},
432                         {"group:stick"},
433                         {"group:stick"}
434                 }
435         })
436
437         minetest.register_craft({
438                 output = "default:axe_".. name,
439                 recipe = {
440                         {mat, mat},
441                         {mat, "group:stick"},
442                         {"", "group:stick"}
443                 }
444         })
445
446         minetest.register_craft({
447                 output = "default:sword_".. name,
448                 recipe = {
449                         {mat},
450                         {mat},
451                         {"group:stick"}
452                 }
453         })
454 end
455
456 minetest.register_tool("default:key", {
457         description = S("Key"),
458         inventory_image = "default_key.png",
459         groups = {key = 1, not_in_creative_inventory = 1},
460         stack_max = 1,
461         on_place = function(itemstack, placer, pointed_thing)
462                 local under = pointed_thing.under
463                 local node = minetest.get_node(under)
464                 local def = minetest.registered_nodes[node.name]
465                 if def and def.on_rightclick and
466                                 not (placer and placer:is_player() and
467                                 placer:get_player_control().sneak) then
468                         return def.on_rightclick(under, node, placer, itemstack,
469                                 pointed_thing) or itemstack
470                 end
471                 if pointed_thing.type ~= "node" then
472                         return itemstack
473                 end
474
475                 local pos = pointed_thing.under
476                 node = minetest.get_node(pos)
477
478                 if not node or node.name == "ignore" then
479                         return itemstack
480                 end
481
482                 local ndef = minetest.registered_nodes[node.name]
483                 if not ndef then
484                         return itemstack
485                 end
486
487                 local on_key_use = ndef.on_key_use
488                 if on_key_use then
489                         on_key_use(pos, placer)
490                 end
491
492                 return nil
493         end
494 })
495
496 minetest.register_craft({
497         type = "fuel",
498         recipe = "default:pick_wood",
499         burntime = 6,
500 })
501
502 minetest.register_craft({
503         type = "fuel",
504         recipe = "default:shovel_wood",
505         burntime = 4,
506 })
507
508 minetest.register_craft({
509         type = "fuel",
510         recipe = "default:axe_wood",
511         burntime = 6,
512 })
513
514 minetest.register_craft({
515         type = "fuel",
516         recipe = "default:sword_wood",
517         burntime = 5,
518 })