abms.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. minetest.register_abm({ -- Controls non-contained fire
  2. nodenames = {'campfire:embers','campfire:campfire'},
  3. interval = 1.0,
  4. chance = 1,
  5. action = function(pos, node, active_object_count, active_object_count_wider)
  6. -- crashes atm. swap out with code from latest furnace
  7. local meta = minetest.get_meta(pos)
  8. local fuel_time = meta:get_float("fuel_time") or 0
  9. -- local src_time = meta:get_float("src_time") or 0
  10. local fuel_totaltime = meta:get_float("fuel_totaltime") or 0
  11. local inv = meta:get_inventory()
  12. -- local srclist = inv:get_list("src")
  13. local cooked = nil
  14. -- if srclist then
  15. -- cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  16. -- end
  17. local was_active = false
  18. if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  19. was_active = true
  20. meta:set_float("fuel_time", meta:get_float("fuel_time") + 0.25)
  21. --meta:set_float("src_time", meta:get_float("src_time") + 0.25)
  22. -- if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
  23. -- if inv:room_for_item("dst",cooked.item) then
  24. -- inv:add_item("dst", cooked.item)
  25. -- local srcstack = inv:get_stack("src", 1)
  26. -- srcstack:take_item()
  27. -- inv:set_stack("src", 1, srcstack)
  28. -- else
  29. -- print("Could not insert '"..cooked.item:to_string().."'")
  30. -- end
  31. -- meta:set_string("src_time", 0)
  32. -- end
  33. end
  34. if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
  35. minetest.sound_play({name="campfire_small"},{pos=pos}, {max_hear_distance = 1},{loop=true},{gain=0.009})
  36. local percent = math.floor(meta:get_float("fuel_time") /
  37. meta:get_float("fuel_totaltime") * 100)
  38. meta:set_string("infotext","Campfire active: "..percent.."%")
  39. minetest.swap_node(pos, {name = 'campfire:campfire'})
  40. return
  41. end
  42. -- crashes atm
  43. -- local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  44. -- local cookable = true
  45. -- if cooked.time == 0 then
  46. -- cookable = false
  47. -- end
  48. -- local item_state = ''
  49. local item_percent = 0
  50. -- if cookable then
  51. -- item_percent = math.floor(src_time / cooked.time * 100)
  52. -- item_state = item_percent .. "%"
  53. -- end
  54. local fuel = nil
  55. local cooked = nil
  56. local fuellist = inv:get_list("fuel")
  57. -- local srclist = inv:get_list("src")
  58. -- if srclist then
  59. -- cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
  60. -- end
  61. local fname
  62. for i,f in ipairs(fuellist) do
  63. local time
  64. fuel = minetest.get_craft_result({method = "fuel", width = 1, items = {f}})
  65. if fuel.time > 0 then
  66. fname = f
  67. break
  68. end
  69. end
  70. -- if fuellist then
  71. -- fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
  72. -- end
  73. if fuel and fuel.time <= 0 then
  74. meta:set_string("infotext","The campfire is out.")
  75. minetest.swap_node(pos, {name = 'campfire:embers'})
  76. meta:set_string("formspec", campfire.fire_formspec(item_percent))
  77. return
  78. end
  79. meta:set_string("fuel_totaltime", fuel.time)
  80. meta:set_string("fuel_time", 0)
  81. inv:remove_item("fuel", fname)
  82. meta:set_string("formspec", campfire.fire_formspec(item_percent))
  83. end,
  84. })