abms.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. minetest.register_abm({
  2. label = 'Firevine Growth/Spread',
  3. nodenames = {'caverealms:fire_vine'},
  4. neighbors = {'group:stone'},
  5. interval = 53,
  6. chance = 25,
  7. action = function(pos)
  8. local node_below = ({x=pos.x, y=pos.y-1, z=pos.z})
  9. local below_name = minetest.get_node(node_below).name
  10. local spread_chance = math.random(0,3)
  11. if spread_chance < 2 then
  12. if below_name ~= 'caverealms:fire_vine' or 'air' then
  13. local ran_num = math.random(1,4)
  14. local location = {}
  15. if ran_num == 1 then
  16. location = {x=pos.x+1, y=pos.y, z=pos.z}
  17. elseif ran_num == 2 then
  18. location = {x=pos.x-1, y=pos.y, z=pos.z}
  19. elseif ran_num == 3 then
  20. location = {x=pos.x, y=pos.y, z=pos.z+1}
  21. elseif ran_num == 4 then
  22. location = {x=pos.x, y=pos.y, z=pos.z-1}
  23. end
  24. local below_location = ({x=location.x, y=location.y-1, z=location.z})
  25. local below_location_node = minetest.get_node(below_location).name
  26. if below_location_node ~= 'air' then
  27. local location_node = minetest.get_node(location)
  28. local location_name = location_node.name
  29. if location_name == 'air' or minetest.get_item_group(location_name, 'flammable') > 0 then
  30. minetest.set_node(location, {name = 'caverealms:fire_vine'})
  31. end
  32. end
  33. if below_name == 'air' then
  34. minetest.remove_node(pos)
  35. end
  36. end
  37. else
  38. local above_pos = {x=pos.x, y=pos.y+1, z=pos.z}
  39. local above_node = minetest.get_node(above_pos).name
  40. while above_node == 'caverealms:fire_vine' do
  41. above_pos.y = above_pos.y + 1
  42. above_node = minetest.get_node(above_pos).name
  43. end
  44. if minetest.get_item_group(above_node, 'flammable') > 0 or above_node == 'air' then
  45. minetest.set_node(above_pos, {name = 'caverealms:fire_vine'})
  46. end
  47. end
  48. end
  49. })