Use get_group_name from doc_items
[minetest_wateringcan.git] / init.lua
blob1f314474c706e4e9c67d9d45d69a51f3d9205c3f
1 local S
2 if (minetest.get_modpath("intllib")) then
3 S = intllib.Getter()
4 else
5 S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
6 end
8 minetest.register_tool("wateringcan:wateringcan_water", {
9 description = S("Watering can with water"),
10 _doc_items_create_entry = false,
11 inventory_image = "wateringcan_wateringcan_water.png",
12 wield_image = "wateringcan_wateringcan_wield.png",
13 liquids_pointable = true,
14 stack_max = 1,
15 tool_capabilities = {
16 full_punch_interval = 2.0,
18 on_place = function(itemstack, user, pointed_thing)
19 if(pointed_thing.type == "node") then
20 local pos = pointed_thing.under
21 local node = minetest.get_node_or_nil(pos)
22 if node ~= nil then
23 local name, nodedef
24 local watered = true
25 local wear, newtool
26 local underunder
27 if minetest.get_item_group(node.name, "plant") > 0 or minetest.get_item_group(node.name, "flora") > 0 or minetest.get_item_group(node.name, "seed") > 0 then
28 pos = {x=pos.x, y=pos.y-1, z=pos.z}
29 underunder = minetest.get_node_or_nil(pos)
30 if(underunder ~= nil) then
31 name = underunder.name
32 nodedef = minetest.registered_nodes[name]
33 else
34 return itemstack
35 end
36 else
37 name = node.name
38 nodedef = minetest.registered_nodes[name]
39 end
40 if minetest.get_item_group(name, "water") > 0 then
41 newtool = { name = "wateringcan:wateringcan_water" }
42 watered = false
43 elseif name == "farming:soil" and minetest.get_modpath("farming") ~= nil then
44 minetest.set_node(pos, { name = "farming:soil_wet" })
45 elseif name == "farming:desert_sand_soil" and minetest.get_modpath("farming") ~= nil then
46 minetest.set_node(pos, { name = "farming:desert_sand_soil_wet" })
48 elseif minetest.get_item_group(name, "sucky") > 0 and minetest.get_item_group(name, "wet") < 2 and minetest.get_modpath("pedology") ~= nil then
49 pedology.wetten(pos)
50 end
52 if watered then
53 minetest.sound_play({name = "wateringcan_pour", gain = 0.25, max_hear_distance = 10}, { pos = user:getpos() })
54 wear = itemstack:get_wear()
55 wear = wear + 2849 -- 24 uses
56 if(wear > 65535) then
57 newtool = { name = "wateringcan:wateringcan_empty" }
58 else
59 newtool = { name = "wateringcan:wateringcan_water", wear = wear }
60 end
61 end
62 return newtool
63 end
64 end
65 end,
69 minetest.register_tool("wateringcan:wateringcan_empty", {
70 description = S("Empty watering can"),
71 _doc_items_entry_name = S("Watering can"),
72 _doc_items_longdesc = S("Watering cans are used to collect a small amount of water in order to pour it on dry blocks. One filled watering can can be used 24 times, after which it has to be refilled. Watering cans don't wear out."),
73 _doc_items_usagehelp = S("Rightclick on water (or any other block belonging to the “@1” group) to fill or refill the watering can. Rightclick with the filled can on an appropriate block (or a plant above it) to wetten it. Soil, desert sand soil, and other blocks capable of becoming wet can be wettened. The tool wear indicator of the watering can indicates the amount of water left.", doc.sub.items.get_group_name("water")),
74 inventory_image = "wateringcan_wateringcan_empty.png",
75 wield_image = "wateringcan_wateringcan_wield.png",
76 liquids_pointable = true,
77 stack_max = 1,
78 tool_capabilities = {
79 full_punch_interval = 2.0,
81 on_place = function(itemstack, user, pointed_thing)
82 local node = minetest.get_node_or_nil(pointed_thing.under)
83 if node ~= nil then
84 local name = node.name
85 local nodedef = minetest.registered_nodes[name]
86 if minetest.get_item_group(name, "water") > 0 then
87 return { name = "wateringcan:wateringcan_water" }
88 end
89 end
90 end
93 if minetest.get_modpath("bucket") ~= nil then
94 if minetest.get_modpath("default") ~= nil then
95 minetest.register_craft({
96 output = "wateringcan:wateringcan_empty",
97 recipe = {
98 {"", "", "default:steel_ingot"},
99 {"group:stick", "default:steel_ingot", ""},
100 {"default:steel_ingot", "bucket:bucket_empty", ""},
103 minetest.register_craft({
104 output = "wateringcan:wateringcan_water",
105 recipe = {
106 {"", "", "default:steel_ingot"},
107 {"group:stick", "default:steel_ingot", ""},
108 {"default:steel_ingot", "group:water_bucket", ""},
112 minetest.register_craft({
113 output = "wateringcan:wateringcan_water",
114 type = "shapeless",
115 recipe = {"wateringcan:wateringcan_empty", "group:water_bucket"},
116 replacements = {{"group:water_bucket", "bucket:bucket_empty"}}
120 if minetest.get_modpath("doc") ~= nil and minetest.get_modpath("doc_items") ~= nil then
121 doc.add_entry_alias("tools", "wateringcan:wateringcan_empty", "wateringcan:wateringcan_water")