2017-01-31 11:35:59 +00:00
minetest.register_node ( " mcl_farming:soil " , {
2015-06-29 17:55:56 +00:00
tiles = { " farming_soil.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " } ,
2017-01-08 02:05:41 +00:00
description = " Farmland " ,
2017-05-14 20:55:46 +00:00
_doc_items_longdesc = " Farmland is used for farming, a necessary surface to plant crops. It is created when a hoe is used on dirt or a similar block. Plants are able to grow on farmland, but slowly. Farmland will become hydrated farmland (on which plants grow faster) when it rains or a water source is nearby. This block will turn back to dirt when a solid block appears above it or a piston arm extends above it. " ,
2017-01-31 22:32:56 +00:00
drop = " mcl_core:dirt " ,
2015-06-29 17:55:56 +00:00
drawtype = " nodebox " ,
paramtype = " light " ,
node_box = {
type = " fixed " ,
fixed = {
2017-01-08 02:12:36 +00:00
-- 15/16 of the normal height
{ - 0.5 , - 0.5 , - 0.5 , 0.5 , 0.4375 , 0.5 } ,
2015-06-29 17:55:56 +00:00
}
} ,
2017-05-14 19:08:02 +00:00
on_construct = function ( pos )
local meta = minetest.get_meta ( pos )
meta : set_int ( " wet " , 0 )
end ,
2017-05-14 20:44:34 +00:00
groups = { handy = 1 , shovely = 1 , not_in_creative_inventory = 1 , dirtifies_below_solid = 1 , soil = 2 , soil_sapling = 1 } ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
2017-02-22 15:03:59 +00:00
_mcl_blast_resistance = 3 ,
2017-03-20 18:53:14 +00:00
_mcl_hardness = 0.6 ,
2015-06-29 17:55:56 +00:00
} )
2017-01-31 11:35:59 +00:00
minetest.register_node ( " mcl_farming:soil_wet " , {
2015-06-29 17:55:56 +00:00
tiles = { " farming_soil_wet.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " , " default_dirt.png " } ,
2017-01-08 02:05:41 +00:00
description = " Hydrated Farmland " ,
2017-05-14 20:55:46 +00:00
_doc_items_longdesc = " Hydrated farmland is used in farming, this is where you can plant and grow some plants. It is created when farmlands is under rain or near water. Without water, this block will dry out eventually. This block will turn back to dirt when a solid block appears above it or a piston arm extends above it. " ,
2017-01-31 22:32:56 +00:00
drop = " mcl_core:dirt " ,
2015-06-29 17:55:56 +00:00
drawtype = " nodebox " ,
paramtype = " light " ,
node_box = {
type = " fixed " ,
fixed = {
2017-01-08 02:12:36 +00:00
{ - 0.5 , - 0.5 , - 0.5 , 0.5 , 0.4375 , 0.5 } ,
2015-06-29 17:55:56 +00:00
}
} ,
2017-05-14 19:08:02 +00:00
on_construct = function ( pos )
local meta = minetest.get_meta ( pos )
meta : set_int ( " wet " , 7 )
end ,
2017-05-14 20:44:34 +00:00
groups = { handy = 1 , shovely = 1 , not_in_creative_inventory = 1 , dirtifies_below_solid = 1 , soil = 3 , soil_sapling = 1 } ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_dirt_defaults ( ) ,
2017-02-22 15:03:59 +00:00
_mcl_blast_resistance = 3 ,
2017-03-20 18:53:14 +00:00
_mcl_hardness = 0.6 ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_abm ( {
2017-05-14 19:08:02 +00:00
label = " Farmland hydration " ,
nodenames = { " mcl_farming:soil " , " mcl_farming:soil_wet " } ,
2015-06-29 17:55:56 +00:00
interval = 15 ,
2017-05-14 19:08:02 +00:00
chance = 4 ,
2015-06-29 17:55:56 +00:00
action = function ( pos , node )
2017-05-14 19:08:02 +00:00
-- Get wetness value
local meta = minetest.get_meta ( pos )
local wet = meta : get_int ( " wet " )
if not wet then
if node.name == " mcl_farming:soil " then
wet = 0
else
wet = 7
end
end
2017-05-14 19:47:45 +00:00
-- Turn back into dirt when covered by solid node
local above_node = minetest.get_node_or_nil ( { x = pos.x , y = pos.y + 1 , z = pos.z } )
if above_node then
2017-05-14 19:53:34 +00:00
if minetest.get_item_group ( above_node.name , " solid " ) ~= 0 then
2017-05-14 19:47:45 +00:00
node.name = " mcl_core:dirt "
minetest.set_node ( pos , node )
return
end
end
2017-05-14 19:08:02 +00:00
-- Check an area of 9× 2× 9 around the node for nodename
local check_surroundings = function ( pos , nodename )
local nodes = minetest.find_nodes_in_area ( { x = pos.x - 4 , y = pos.y - 1 , z = pos.z - 4 } , { x = pos.x + 4 , y = pos.y , z = pos.z + 4 } , { nodename } )
return # nodes > 0
end
if check_surroundings ( pos , " group:water " ) then
if node.name ~= " mcl_farming:soil_wet " then
-- Make it wet
node.name = " mcl_farming:soil_wet "
minetest.set_node ( pos , node )
end
2017-05-14 20:16:56 +00:00
else -- No water nearby.
-- The decay branch (make farmland dry or turn back to dirt)
-- Don't decay while it's raining
if rain.raining then
if weather.is_outdoor ( pos ) then
return
end
end
-- No decay near unloaded areas since these might include water.
2017-05-14 19:08:02 +00:00
if not check_surroundings ( pos , " ignore " ) then
if wet <= 0 then
local n_def = minetest.registered_nodes [ node.name ] or nil
local nn = minetest.get_node_or_nil ( { x = pos.x , y = pos.y + 1 , z = pos.z } )
if not nn or not nn.name then
return
end
local nn_def = minetest.registered_nodes [ nn.name ] or nil
if nn_def and minetest.get_item_group ( nn.name , " plant " ) == 0 then
node.name = " mcl_core:dirt "
minetest.set_node ( pos , node )
return
end
else
if wet == 7 then
node.name = " mcl_farming:soil "
minetest.swap_node ( pos , node )
end
-- Slowly count down wetness
meta : set_int ( " wet " , wet - 1 )
end
end
2015-06-29 17:55:56 +00:00
end
end ,
} )
2017-05-14 20:44:34 +00:00