heater.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. local function swap_node(pos, name)
  2. local node = minetest.get_node(pos)
  3. if node.name == name then
  4. return
  5. end
  6. node.name = name
  7. minetest.swap_node(pos, node)
  8. end
  9. minetest.register_craftitem("bitumen:heat", {
  10. description = "Heat",
  11. stack_max = 100,
  12. inventory_image = "bitumen_heat.png",
  13. groups = {flammable = 3},
  14. })
  15. minetest.register_craft({
  16. type = "fuel",
  17. recipe = "bitumen:heat",
  18. burntime = 10,
  19. })
  20. minetest.register_node("bitumen:heater", {
  21. description = "Heater",
  22. tiles = {
  23. "default_bronze_block.png", "default_bronze_block.png",
  24. "default_bronze_block.png", "default_bronze_block.png",
  25. "default_bronze_block.png", "default_furnace_front.png",
  26. },
  27. paramtype2 = "facedir",
  28. groups = {cracky=2, petroleum_fixture=1},
  29. is_ground_content = false,
  30. sounds = default.node_sound_stone_defaults(),
  31. on_punch = function(pos)
  32. swap_node(pos, "bitumen:heater_on")
  33. end,
  34. })
  35. minetest.register_node("bitumen:heater_on", {
  36. description = "Heater (Active)",
  37. tiles = {
  38. "default_tin_block.png", "default_bronze_block.png",
  39. "default_bronze_block.png", "default_tin_block.png",
  40. "default_tin_block.png",
  41. {
  42. image = "default_furnace_front_active.png",
  43. backface_culling = false,
  44. animation = {
  45. type = "vertical_frames",
  46. aspect_w = 16,
  47. aspect_h = 16,
  48. length = 1.5
  49. },
  50. }
  51. },
  52. paramtype2 = "facedir",
  53. groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
  54. is_ground_content = false,
  55. sounds = default.node_sound_stone_defaults(),
  56. on_punch = function(pos)
  57. swap_node(pos, "bitumen:heater")
  58. end,
  59. })
  60. minetest.register_abm({
  61. nodenames = {"bitumen:heater_on"},
  62. interval = 1,
  63. chance = 1,
  64. action = function(pos)
  65. local apos = {x=pos.x, y=pos.y + 1, z=pos.z}
  66. local anode = minetest.get_node(apos)
  67. if anode.name == "air" then
  68. -- print("air above")
  69. return
  70. end
  71. local ameta = minetest.get_meta(apos)
  72. local ainv = ameta:get_inventory()
  73. if ainv:get_size("fuel") <= 0 then
  74. -- print("no fuel inv")
  75. return
  76. end
  77. if ainv:contains_item("fuel", "bitumen:heat 2") then
  78. -- print("fuel full")
  79. return -- still full
  80. end
  81. local node = minetest.get_node(pos)
  82. local back_dir = minetest.facedir_to_dir(node.param2)
  83. local backpos = vector.add(pos, back_dir)
  84. local backnet = bitumen.pipes.get_net(backpos)
  85. if backnet == nil then
  86. -- print("no network")
  87. return
  88. end
  89. local max_amount = 1
  90. local taken, fluid = bitumen.pipes.take_fluid(backpos, max_amount)
  91. -- print("taken " .. fluid .. " " .. taken)
  92. local heat = bitumen.fluid_to_heat(fluid, taken)
  93. ainv:add_item("fuel", "bitumen:heat ".. math.floor(heat+.5))
  94. -- print("")
  95. -- print("added heat ".. heat)
  96. end
  97. })
  98. minetest.register_craft({
  99. output = "bitumen:heater",
  100. recipe = {
  101. {"default:tin_ingot", "default:furnace", "default:tin_ingot"},
  102. {"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
  103. {"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
  104. }
  105. })