2013-03-20 11:41:45 -07:00
|
|
|
local remove_full_grass = false --set "true" to remove all full_grass_blocks
|
|
|
|
|
|
|
|
minetest.register_node("landscape:full_grass_block", {
|
|
|
|
description = "Dirt with Grass",
|
|
|
|
tiles = {"default_grass.png"},
|
|
|
|
is_ground_content = true,
|
2013-05-12 12:01:11 -07:00
|
|
|
groups = {crumbly=3, not_in_creative=1},
|
2013-03-20 11:41:45 -07:00
|
|
|
drop = 'default:dirt',
|
|
|
|
sounds = default.node_sound_dirt_defaults({
|
|
|
|
footstep = {name="default_grass_footstep", gain=0.4},
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
|
|
|
|
local function get_type(pos) --1 for left, 2 for right, 3 for behind, 4 for front
|
2013-05-12 12:01:11 -07:00
|
|
|
local l1 = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}).name
|
|
|
|
local l2 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}).name
|
|
|
|
local r1 = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}).name
|
|
|
|
local r2 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}).name
|
2013-05-12 12:22:49 -07:00
|
|
|
if l1 == nil or l2 == nil or r1 == nil or r2 == nil then return end
|
2013-05-12 12:01:11 -07:00
|
|
|
if l1 == "air" or not minetest.registered_nodes[l1].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
return 1
|
2013-05-12 12:01:11 -07:00
|
|
|
elseif r1 == "air" or not minetest.registered_nodes[r1].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
return 2
|
2013-05-12 12:01:11 -07:00
|
|
|
elseif l2 == "air" or not minetest.registered_nodes[l2].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
return 3
|
2013-05-12 12:01:11 -07:00
|
|
|
elseif r2 == "air" or not minetest.registered_nodes[r2].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
return 4
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_edge(pos)
|
2013-05-12 03:51:00 -07:00
|
|
|
local l1 = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}).name
|
|
|
|
local l2 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}).name
|
|
|
|
local r1 = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}).name
|
|
|
|
local r2 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}).name
|
2013-05-12 12:22:49 -07:00
|
|
|
if l1 == nil or l2 == nil or r1 == nil or r2 == nil then return end
|
2013-05-12 03:51:00 -07:00
|
|
|
if l1 == "air" or not minetest.registered_nodes[l1] or
|
|
|
|
l2 == "air" or not minetest.registered_nodes[l2].walkable or
|
|
|
|
l3 == "air" or not minetest.registered_nodes[r1].walkable or
|
|
|
|
l4 == "air" or not minetest.registered_nodes[r2].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
return true
|
|
|
|
end
|
2013-05-11 10:29:56 -07:00
|
|
|
|
2013-03-20 11:41:45 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
local function check(pos)
|
|
|
|
if string.find(minetest.env:get_node(pos).name, "_grass") then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if remove_full_grass == false then
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"default:dirt_with_grass"},
|
|
|
|
--neighbors = {"default:dirt_with_grass", "landscape:full_grass_block"},
|
2013-04-25 22:42:17 -07:00
|
|
|
interval = 1,
|
2013-03-20 11:41:45 -07:00
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local under = {x=pos.x, y=pos.y-1, z=pos.z}
|
|
|
|
local above = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
|
|
local under_front = {x=pos.x+1, y=pos.y-1, z=pos.z}
|
|
|
|
local under_front2 = {x=pos.x, y=pos.y-1, z=pos.z+1}
|
|
|
|
local under_back = {x=pos.x-1, y=pos.y-1, z=pos.z}
|
|
|
|
local under_back2 = {x=pos.x, y=pos.y-1, z=pos.z-1}
|
2013-05-11 10:29:56 -07:00
|
|
|
local n = minetest.env:get_node(above).name
|
|
|
|
if n == nil then return end
|
2013-05-12 03:51:00 -07:00
|
|
|
if n == "air" or not minetest.registered_nodes[n].walkable then
|
2013-03-20 11:41:45 -07:00
|
|
|
if get_type(pos) ~= 0 then
|
|
|
|
local typ = get_type(pos)
|
|
|
|
local ok = false
|
|
|
|
if typ == 1 then
|
|
|
|
ok = check(under_front)
|
|
|
|
elseif typ == 2 then
|
|
|
|
ok = check(under_back)
|
|
|
|
elseif typ == 3 then
|
|
|
|
ok = check(under_front2)
|
|
|
|
elseif typ == 4 then
|
|
|
|
ok = check(under_back2)
|
|
|
|
end
|
|
|
|
if ok then
|
|
|
|
if minetest.env:get_node(under).name == "default:dirt" then
|
|
|
|
if not is_edge(under) then
|
|
|
|
--IF GRAS UNTEN-DAVOR tthen....
|
2013-05-12 12:01:11 -07:00
|
|
|
minetest.env:set_node(pos, {name="landscape:full_grass_block"})
|
2013-03-20 11:41:45 -07:00
|
|
|
end
|
|
|
|
else
|
2013-05-12 12:01:11 -07:00
|
|
|
minetest.env:set_node(pos, {name="landscape:full_grass_block"})
|
2013-03-20 11:41:45 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-11 10:29:56 -07:00
|
|
|
|
2013-03-20 11:41:45 -07:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
--remove full grass when block is placed above
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"landscape:full_grass_block"},
|
|
|
|
interval = 2.0,
|
|
|
|
chance = 20,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2013-05-11 10:29:56 -07:00
|
|
|
local n = minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
|
|
|
if n == nil then return end
|
2013-05-12 12:01:11 -07:00
|
|
|
if n ~= "air" or minetest.registered_nodes[n].walkable then
|
|
|
|
minetest.env:set_node(pos, {name="default:dirt"})
|
2013-03-20 11:41:45 -07:00
|
|
|
end
|
2013-04-25 22:42:17 -07:00
|
|
|
end
|
2013-03-20 11:41:45 -07:00
|
|
|
})
|
|
|
|
else
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"landscape:full_grass_block"},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local tmp_node3 = {name="default:dirt_with_grass"}
|
|
|
|
minetest.env:set_node(pos, tmp_node3)
|
|
|
|
end
|
|
|
|
})
|
2013-04-25 22:42:17 -07:00
|
|
|
end
|