electrode.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. if minetest.get_modpath("technic") ~= nil then
  2. local minetest, pairs, min = minetest, pairs, math.min
  3. local modname = minetest.get_current_modname()
  4. local forge, melt_energy_requirement, meltable_ores, random_melt_product = ...
  5. local electrode_min_demand = 20
  6. local function electrode_run(pos, node)
  7. local meta = minetest.get_meta(pos)
  8. local input = meta:get_int("LV_EU_input")
  9. local heat = meta:get_int("stored_eu")
  10. local current_charge = meta:get_int("internal_EU_charge")
  11. if false and input < electrode_min_demand then
  12. meta:set_string("infotext", "Electrode Unpowered")
  13. return
  14. end
  15. heat = heat + input
  16. meta:set_string("infotext", "Electrode Active")
  17. local ore_nodes = minetest.find_nodes_in_area(
  18. {x=pos.x - 3, y=pos.y - 6,z=pos.z - 3},
  19. {x=pos.x + 3, y=pos.y, z=pos.z + 3},
  20. meltable_ores
  21. )
  22. for _,p in pairs(ore_nodes) do
  23. local n = minetest.get_node(p)
  24. local req = melt_energy_requirement[n.name]
  25. if heat < req then
  26. break
  27. end
  28. heat = heat - req
  29. minetest.set_node(p, {name=random_melt_product(n.name)})
  30. end
  31. meta:set_int("stored_eu", min(forge.max_heat, heat))
  32. end
  33. minetest.register_node(modname..":electrode", {
  34. description = "Electrode",
  35. drawtype = "nodebox",
  36. tiles = {"default_steel_block.png^[colorize:blue:10"},
  37. paramtype = "light",
  38. paramtype2 = "facedir",
  39. is_ground_content = false,
  40. groups = {cracky=3, refractory=1, technic_machine=1, technic_lv=1 },
  41. node_box = {
  42. type = "fixed",
  43. fixed = {
  44. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  45. {-.5, -2.5, -0.15, -.2, 0, 0.15},
  46. {.5, -2.5, -0.15, .2, 0, 0.15},
  47. },
  48. },
  49. on_punch = function (pos, node)
  50. minetest.set_node(pos, {name=modname..":electrode_on"})
  51. end,
  52. on_construct = function(pos)
  53. local meta = minetest.get_meta(pos)
  54. meta:set_int("enabled", 0)
  55. meta:set_int("active", 0)
  56. meta:set_string("power_flag", "LV")
  57. meta:get_int("stored_eu", 0)
  58. meta:set_int("LV_EU_demand", 0)
  59. end,
  60. })
  61. minetest.register_craft({
  62. output = modname..':electrode',
  63. recipe = {
  64. {"technic:lv_cable0", "default:steelblock", "technic:lv_cable0"},
  65. {"default:steel_ingot", "", "default:steel_ingot"},
  66. {"default:steel_ingot", "", "default:steel_ingot"},
  67. }
  68. })
  69. local function set_electrode_demand(meta)
  70. local machine_name = "Electrode"
  71. meta:set_int("LV_EU_demand", 10000000)
  72. -- meta:set_int("LV_EU_demand", electrode_demand)
  73. local input = meta:get_int("LV_EU_input")
  74. if input ~= nil then
  75. meta:set_string("infotext", (input > 0 and "%s Active" or "%s Unpowered"):format(machine_name))
  76. else
  77. meta:set_string("infotext", machine_name.. " has no network.")
  78. end
  79. end
  80. minetest.register_node(modname..":electrode_on", {
  81. description = "Electrode",
  82. drawtype = "nodebox",
  83. tiles = {"default_steel_block.png^default_torch.png^[colorize:blue:10"},
  84. paramtype = "light",
  85. paramtype2 = "facedir",
  86. is_ground_content = false,
  87. connect_sides = {"top"},
  88. groups = {
  89. cracky=3, refractory=1, technic_machine=1, technic_lv=1,
  90. not_in_creative_inventory = 1,
  91. },
  92. node_box = {
  93. type = "fixed",
  94. fixed = {
  95. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  96. {-.5, -2.5, -0.15, -.2, 0, 0.15},
  97. {.5, -2.5, -0.15, .2, 0, 0.15},
  98. },
  99. },
  100. on_punch = function (pos, node)
  101. minetest.set_node(pos, {name=modname..":electrode"})
  102. end,
  103. on_construct = function(pos)
  104. local meta = minetest.get_meta(pos)
  105. meta:set_int("enabled", 1)
  106. meta:set_int("active", 1)
  107. meta:set_string("power_flag", "LV")
  108. meta:set_int("stored_eu", 0)
  109. --meta:set_int("LV_EU_demand", 200)
  110. set_electrode_demand(meta)
  111. end,
  112. technic_run = electrode_run,
  113. drop = modname..":electrode",
  114. })
  115. -- technic.register_machine("LV", mn..":electrode", technic.receiver)
  116. -- technic.register_machine("LV", mn..":electrode_on", technic.receiver)
  117. technic.register_machine("LV", modname..":electrode", technic.receiver)
  118. technic.register_machine("LV", modname..":electrode_on", technic.battery)
  119. end