Make mushrooms spread over time
parent
75289ce039
commit
fca5520d63
|
@ -114,4 +114,66 @@ minetest.register_craft({
|
|||
recipe = {'mcl_core:bowl', 'mcl_mushrooms:mushroom_brown', 'mcl_mushrooms:mushroom_red'}
|
||||
})
|
||||
|
||||
--[[ Mushroom spread and death
|
||||
Code based on information gathered from Minecraft Wiki
|
||||
<http://minecraft.gamepedia.com/Tutorials/Mushroom_farming#Videos>
|
||||
]]
|
||||
minetest.register_abm({
|
||||
label = "Mushroom spread",
|
||||
nodenames = {"mcl_mushrooms:mushroom_brown", "mcl_mushrooms:mushroom_red"},
|
||||
interval = 11,
|
||||
chance = 50,
|
||||
action = function(pos, node)
|
||||
if minetest.get_node_light(pos, nil) > 12 then
|
||||
minetest.remove_node(pos)
|
||||
return
|
||||
end
|
||||
|
||||
local pos0 = vector.add(pos, {x=-4, y=-1, z=-4})
|
||||
local pos1 = vector.add(pos, {x=4, y=1, z=4})
|
||||
|
||||
-- Stop mushroom spread if a 9×3×9 box is too crowded
|
||||
if #minetest.find_nodes_in_area(pos0, pos1, node.name) >= 5 then
|
||||
return
|
||||
end
|
||||
|
||||
local selected_pos = table.copy(pos)
|
||||
|
||||
-- Do two random selections which may place the new mushroom in a 5×5×5 cube
|
||||
local random = {
|
||||
x = selected_pos.x + math.random(-1, 1),
|
||||
y = selected_pos.y + math.random(0, 1) - math.random(0, 1),
|
||||
z = selected_pos.z + math.random(-1, 1)
|
||||
}
|
||||
local random_node = minetest.get_node_or_nil(random)
|
||||
if not random_node or random_node.name ~= "air" then
|
||||
return
|
||||
end
|
||||
local node_under = minetest.get_node_or_nil({x = random.x, y = random.y - 1, z = random.z})
|
||||
if not node_under then
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.get_node_light(random, 0.5) > 12 or (minetest.get_item_group(node_under.name, "opaque") == 0) then
|
||||
return
|
||||
end
|
||||
local random2 = {
|
||||
x = random.x + math.random(-1, 1),
|
||||
y = random.y,
|
||||
z = random.z + math.random(-1, 1)
|
||||
}
|
||||
random_node = minetest.get_node_or_nil(random2)
|
||||
if not random_node or random_node.name ~= "air" then
|
||||
return
|
||||
end
|
||||
node_under = minetest.get_node_or_nil({x = random2.x, y = random2.y - 1, z = random2.z})
|
||||
if not node_under then
|
||||
return
|
||||
end
|
||||
if minetest.get_node_light(random2, 0.5) > 12 or (minetest.get_item_group(node_under.name, "opaque") == 0) then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.set_node(random2, {name = node.name})
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue