abms.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. minetest.register_abm({
  2. label = 'Firevine Growth/Spread',
  3. nodenames = {'caverealms:fire_vine'},
  4. neighbors = {'group:stone'},
  5. interval = 104,
  6. chance = 40,
  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. local node_count = 0
  41. while above_node == 'caverealms:fire_vine' and node_count < 15 do
  42. above_pos.y = above_pos.y + 1
  43. above_node = minetest.get_node(above_pos).name
  44. local node_count = node_count + 1
  45. end
  46. if minetest.get_item_group(above_node, 'flammable') > 0 or above_node == 'air' then
  47. minetest.set_node(above_pos, {name = 'caverealms:fire_vine'})
  48. end
  49. end
  50. end
  51. })