Allow to use watering can through placed seeds
[minetest_wateringcan.git] / init.lua
blob90745cc1c026725609beba8286ed136c1940dc30
1 if (minetest.get_modpath("intllib")) then
2 dofile(minetest.get_modpath("intllib").."/intllib.lua")
3 S = intllib.Getter(minetest.get_current_modname())
4 else
5 S = function ( s ) return s end
6 end
8 minetest.register_tool("wateringcan:wateringcan_water", {
9 description = S("watering can with water"),
10 inventory_image = "wateringcan_wateringcan_water.png",
11 wield_image = "wateringcan_wateringcan_wield.png",
12 liquids_pointable = true,
13 stack_max = 1,
14 tool_capabilities = {
15 full_punch_interval = 2.0,
17 on_place = function(itemstack, user, pointed_thing)
18 if(pointed_thing.type == "node") then
19 local pos = pointed_thing.under
20 local node = minetest.get_node_or_nil(pos)
21 if node ~= nil then
22 local name, nodedef
23 local watered = true
24 local wear, newtool
25 local underunder
26 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
27 pos = {x=pos.x, y=pos.y-1, z=pos.z}
28 underunder = minetest.get_node_or_nil(pos)
29 if(underunder ~= nil) then
30 name = underunder.name
31 nodedef = minetest.registered_nodes[name]
32 else
33 return itemstack
34 end
35 else
36 name = node.name
37 nodedef = minetest.registered_nodes[name]
38 end
39 if minetest.get_item_group(name, "water") > 0 then
40 newtool = { name = "wateringcan:wateringcan_water" }
41 watered = false
42 elseif name == "farming:soil" and minetest.get_modpath("farming") ~= nil then
43 minetest.set_node(pos, { name = "farming:soil_wet" })
44 elseif name == "farming:desert_sand_soil" and minetest.get_modpath("farming") ~= nil then
45 minetest.set_node(pos, { name = "farming:desert_sand_soil_wet" })
47 elseif minetest.get_item_group(name, "sucky") > 0 and minetest.get_item_group(name, "wet") < 2 and minetest.get_modpath("pedology") ~= nil then
48 pedology.wetten(pos)
49 end
51 if watered then
52 wear = itemstack:get_wear()
53 wear = wear + 2849 -- 24 uses
54 if(wear > 65535) then
55 newtool = { name = "wateringcan:wateringcan_empty" }
56 else
57 newtool = { name = "wateringcan:wateringcan_water", wear = wear }
58 end
59 end
60 return newtool
61 end
62 end
63 end
68 minetest.register_tool("wateringcan:wateringcan_empty", {
69 description = S("empty watering can"),
70 inventory_image = "wateringcan_wateringcan_empty.png",
71 wield_image = "wateringcan_wateringcan_wield.png",
72 liquids_pointable = true,
73 stack_max = 1,
74 tool_capabilities = {
75 full_punch_interval = 2.0,
77 on_place = function(itemstack, user, pointed_thing)
78 local node = minetest.get_node_or_nil(pointed_thing.under)
79 if node ~= nil then
80 local name = node.name
81 local nodedef = minetest.registered_nodes[name]
82 if minetest.get_item_group(name, "water") > 0 then
83 return { name = "wateringcan:wateringcan_water" }
84 end
85 end
86 end