When applying on plant, wetten node below it
[minetest_wateringcan.git] / init.lua
blobcf4aa342c5415d3a4bdc68d88c7822a710fb0dce
1 minetest.register_tool("wateringcan:wateringcan_water", {
2 description = "watering can with water",
3 inventory_image = "wateringcan_wateringcan_water.png",
4 wield_image = "wateringcan_wateringcan_wield.png",
5 liquids_pointable = true,
6 stack_max = 1,
7 tool_capabilities = {
8 full_punch_interval = 2.0,
9 },
10 on_place = function(itemstack, user, pointed_thing)
11 if(pointed_thing.type == "node") then
12 local pos = pointed_thing.under
13 local node = minetest.get_node_or_nil(pos)
14 if node ~= nil then
15 local name, nodedef
16 local watered = true
17 local wear, newtool
18 local underunder
19 if minetest.get_item_group(node.name, "plant") > 0 or minetest.get_item_group(node.name, "flora") > 0 then
20 pos = {x=pos.x, y=pos.y-1, z=pos.z}
21 underunder = minetest.get_node_or_nil(pos)
22 if(underunder ~= nil) then
23 name = underunder.name
24 nodedef = minetest.registered_nodes[name]
25 else
26 return itemstack
27 end
28 else
29 name = node.name
30 nodedef = minetest.registered_nodes[name]
31 end
32 if minetest.get_item_group(name, "water") > 0 then
33 newtool = { name = "wateringcan:wateringcan_water" }
34 watered = false
35 elseif name == "farming:soil" and minetest.get_modpath("farming") ~= nil then
36 minetest.set_node(pos, { name = "farming:soil_wet" })
38 elseif minetest.get_item_group(name, "sucky") > 0 and minetest.get_item_group(name, "wet") < 2 and minetest.get_modpath("pedology") ~= nil then
39 pedology.wetten(pos)
40 end
42 if watered then
43 wear = itemstack:get_wear()
44 wear = wear + 2849 -- 24 uses
45 if(wear > 65535) then
46 newtool = { name = "wateringcan:wateringcan_empty" }
47 else
48 newtool = { name = "wateringcan:wateringcan_water", wear = wear }
49 end
50 end
51 return newtool
52 end
53 end
54 end
59 minetest.register_tool("wateringcan:wateringcan_empty", {
60 description = "empty watering can",
61 inventory_image = "wateringcan_wateringcan_empty.png",
62 wield_image = "wateringcan_wateringcan_wield.png",
63 liquids_pointable = true,
64 stack_max = 1,
65 tool_capabilities = {
66 full_punch_interval = 2.0,
68 on_place = function(itemstack, user, pointed_thing)
69 local node = minetest.get_node_or_nil(pointed_thing.under)
70 if node ~= nil then
71 local name = node.name
72 local nodedef = minetest.registered_nodes[name]
73 if minetest.get_item_group(name, "water") > 0 then
74 return { name = "wateringcan:wateringcan_water" }
75 end
76 end
77 end