2019-03-07 19:00:54 +01:00
local S = minetest.get_translator ( " wateringcan " )
2014-06-14 06:35:25 +02:00
2014-06-13 16:35:40 +02:00
minetest.register_tool ( " wateringcan:wateringcan_water " , {
2016-08-07 18:12:40 +02:00
description = S ( " Watering can with water " ) ,
2016-11-16 06:37:40 +01:00
_doc_items_create_entry = false ,
2014-06-13 16:35:40 +02:00
inventory_image = " wateringcan_wateringcan_water.png " ,
wield_image = " wateringcan_wateringcan_wield.png " ,
2014-06-13 16:59:54 +02:00
liquids_pointable = true ,
stack_max = 1 ,
2018-10-16 04:51:33 +02:00
groups = { disable_repair = 1 } ,
2014-06-13 16:59:54 +02:00
tool_capabilities = {
full_punch_interval = 2.0 ,
} ,
2014-06-13 16:35:40 +02:00
on_place = function ( itemstack , user , pointed_thing )
if ( pointed_thing.type == " node " ) then
2014-06-13 21:08:14 +02:00
local pos = pointed_thing.under
local node = minetest.get_node_or_nil ( pos )
2014-06-13 16:35:40 +02:00
if node ~= nil then
2014-06-13 21:08:14 +02:00
local name , nodedef
2014-06-13 17:57:37 +02:00
local watered = true
2014-06-13 16:59:54 +02:00
local wear , newtool
2014-06-13 21:08:14 +02:00
local underunder
2016-07-25 20:08:08 +02:00
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
2014-06-13 21:08:14 +02:00
pos = { x = pos.x , y = pos.y - 1 , z = pos.z }
underunder = minetest.get_node_or_nil ( pos )
if ( underunder ~= nil ) then
name = underunder.name
nodedef = minetest.registered_nodes [ name ]
else
return itemstack
end
else
name = node.name
nodedef = minetest.registered_nodes [ name ]
end
2014-06-13 17:21:28 +02:00
if minetest.get_item_group ( name , " water " ) > 0 then
newtool = { name = " wateringcan:wateringcan_water " }
watered = false
2020-04-06 00:41:29 +02:00
minetest.sound_play ( { name = " wateringcan_fill " , gain = 0.25 , max_hear_distance = 10 } , { pos = user : get_pos ( ) } , true )
2014-06-13 17:21:28 +02:00
elseif name == " farming:soil " and minetest.get_modpath ( " farming " ) ~= nil then
2014-06-13 21:08:14 +02:00
minetest.set_node ( pos , { name = " farming:soil_wet " } )
2016-07-25 19:58:23 +02:00
elseif name == " farming:desert_sand_soil " and minetest.get_modpath ( " farming " ) ~= nil then
minetest.set_node ( pos , { name = " farming:desert_sand_soil_wet " } )
2014-06-13 21:08:14 +02:00
2014-06-13 18:02:19 +02:00
elseif minetest.get_item_group ( name , " sucky " ) > 0 and minetest.get_item_group ( name , " wet " ) < 2 and minetest.get_modpath ( " pedology " ) ~= nil then
2014-06-13 21:08:14 +02:00
pedology.wetten ( pos )
2014-06-13 16:35:40 +02:00
end
2014-06-13 17:21:28 +02:00
2014-06-13 16:59:54 +02:00
if watered then
2020-04-06 00:41:29 +02:00
minetest.sound_play ( { name = " wateringcan_pour " , gain = 0.25 , max_hear_distance = 10 } , { pos = user : get_pos ( ) } , true )
2014-06-13 16:59:54 +02:00
wear = itemstack : get_wear ( )
wear = wear + 2849 -- 24 uses
if ( wear > 65535 ) then
newtool = { name = " wateringcan:wateringcan_empty " }
else
newtool = { name = " wateringcan:wateringcan_water " , wear = wear }
end
end
return newtool
2014-06-13 16:35:40 +02:00
end
end
2016-08-07 18:02:56 +02:00
end ,
2014-06-13 16:35:40 +02:00
}
)
2016-11-18 14:46:18 +01:00
local usagehelp , longdesc , entry_name
local entry_name
if minetest.get_modpath ( " doc_items " ) then
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 " ) )
entry_name = S ( " Watering can " )
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. " )
end
2014-06-13 16:59:54 +02:00
minetest.register_tool ( " wateringcan:wateringcan_empty " , {
2016-08-07 18:12:40 +02:00
description = S ( " Empty watering can " ) ,
2016-11-18 23:41:29 +01:00
_doc_items_entry_name = entry_name ,
2016-11-18 14:46:18 +01:00
_doc_items_longdesc = longdesc ,
_doc_items_usagehelp = usagehelp ,
2014-06-13 16:35:40 +02:00
inventory_image = " wateringcan_wateringcan_empty.png " ,
wield_image = " wateringcan_wateringcan_wield.png " ,
2014-06-13 16:59:54 +02:00
liquids_pointable = true ,
stack_max = 1 ,
2018-10-16 04:51:33 +02:00
groups = { disable_repair = 1 } ,
2014-06-13 16:59:54 +02:00
tool_capabilities = {
full_punch_interval = 2.0 ,
} ,
2014-06-13 17:21:28 +02:00
on_place = function ( itemstack , user , pointed_thing )
local node = minetest.get_node_or_nil ( pointed_thing.under )
if node ~= nil then
local name = node.name
local nodedef = minetest.registered_nodes [ name ]
if minetest.get_item_group ( name , " water " ) > 0 then
2020-04-06 00:41:29 +02:00
minetest.sound_play ( { name = " wateringcan_fill " , gain = 0.25 , max_hear_distance = 10 } , { pos = user : get_pos ( ) } , true )
2014-06-13 17:21:28 +02:00
return { name = " wateringcan:wateringcan_water " }
end
end
end
2014-06-13 16:59:54 +02:00
} )
2016-08-07 18:02:56 +02:00
2016-10-29 16:12:43 +02:00
if minetest.get_modpath ( " bucket " ) ~= nil then
if minetest.get_modpath ( " default " ) ~= nil then
minetest.register_craft ( {
output = " wateringcan:wateringcan_empty " ,
recipe = {
{ " " , " " , " default:steel_ingot " } ,
{ " group:stick " , " default:steel_ingot " , " " } ,
{ " default:steel_ingot " , " bucket:bucket_empty " , " " } ,
}
} )
minetest.register_craft ( {
output = " wateringcan:wateringcan_water " ,
recipe = {
{ " " , " " , " default:steel_ingot " } ,
{ " group:stick " , " default:steel_ingot " , " " } ,
{ " default:steel_ingot " , " group:water_bucket " , " " } ,
}
} )
end
minetest.register_craft ( {
output = " wateringcan:wateringcan_water " ,
type = " shapeless " ,
recipe = { " wateringcan:wateringcan_empty " , " group:water_bucket " } ,
replacements = { { " group:water_bucket " , " bucket:bucket_empty " } }
} )
end
2016-11-17 18:44:07 +01:00
if minetest.get_modpath ( " doc " ) ~= nil and minetest.get_modpath ( " doc_items " ) ~= nil then
2016-12-28 17:35:56 +01:00
doc.add_entry_alias ( " tools " , " wateringcan:wateringcan_empty " , " tools " , " wateringcan:wateringcan_water " )
2016-08-07 18:02:56 +02:00
end