reactor.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. -- Functions for the generator nodes.
  2. reactor = reactor or {}
  3. reactor_inactive = reactor_inactive or {}
  4. reactor_active = reactor_active or {}
  5. reactor.siren = reactor.siren or {}
  6. local BUFFER_SIZE = tech.reactor.buffer
  7. local ENERGY_TIME = tech.reactor.time
  8. local TOTAL_COOK_TIME = tech.reactor.totaltime
  9. local ENERGY_AMOUNT = tech.reactor.power
  10. local REACTOR_TIER = "hv"
  11. -- Localize for performance.
  12. local math_floor = math.floor
  13. local math_random = math.random
  14. local SS_OFF = 0
  15. local SS_DANGER = 1
  16. local SS_CLEAR = 2
  17. local reactor_siren = reactor.siren
  18. local function siren_set_state(pos, state)
  19. local hpos = minetest.hash_node_position(pos)
  20. local siren = reactor_siren[hpos]
  21. if not siren then
  22. if state == SS_OFF then return end
  23. siren = {state=SS_OFF}
  24. reactor_siren[hpos] = siren
  25. end
  26. if state == SS_DANGER and siren.state ~= SS_DANGER then
  27. if siren.handle then minetest.sound_stop(siren.handle) end
  28. siren.handle = minetest.sound_play("technic_hv_nuclear_reactor_siren_danger_loop",
  29. {pos=pos, gain=1.5, loop=true, max_hear_distance=48})
  30. siren.state = SS_DANGER
  31. elseif state == SS_CLEAR then
  32. if siren.handle then minetest.sound_stop(siren.handle) end
  33. local clear_handle = minetest.sound_play("technic_hv_nuclear_reactor_siren_clear",
  34. {pos=pos, gain=1.5, loop=false, max_hear_distance=48})
  35. siren.handle = clear_handle
  36. siren.state = SS_CLEAR
  37. minetest.after(10, function()
  38. if siren.handle ~= clear_handle then return end
  39. minetest.sound_stop(clear_handle)
  40. if reactor_siren[hpos] == siren then
  41. reactor_siren[hpos] = nil
  42. end
  43. end)
  44. elseif state == SS_OFF and siren.state ~= SS_OFF then
  45. if siren.handle then minetest.sound_stop(siren.handle) end
  46. reactor_siren[hpos] = nil
  47. end
  48. end
  49. local function siren_danger(pos, meta)
  50. meta:set_int("siren", 1)
  51. siren_set_state(pos, SS_DANGER)
  52. end
  53. local function siren_clear(pos, meta)
  54. if meta:get_int("siren") ~= 0 then
  55. siren_set_state(pos, SS_CLEAR)
  56. meta:set_int("siren", 0)
  57. end
  58. end
  59. local function get_reactor_damage(pos)
  60. local meta = minetest.get_meta(pos)
  61. local owner = meta:get_string("owner")
  62. local vm = VoxelManip()
  63. local pos1 = vector.subtract(pos, 4)
  64. local pos2 = vector.add(pos, 4)
  65. local MinEdge, MaxEdge = vm:read_from_map(pos1, pos2)
  66. local data = vm:get_data()
  67. local area = VoxelArea:new({MinEdge=MinEdge, MaxEdge=MaxEdge})
  68. local c_blast_concrete = minetest.get_content_id("concrete:brc")
  69. local c_lead = minetest.get_content_id("lead:block")
  70. local c_steel = minetest.get_content_id("stainless_steel:block")
  71. local c_water_source = minetest.get_content_id("default:water_source")
  72. local c_water_flowing = minetest.get_content_id("default:water_flowing")
  73. local c_cw_source = minetest.get_content_id("cw:water_source")
  74. local c_cw_flowing = minetest.get_content_id("cw:water_flowing")
  75. local c_river_source = minetest.get_content_id("default:river_water_source")
  76. local c_river_flowing = minetest.get_content_id("default:river_water_flowing")
  77. local c_concrete = minetest.get_content_id("concrete:concrete")
  78. local concrete_layer, blast_layer, lead_layer, water_layer = 0, 0, 0, 0
  79. for z = pos1.z, pos2.z do
  80. for y = pos1.y, pos2.y do
  81. for x = pos1.x, pos2.x do
  82. local cid = data[area:index(x, y, z)]
  83. if x == pos1.x+0 or x == pos2.x-0 or
  84. y == pos1.y+0 or y == pos2.y-0 or
  85. z == pos1.z+0 or z == pos2.z-0 then
  86. if cid == c_concrete then
  87. concrete_layer = concrete_layer + 1
  88. end
  89. elseif x == pos1.x+1 or x == pos2.x-1 or
  90. y == pos1.y+1 or y == pos2.y-1 or
  91. z == pos1.z+1 or z == pos2.z-1 then
  92. if cid == c_blast_concrete then
  93. blast_layer = blast_layer + 1
  94. end
  95. elseif x == pos1.x+2 or x == pos2.x-2 or
  96. y == pos1.y+2 or y == pos2.y-2 or
  97. z == pos1.z+2 or z == pos2.z-2 then
  98. if cid == c_lead or cid == c_steel then
  99. lead_layer = lead_layer + 1
  100. end
  101. elseif x == pos1.x+3 or x == pos2.x-3 or
  102. y == pos1.y+3 or y == pos2.y-3 or
  103. z == pos1.z+3 or z == pos2.z-3 then
  104. if cid == c_water_source or cid == c_water_flowing or
  105. cid == c_river_source or cid == c_river_flowing or
  106. cid == c_cw_source or cid == c_cw_flowing then
  107. water_layer = water_layer + 1
  108. end
  109. end
  110. end
  111. end
  112. end
  113. --minetest.chat_send_player("MustTest", "Checking reactor!")
  114. -- Debug!
  115. --if minetest.is_singleplayer() or gdac.player_is_admin(owner) then
  116. -- return 0
  117. --end
  118. if water_layer > 25 then water_layer = 25 end
  119. if lead_layer > 96 then lead_layer = 96 end
  120. if blast_layer > 216 then blast_layer = 216 end
  121. if concrete_layer > 384 then concrete_layer = 384 end
  122. return (25 - water_layer) +
  123. (96 - lead_layer) +
  124. (216 - blast_layer) +
  125. (384 - concrete_layer)
  126. end
  127. local function check_environment(pos, meta)
  128. --minetest.chat_send_player("MustTest", "Check env!")
  129. local timer = meta:get_int("chktmr")
  130. --local active = meta:get_int("active")
  131. if timer <= 0 then
  132. local result = false
  133. local good = false
  134. local damage = get_reactor_damage(pos)
  135. if damage == 0 then
  136. good = true
  137. end
  138. --minetest.chat_send_player("MustTest", "Reactor damage: " .. damage .. "!")
  139. if good then
  140. meta:set_string("error", "DUMMY")
  141. result = false
  142. else
  143. meta:set_string("error", "INSUFFICIENT REACTOR SHIELDING!")
  144. result = true -- Bad
  145. end
  146. -- Randomize time to next nodecheck.
  147. meta:set_int("chktmr", math_random(1*60, 3*60))
  148. return result
  149. end
  150. -- Decrement check timer.
  151. timer = timer - 1
  152. meta:set_int("chktmr", timer)
  153. -- No check performed.
  154. return nil
  155. end
  156. for k, v in ipairs({
  157. {name="inactive"},
  158. {name="active"},
  159. }) do
  160. -- Which function table are we operating on?
  161. local func = _G["reactor_" .. v.name]
  162. func.on_energy_get =
  163. function(pos, energy)
  164. local meta = minetest.get_meta(pos)
  165. local inv = meta:get_inventory()
  166. local have = inv:get_stack("out", 1):get_count()
  167. if have < energy then
  168. inv:set_stack("out", 1, ItemStack(""))
  169. if have > 0 then
  170. func.trigger_update(pos)
  171. end
  172. return have
  173. end
  174. have = have - energy
  175. inv:set_stack("out", 1, ItemStack("atomic:energy " .. have))
  176. if energy > 0 then
  177. func.trigger_update(pos)
  178. end
  179. return energy
  180. end
  181. func.reactor_destroy =
  182. function(pos)
  183. minetest.after(0, function()
  184. tnt.boom(pos, {
  185. radius = 20,
  186. ignore_protection = false,
  187. ignore_on_blast = false,
  188. damage_radius = 30,
  189. disable_drops = true,
  190. })
  191. local minp = vector.subtract(pos, 1)
  192. local maxp = vector.add(pos, 1)
  193. -- Transform reactor and all water around it into lava.
  194. -- Must be done *after* explosion runs.
  195. for x=minp.x, maxp.x do
  196. for y=minp.y, maxp.y do
  197. for z=minp.z, maxp.z do
  198. local p = {x=x, y=y, z=z}
  199. if p.y < -14 then
  200. minetest.add_node(p, {name="default:lava_source"})
  201. minetest.transforming_liquid_add(p)
  202. else
  203. minetest.add_node(p, {name="fire:basic_flame"})
  204. end
  205. end
  206. end
  207. end
  208. end)
  209. end
  210. func.trigger_update =
  211. function(pos)
  212. local timer = minetest.get_node_timer(pos)
  213. -- Restart timer even if already running.
  214. timer:start(1.0)
  215. end
  216. func.on_punch =
  217. function(pos, node, puncher, pointed_thing)
  218. --minetest.chat_send_player("MustTest", "Punched!")
  219. func.trigger_update(pos)
  220. -- Check reactor integrity.
  221. local meta = minetest.get_meta(pos)
  222. meta:set_int("chktmr", 0)
  223. func.privatize(meta)
  224. end
  225. func.compose_formspec =
  226. function(fuel_percent, item_percent)
  227. local formspec =
  228. "size[8,8.5]" ..
  229. default.formspec.get_form_colors() ..
  230. default.formspec.get_form_image() ..
  231. default.formspec.get_slot_colors() ..
  232. "label[1,0.5;Uranium Rod Compartment]" ..
  233. "list[context;fuel;1,1;3,2;]" ..
  234. utility.progress_image(4, 1.5, "default_furnace_fire_bg.png", "default_furnace_fire_fg.png", fuel_percent) ..
  235. utility.progress_image(5, 1.5, "gui_furnace_arrow_bg.png", "gui_furnace_arrow_fg.png", item_percent, "^[transformR270") ..
  236. "label[6,1.0;Charge Buffer]" ..
  237. "list[context;out;6,1.5;1,1;]" ..
  238. "list[current_player;main;0,4.25;8,1;]" ..
  239. "list[current_player;main;0,5.5;8,3;8]" ..
  240. "listring[context;fuel]" ..
  241. "listring[current_player;main]" ..
  242. default.get_hotbar_bg(0, 4.25)
  243. return formspec
  244. end
  245. func.compose_infotext =
  246. function(pos, keeprunning)
  247. local meta = minetest.get_meta(pos)
  248. local eups = meta:get_int("eups")
  249. local machine_state = "Standby"
  250. if keeprunning then machine_state = "Active" end
  251. local output = math_floor(eups / ENERGY_TIME)
  252. if not keeprunning then
  253. output = 0
  254. end
  255. local infotext = "Fission Reactor (" .. machine_state .. ")\n" ..
  256. "Output: " .. output .. " EU Per/Sec"
  257. local err = meta:get_string("error") or "DUMMY"
  258. if err ~= "" and err ~= "DUMMY" then
  259. infotext = infotext .. "\n" .. err
  260. end
  261. local damage = meta:get_int("damage")
  262. if damage > 0 then
  263. infotext = infotext .. "\nReactor damage: " .. damage .. "!"
  264. end
  265. return infotext
  266. end
  267. func.can_dig =
  268. function(pos, player)
  269. local meta = minetest.get_meta(pos)
  270. local inv = meta:get_inventory()
  271. -- The energy output inventory does not count.
  272. return inv:is_empty("fuel")
  273. end
  274. func.allow_metadata_inventory_put =
  275. function(pos, listname, index, stack, player)
  276. if minetest.test_protection(pos, player:get_player_name()) then
  277. return 0
  278. end
  279. if listname == "fuel" then
  280. local node = minetest.get_node(pos)
  281. -- Cannot put rods in an active reactor.
  282. if node.name == "reactor:inactive" and stack:get_name() == "uranium:rod" then
  283. return stack:get_count()
  284. end
  285. end
  286. return 0
  287. end
  288. func.allow_metadata_inventory_move =
  289. function(pos, from_list, from_index, to_list, to_index, count, player)
  290. return 0
  291. end
  292. func.allow_metadata_inventory_take =
  293. function(pos, listname, index, stack, player)
  294. if minetest.test_protection(pos, player:get_player_name()) then
  295. return 0
  296. end
  297. if listname == "fuel" then
  298. return stack:get_count()
  299. end
  300. return 0
  301. end
  302. func.on_timer =
  303. function(pos, elapsed)
  304. --minetest.chat_send_all("# Server: On Timer! " .. minetest.get_gametime())
  305. local keeprunning = false
  306. local meta = minetest.get_meta(pos)
  307. local owner = meta:get_string("owner")
  308. local inv = meta:get_inventory()
  309. local fuellist = inv:get_list("fuel")
  310. local time = meta:get_int("time")
  311. local time2 = meta:get_float("time2")
  312. local maxtime = meta:get_int("maxtime")
  313. local maxtime2 = ENERGY_TIME
  314. local eups = meta:get_int("eups")
  315. local fuel_percent = 0
  316. local item_percent = 0
  317. local need_discharge = false
  318. -- This sets infotext, so must always call this.
  319. local bad = check_environment(pos, meta)
  320. if v.name == "active" then
  321. if bad ~= nil then
  322. if bad then
  323. meta:set_int("bad", 1)
  324. siren_danger(pos, meta)
  325. else
  326. if meta:get_int("bad") == 1 then
  327. siren_clear(pos, meta)
  328. end
  329. meta:set_int("bad", 0)
  330. end
  331. end
  332. -- Damage reactor over time if bad.
  333. if meta:get_int("bad") == 1 then
  334. local damage = meta:get_int("damage")
  335. damage = damage + 1
  336. meta:set_int("damage", damage)
  337. -- Destroy reactor after 10 minutes of continous damage.
  338. if damage > 60*10 then
  339. func.reactor_destroy(pos)
  340. return
  341. end
  342. else
  343. -- Slowly decrease damage if not bad.
  344. local damage = meta:get_int("damage")
  345. if damage > 0 then
  346. damage = damage - 1
  347. meta:set_int("damage", damage)
  348. end
  349. end
  350. else
  351. -- Slowly decrease damage when inactive.
  352. local damage = meta:get_int("damage")
  353. if damage > 0 then
  354. damage = damage - 1
  355. meta:set_int("damage", damage)
  356. end
  357. end
  358. -- Radiation damage to nearby players.
  359. if v.name == "active" then
  360. local entities = minetest.get_objects_inside_radius(pos, 4.5)
  361. for k, v in ipairs(entities) do
  362. if v:is_player() then
  363. v:set_hp(v:get_hp() - 1)
  364. -- Radiation exhausts player.
  365. sprint.set_stamina(v, 0)
  366. end
  367. end
  368. end
  369. do
  370. local stack = inv:get_stack("out", 1)
  371. --minetest.chat_send_player("MustTest", "# Server: " .. stack:get_count() .. " charge!")
  372. if stack:get_count() >= BUFFER_SIZE then
  373. need_discharge = true
  374. end
  375. end
  376. -- Manage fuel.
  377. if time > 0 then
  378. -- Keep burning current fuel item.
  379. time = time - 1
  380. -- Restart timer.
  381. keeprunning = true
  382. -- Generate energy.
  383. time2 = time2 + 1
  384. if time2 >= maxtime2 then
  385. if not need_discharge then
  386. local energy = "atomic:energy " .. eups
  387. if inv:room_for_item("out", energy) then
  388. inv:add_item("out", energy)
  389. else
  390. -- No room? Huh. Discharge reactor!
  391. -- Note: this can happen because charge to be added would be
  392. -- greater than stack_max. This bug was actually observed.
  393. -- It is only likely to affect high-output machines.
  394. need_discharge = true
  395. end
  396. end
  397. time2 = 0
  398. end
  399. else
  400. -- Burntime has run out, get new fuel item.
  401. if fuellist[1]:get_count() > 0 and not need_discharge then
  402. local fuel, afterfuel
  403. local is_mese = false
  404. meta:set_int("eups", 0)
  405. -- Check if we have enough fuel.
  406. local rods = 0
  407. for i = 1, 6, 1 do
  408. local stack = inv:get_stack("fuel", i)
  409. if stack:get_name() == "uranium:rod" and stack:get_count() > 0 then
  410. rods = rods + 1
  411. end
  412. end
  413. -- Try to get fuel.
  414. fuel, afterfuel = minetest.get_craft_result({
  415. method="coalfuel", width=1, items=fuellist,
  416. })
  417. if rods == 6 then
  418. -- We got uranium rods, consume them.
  419. for i = 1, 6, 1 do
  420. inv:set_stack("fuel", i, ItemStack(""))
  421. end
  422. time = TOTAL_COOK_TIME
  423. meta:set_int("maxtime", TOTAL_COOK_TIME)
  424. machines.swap_node(pos, "reactor:active")
  425. fuel_percent = 100
  426. keeprunning = true -- Restart timer.
  427. meta:set_int("eups", ENERGY_AMOUNT)
  428. else
  429. -- No valid fuel in fuel slot.
  430. machines.swap_node(pos, "reactor:inactive")
  431. --minetest.get_node_timer(pos):stop()
  432. time2 = 0
  433. end
  434. else
  435. -- No more fuel, shutdown generator.
  436. machines.swap_node(pos, "reactor:inactive")
  437. --minetest.get_node_timer(pos):stop()
  438. meta:set_int("eups", 0)
  439. time2 = 0
  440. end
  441. end
  442. -- Discharge energy into the network.
  443. if need_discharge then
  444. --minetest.chat_send_player("MustTest", "# Server: Discharging reactor!")
  445. local timer = meta:get_int("dschgtmr")
  446. -- It's frequently the case that a reactor spends a lot of time trying to
  447. -- send energy to a network where all the batteries are full. We can save
  448. -- the server some work by delaying a little before the next discharge, if
  449. -- the last discharge didn't succeed.
  450. if timer <= 0 then
  451. local energy = inv:get_stack("out", 1)
  452. local old = energy:get_count()
  453. energy:set_count(net2.put_energy(pos, owner, old, REACTOR_TIER))
  454. inv:set_stack("out", 1, energy)
  455. if energy:get_count() < old then
  456. -- If we succeeded in discharging energy, keep doing so.
  457. -- Otherwise, batteries are full.
  458. keeprunning = true
  459. else
  460. meta:set_int("dschgtmr", 60)
  461. end
  462. else
  463. timer = timer - 1
  464. meta:set_int("dschgtmr", timer)
  465. end
  466. end
  467. -- If generator is no longer producing energy,
  468. -- unload the buffered energy.
  469. if not keeprunning then
  470. local energy = inv:get_stack("out", 1)
  471. energy:set_count(net2.put_energy(pos, owner, energy:get_count(), REACTOR_TIER))
  472. inv:set_stack("out", 1, energy)
  473. end
  474. -- Update infotext & formspec.
  475. meta:set_int("time", time)
  476. meta:set_float("time2", time2)
  477. fuel_percent = math_floor(time / maxtime * 100)
  478. item_percent = math_floor(time2 / maxtime2 * 100)
  479. meta:set_string("infotext", func.compose_infotext(pos, keeprunning))
  480. meta:set_string("formspec", func.compose_formspec(fuel_percent, item_percent))
  481. -- Determine mode (active or sleep) and set timer accordingly.
  482. if keeprunning then
  483. minetest.get_node_timer(pos):start(1.0)
  484. -- Change water to salt water sometimes.
  485. if math_random(1, 60) == 1 then
  486. local minp = {x=pos.x-1, y=pos.y-1, z=pos.z-1}
  487. local maxp = {x=pos.x+1, y=pos.y+1, z=pos.z+1}
  488. local nodes = minetest.find_nodes_in_area(minp, maxp, {
  489. "default:water_source",
  490. "default:water_flowing",
  491. "default:river_water_flowing",
  492. })
  493. if nodes and #nodes > 0 then
  494. minetest.add_node(nodes[math_random(1, #nodes)], {name="default:river_water_source"})
  495. end
  496. end
  497. else
  498. -- Slow down timer during sleep periods to reduce load.
  499. minetest.get_node_timer(pos):start(math_random(1, 3*60))
  500. end
  501. end
  502. func.on_blast =
  503. function(pos)
  504. local drops = {}
  505. -- Ignore contents of fuel inventory.
  506. minetest.remove_node(pos)
  507. if v.name == "active" then
  508. func.reactor_destroy(pos)
  509. else
  510. -- Only save reactor if it wasn't active.
  511. drops[#drops+1] = "reactor:inactive"
  512. end
  513. return drops
  514. end
  515. func.on_construct =
  516. function(pos)
  517. local meta = minetest.get_meta(pos)
  518. local inv = meta:get_inventory()
  519. meta:set_string("infotext", func.compose_infotext(pos, false))
  520. meta:set_string("formspec", func.compose_formspec(0, 0))
  521. --minetest.chat_send_player("MustTest", "Constructed!")
  522. inv:set_size("fuel", 6)
  523. inv:set_size("out", 1)
  524. meta:set_string("owner", "DUMMY")
  525. meta:set_string("error", "DUMMY")
  526. meta:set_string("nodename", "DUMMY")
  527. meta:set_int("siren", 0)
  528. meta:set_int("chktmr", 0)
  529. meta:set_int("eups", 0)
  530. meta:set_int("damage", 0)
  531. meta:set_int("time", 0)
  532. meta:set_int("maxtime", 0)
  533. meta:set_int("bad", 0)
  534. meta:set_float("time2", 0.0)
  535. func.privatize(meta)
  536. end
  537. func.privatize =
  538. function(meta)
  539. meta:mark_as_private({
  540. "nodename", "bad", "time2", "maxtime", "siren", "owner",
  541. "chktmr", "error", "eups", "damage", "time", "dschgtmr",
  542. })
  543. end
  544. func.on_destruct =
  545. function(pos)
  546. local meta = minetest.get_meta(pos)
  547. siren_set_state(pos, SS_OFF)
  548. net2.clear_caches(pos, meta:get_string("owner"), REACTOR_TIER)
  549. nodestore.del_node(pos)
  550. if v.name == "active" then
  551. func.reactor_destroy(pos)
  552. end
  553. end
  554. func.after_place_node =
  555. function(pos, placer, itemstack, pointed_thing)
  556. local meta = minetest.get_meta(pos)
  557. local node = minetest.get_node(pos)
  558. local owner = placer:get_player_name()
  559. meta:set_string("nodename", node.name)
  560. meta:set_string("owner", owner)
  561. net2.clear_caches(pos, owner, REACTOR_TIER)
  562. nodestore.add_node(pos)
  563. end
  564. func.on_metadata_inventory_move =
  565. function(pos)
  566. func.trigger_update(pos)
  567. end
  568. func.on_metadata_inventory_put =
  569. function(pos)
  570. func.trigger_update(pos)
  571. end
  572. func.on_metadata_inventory_take =
  573. function(pos, listname, index, stack, player)
  574. func.trigger_update(pos)
  575. end
  576. end
  577. if not reactor.run_once then
  578. for k, v in ipairs({
  579. {name="inactive", light=0},
  580. {name="active", light=14},
  581. }) do
  582. -- Which function table are we operating on?
  583. local func = _G["reactor_" .. v.name]
  584. minetest.register_node(":reactor:" .. v.name, {
  585. description = "Fission Reactor Core\n\nConnects to an HV power-network.\nGenerates huge amounts of power.\nExplosion danger, requires shielding!",
  586. tiles = {"reactor_core.png"},
  587. groups = utility.dig_groups("machine", {immovable=1}),
  588. paramtype2 = "facedir",
  589. is_ground_content = false,
  590. sounds = default.node_sound_metal_defaults(),
  591. drop = "reactor:inactive",
  592. light_source = v.light,
  593. on_energy_get = function(...)
  594. return func.on_energy_get(...) end,
  595. on_rotate = function(...)
  596. return screwdriver.rotate_simple(...) end,
  597. on_punch = function(...)
  598. return func.on_punch(...) end,
  599. can_dig = function(...)
  600. return func.can_dig(...) end,
  601. on_timer = function(...)
  602. return func.on_timer(...) end,
  603. on_construct = function(...)
  604. return func.on_construct(...) end,
  605. on_destruct = function(...)
  606. return func.on_destruct(...) end,
  607. after_place_node = function(...)
  608. return func.after_place_node(...) end,
  609. on_blast = function(...)
  610. return func.on_blast(...) end,
  611. on_metadata_inventory_move = function(...)
  612. return func.on_metadata_inventory_move(...) end,
  613. on_metadata_inventory_put = function(...)
  614. return func.on_metadata_inventory_put(...) end,
  615. on_metadata_inventory_take = function(...)
  616. return func.on_metadata_inventory_take(...) end,
  617. allow_metadata_inventory_put = function(...)
  618. return func.allow_metadata_inventory_put(...) end,
  619. allow_metadata_inventory_move = function(...)
  620. return func.allow_metadata_inventory_move(...) end,
  621. allow_metadata_inventory_take = function(...)
  622. return func.allow_metadata_inventory_take(...) end,
  623. })
  624. end
  625. minetest.register_craft({
  626. output = 'reactor:inactive',
  627. recipe = {
  628. {'techcrafts:carbon_plate', 'default:obsidian_glass', 'techcrafts:carbon_plate'},
  629. {'techcrafts:composite_plate', 'gen2:hv_inactive', 'techcrafts:composite_plate'},
  630. {'stainless_steel:ingot', 'geo2:lv_inactive', 'stainless_steel:ingot'},
  631. }
  632. })
  633. local c = "reactor:core"
  634. local f = machines.modpath .. "/reactor.lua"
  635. reload.register_file(c, f, false)
  636. reactor.run_once = true
  637. end