Skip to content

Commit

Permalink
Don't crash when saplings try to grow on unknown nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexYst authored and est31 committed Jun 15, 2015
1 parent 38482d2 commit 3b4408a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion games/minimal/mods/default/init.lua
Expand Up @@ -1660,7 +1660,12 @@ minetest.register_abm({
interval = 10,
chance = 50,
action = function(pos, node)
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
local node_under = minetest.registered_nodes[
minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name]
if not node_under then
return
end
local is_soil = node_under.groups.soil
if is_soil == nil or is_soil == 0 then return end
print("A sapling grows into a tree at "..minetest.pos_to_string(pos))
local vm = minetest.get_voxel_manip()
Expand Down

2 comments on commit 3b4408a

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replaced with simply:

if minetest.get_item_group(minetest.get_node(
        {x = pos.x, y = pos.y - 1, z = pos.z}).name, "soil") == 0 then
    return
end

@est31
Copy link
Contributor

@est31 est31 commented on 3b4408a Jun 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do it, if you want.

Please sign in to comment.