farming/soil.lua

67 lines
2.0 KiB
Lua
Raw Normal View History

2016-05-30 04:30:00 -07:00
local S = farming.intllib
2015-05-11 11:19:16 -07:00
-- normal soil
2014-11-09 11:06:28 -08:00
minetest.register_node("farming:soil", {
2016-05-30 04:30:00 -07:00
description = S("Soil"),
2015-08-26 07:05:17 -07:00
tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
2014-11-09 11:06:28 -08:00
drop = "default:dirt",
2015-07-05 02:54:18 -07:00
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2},
2014-11-09 11:06:28 -08:00
sounds = default.node_sound_dirt_defaults(),
})
2015-05-11 11:19:16 -07:00
-- wet soil
2014-11-09 11:06:28 -08:00
minetest.register_node("farming:soil_wet", {
2016-05-30 04:30:00 -07:00
description = S("Wet Soil"),
2015-08-26 07:05:17 -07:00
tiles = {"default_dirt.png^farming_soil_wet.png", "default_dirt.png^farming_soil_wet_side.png"},
2014-11-09 11:06:28 -08:00
drop = "default:dirt",
2015-07-05 02:54:18 -07:00
groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3},
2014-11-09 11:06:28 -08:00
sounds = default.node_sound_dirt_defaults(),
})
2015-08-26 07:05:17 -07:00
-- sand is not soil, change existing sand-soil to use normal soil
minetest.register_alias("farming:desert_sand_soil", "farming:soil")
2014-11-09 11:06:28 -08:00
minetest.register_alias("farming:desert_sand_soil_wet", "farming:soil_wet")
2015-05-11 11:19:16 -07:00
-- if water near soil then change to wet soil
2014-11-09 11:06:28 -08:00
minetest.register_abm({
nodenames = {"farming:soil", "farming:soil_wet"},
2015-05-11 11:20:58 -07:00
interval = 15,
2014-11-09 11:06:28 -08:00
chance = 4,
2015-11-07 13:06:54 -08:00
catch_up = false,
2014-11-09 11:06:28 -08:00
action = function(pos, node)
2015-07-05 02:54:18 -07:00
pos.y = pos.y + 1
local nn = minetest.get_node_or_nil(pos)
pos.y = pos.y - 1
if nn then nn = nn.name else return end
2014-11-09 11:06:28 -08:00
-- what's on top of soil, if solid/not plant change soil to dirt
if minetest.registered_nodes[nn]
and minetest.registered_nodes[nn].walkable
and minetest.get_item_group(nn, "plant") == 0 then
2015-07-05 02:54:18 -07:00
minetest.set_node(pos, {name = "default:dirt"})
2015-05-11 11:19:16 -07:00
return
2014-11-09 11:06:28 -08:00
end
2014-12-10 02:51:27 -08:00
-- if map around soil not loaded then skip until loaded
if minetest.find_node_near(pos, 3, {"ignore"}) then
return
end
2014-11-09 11:06:28 -08:00
-- check if there is water nearby and change soil accordingly
if minetest.find_node_near(pos, 3, {"group:water"}) then
if node.name == "farming:soil" then
2015-07-05 02:54:18 -07:00
minetest.set_node(pos, {name = "farming:soil_wet"})
2014-11-09 11:06:28 -08:00
end
2014-11-09 11:06:28 -08:00
elseif node.name == "farming:soil_wet" then
2015-07-05 02:54:18 -07:00
minetest.set_node(pos, {name = "farming:soil"})
2014-11-09 11:06:28 -08:00
elseif node.name == "farming:soil" then
2015-07-05 02:54:18 -07:00
minetest.set_node(pos, {name = "default:dirt"})
2014-11-09 11:06:28 -08:00
end
end,
2015-07-05 02:54:18 -07:00
})