init.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. local modpath = minetest.get_modpath("treefelling")
  2. function fell_tree(pos, oldnode, player)
  3. local height = 0
  4. --pos.y = pos.y + 1
  5. local name = minetest.get_node(pos).name
  6. minetest.set_node(pos, {name="air"})
  7. local trunk_name = name
  8. minetest.node_dig(pos, oldnode, player)
  9. repeat
  10. local itemstacks = minetest.get_node_drops(name)
  11. for _, itemname in ipairs(itemstacks) do
  12. minetest.add_item(pos, itemname)
  13. end
  14. minetest.set_node(pos, {name="air"})
  15. print(name .. " = " .. trunk_name)
  16. print(height)
  17. height = height + 1
  18. pos.y = pos.y + 1
  19. name = minetest.get_node(pos).name
  20. until name ~= trunk_name or height >= 14
  21. end
  22. minetest.override_item("default:tree", { on_dig = fell_tree })
  23. minetest.override_item("default:jungletree", { on_dig = fell_tree })
  24. minetest.override_item("default:pine_tree", { on_dig = fell_tree })
  25. minetest.override_item("default:acacia_tree", { on_dig = fell_tree })
  26. minetest.override_item("default:aspen_tree", { on_dig = fell_tree })
  27. -- bug: handle roots
  28. if minetest.get_modpath("treegrowth") then
  29. minetest.override_item("treegrowth:tree_thin_1", { on_dig = fell_tree })
  30. minetest.override_item("treegrowth:tree_thin_2", { on_dig = fell_tree })
  31. minetest.override_item("treegrowth:tree_thin_3", { on_dig = fell_tree })
  32. minetest.override_item("treegrowth:tree_thin_4", { on_dig = fell_tree })
  33. end