Add 24 uses of watering can before water is empty
[minetest_wateringcan.git] / init.lua
blobcd9bfec93c9bb1b240feb3cf6d0c6617488acf9e
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 node = minetest.get_node_or_nil(pointed_thing.under)
13 if node ~= nil then
14 local name = node.name
15 local nodedef = minetest.registered_nodes[name]
16 local watered = false
17 local wear, newtool
18 if name == "farming:soil" and minetest.get_modpath("farming") ~= nil then
19 minetest.set_node(pointed_thing.under, { name = "farming:soil_wet" })
20 watered = true
21 elseif minetest.get_item_group(name, "sucky") > 0 and minetest.get_modpath("pedology") ~= nil then
22 pedology.wetten(pointed_thing.under)
23 watered = true
24 end
25 if watered then
26 wear = itemstack:get_wear()
27 wear = wear + 2849 -- 24 uses
28 if(wear > 65535) then
29 newtool = { name = "wateringcan:wateringcan_empty" }
30 else
31 newtool = { name = "wateringcan:wateringcan_water", wear = wear }
32 end
33 end
34 return newtool
35 end
36 end
37 end
42 minetest.register_tool("wateringcan:wateringcan_empty", {
43 description = "empty watering can",
44 inventory_image = "wateringcan_wateringcan_empty.png",
45 wield_image = "wateringcan_wateringcan_wield.png",
46 liquids_pointable = true,
47 stack_max = 1,
48 tool_capabilities = {
49 full_punch_interval = 2.0,