init.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. if not minetest.global_exists("battery") then battery = {} end
  2. battery.modpath = minetest.get_modpath("battery")
  3. dofile(battery.modpath .. "/functions.lua")
  4. dofile(battery.modpath .. "/battery.lua")
  5. dofile(battery.modpath .. "/bat2.lua")
  6. -- The battery array is basically a box with slots in which batteries
  7. -- can be placed, thus giving it the ability to store energy. The box
  8. -- provides the wiring so all the batteries can be accessed as a unit.
  9. for k, v in ipairs({
  10. {tier="lv", title="Low-Voltage"},
  11. {tier="mv", title="Medium-Voltage"},
  12. {tier="hv", title="High-Voltage"},
  13. }) do
  14. -- Register 13 nodes for each tier; each node has a different texture set to show the charge level.
  15. for i = 0, 12, 1 do
  16. -- Which function table are we operating on?
  17. local functable = _G["battery_" .. v.tier]
  18. minetest.register_node("battery:array" .. i .. "_" .. v.tier, {
  19. description = v.title .. " Battery Array",
  20. tiles = {
  21. "technic_" .. v.tier .. "_battery_box_top.png",
  22. "technic_" .. v.tier .. "_battery_box_bottom.png",
  23. "technic_" .. v.tier .. "_battery_box_side.png^battery_meter" .. i .. ".png",
  24. "technic_" .. v.tier .. "_battery_box_side.png^battery_meter" .. i .. ".png",
  25. "technic_" .. v.tier .. "_battery_box_side.png^battery_meter" .. i .. ".png",
  26. "technic_" .. v.tier .. "_battery_box_side.png^battery_meter" .. i .. ".png",
  27. },
  28. groups = utility.dig_groups("machine", {
  29. immovable = 1,
  30. ["tier_" .. v.tier] = 1,
  31. }),
  32. paramtype2 = "facedir",
  33. on_rotate = function(...) return screwdriver.rotate_simple(...) end,
  34. is_ground_content = false,
  35. sounds = default.node_sound_metal_defaults(),
  36. drop = "bat2:bt0_" .. v.tier,
  37. on_punch = function(...)
  38. return functable.on_punch(...) end,
  39. can_dig = function(...)
  40. return functable.can_dig(...) end,
  41. on_timer = function(...)
  42. return functable.on_timer(...) end,
  43. on_construct = function(...)
  44. return functable.on_construct(...) end,
  45. after_place_node = function(...)
  46. return functable.after_place_node(...) end,
  47. on_metadata_inventory_move = function(...)
  48. return functable.on_metadata_inventory_move(...) end,
  49. on_metadata_inventory_put = function(...)
  50. return functable.on_metadata_inventory_put(...) end,
  51. on_metadata_inventory_take = function(...)
  52. return functable.on_metadata_inventory_take(...) end,
  53. on_blast = function(...)
  54. return functable.on_blast(...) end,
  55. allow_metadata_inventory_put = function(...)
  56. return functable.allow_metadata_inventory_put(...) end,
  57. allow_metadata_inventory_move = function(...)
  58. return functable.allow_metadata_inventory_move(...) end,
  59. allow_metadata_inventory_take = function(...)
  60. return functable.allow_metadata_inventory_take(...) end,
  61. on_machine_execute = function(...)
  62. return functable.on_machine_execute(...) end,
  63. })
  64. -- Alias old non-tiered nodes to tiered nodes.
  65. if v.tier == "lv" then
  66. minetest.register_alias("battery:array" .. i, "battery:array" .. i .. "_lv")
  67. end
  68. end
  69. end
  70. minetest.register_alias("battery:lv_battery", "battery:array0_lv")
  71. minetest.register_alias("battery:array", "battery:array0_lv")
  72. minetest.register_craft({
  73. output = 'bat2:bt0_lv',
  74. recipe = {
  75. {'group:wood', 'transformer:lv', 'group:wood'},
  76. {'rubber:rubber_fiber', 'techcrafts:machine_casing', 'rubber:rubber_fiber'},
  77. {'fine_wire:copper', 'cb2:lv', 'fine_wire:copper'},
  78. }
  79. })
  80. minetest.register_craft({
  81. output = 'bat2:bt0_mv',
  82. recipe = {
  83. {'bat2:bt0_lv', 'transformer:mv', 'bat2:bt0_lv'},
  84. {'rubber:rubber_fiber', 'techcrafts:machine_casing', 'rubber:rubber_fiber'},
  85. {'fine_wire:silver', 'cb2:mv', 'fine_wire:silver'},
  86. }
  87. })
  88. minetest.register_craft({
  89. output = 'bat2:bt0_hv',
  90. recipe = {
  91. {'bat2:bt0_mv', 'transformer:hv', 'bat2:bt0_mv'},
  92. {'rubber:rubber_fiber', 'techcrafts:machine_casing', 'rubber:rubber_fiber'},
  93. {'fine_wire:gold', 'cb2:hv', 'fine_wire:gold'},
  94. }
  95. })