]> git.lizzy.rs Git - mcl_enchanting.git/blob - silk_touch.lua
Add crafting recipe
[mcl_enchanting.git] / silk_touch.lua
1 local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
2 local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
3 local pickaxes_better_than_stone = {"mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
4 local shovels = {"mcl_tools:shovel_wood", "mcl_tools:shovel_stone", "mcl_tools:shovel_gold", "mcl_tools:shovel_iron", "mcl_tools:shovel_diamond"}
5
6 local silk_touch_tool_lists = {
7         ["mcl_books:bookshelf"] = true,
8         ["mcl_core:clay"] = true,
9         ["mcl_core:stone_with_coal"] = pickaxes,
10         ["group:coral_block"] = pickaxes,
11         ["group:coral"] = true,
12         ["group:coral_fan"] = true,
13         ["mcl_core:stone_with_diamond"] = pickaxes_better_than_iron,
14         ["mcl_core:stone_with_emerald"] = pickaxes_better_than_iron,
15         ["mcl_chests:ender_chest"] = pickaxes,
16         ["group:glass"] = true,
17         ["mcl_nether:glowstone"] = true,
18         ["mcl_core:dirt_with_grass"] = true,
19         ["mcl_core:gravel"] = true,
20         ["mcl_core:ice"] = true,
21         ["mcl_core:stone_with_lapis"] = pickaxes_better_than_stone,
22         ["group:leaves"] = true,
23         ["mcl_farming:melon"] = true,
24         ["group:huge_mushroom"] = true,
25         ["mcl_core:mycelium"] = true,
26         ["mcl_nether:quartz_ore"] = pickaxes,
27         ["mcl_core:packed_ice"] = true,
28         ["mcl_core:podzol"] = true,
29         ["mcl_core:stone_with_redstone"] = pickaxes_better_than_iron,
30         ["mcl_ocean:sea_lantern"] = true,
31         ["group:top_snow"] = shovels,
32         ["mcl_core:snowblock"] = shovels,
33         ["mcl_core:stone"] = pickaxes,
34 }
35
36 minetest.register_on_mods_loaded(function()
37         local old_handle_node_drops = minetest.handle_node_drops
38         function minetest.handle_node_drops(pos, drops, digger)
39                 if digger and digger:is_player() then
40                         local wielditem = digger:get_wielded_item()
41                         local tooldef = wielditem:get_definition()
42                         if tooldef._silk_touch then
43                                 local nodename = minetest.get_node(pos).name
44                                 local nodedef = minetest.registered_nodes[nodename]
45                                 local silk_touch_spec = silk_touch_tool_lists[nodename]
46                                 local suitable_tool = false
47                                 local tool_list
48                                 if silk_touch_spec == true then
49                                         suitable_tool = true
50                                 elseif silk_touch_spec then
51                                         tool_list = silk_touch_spec
52                                 else
53                                         for k, v in pairs(nodedef.groups) do
54                                                 if v > 0 then
55                                                         local group_spec = silk_touch_tool_lists["group:" .. k]
56                                                         if group_spec == true then
57                                                                 suitable_tool = true
58                                                         elseif group_spec then
59                                                                 toollist = group_spec
60                                                                 break
61                                                         end
62                                                 end
63                                         end
64                                 end
65                                 if tool_list and not suitable_tool then
66                                         suitable_tool = (table.indexof(tool_list, tooldef._original_tool) ~= -1)
67                                 end
68                                 if suitable_tool then
69                                         drops = {nodename}
70                                 end
71                         end
72                 end
73                 old_handle_node_drops(pos, drops, digger)
74         end
75 end)