init.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. -- HYDRO_TURBINE
  2. -- Water turbine:
  3. -- Active if flowing >water< above it
  4. -- (does not work with other liquids)
  5. minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
  6. drawtype = "mesh",
  7. mesh = "jeija_hydro_turbine_off.obj",
  8. tiles = {
  9. "jeija_hydro_turbine_sides_off.png",
  10. "jeija_hydro_turbine_top_bottom.png",
  11. "jeija_hydro_turbine_turbine_top_bottom_off.png",
  12. "jeija_hydro_turbine_turbine_misc_off.png"
  13. },
  14. inventory_image = "jeija_hydro_turbine_inv.png",
  15. is_ground_content = false,
  16. wield_scale = {x=0.75, y=0.75, z=0.75},
  17. groups = {dig_immediate=2},
  18. description="Water Turbine",
  19. paramtype = "light",
  20. selection_box = {
  21. type = "fixed",
  22. fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 },
  23. },
  24. sounds = default.node_sound_metal_defaults(),
  25. mesecons = {receptor = {
  26. state = mesecon.state.off
  27. }},
  28. on_blast = mesecon.on_blastnode,
  29. })
  30. minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
  31. drawtype = "mesh",
  32. is_ground_content = false,
  33. mesh = "jeija_hydro_turbine_on.obj",
  34. wield_scale = {x=0.75, y=0.75, z=0.75},
  35. tiles = {
  36. "jeija_hydro_turbine_sides_on.png",
  37. "jeija_hydro_turbine_top_bottom.png",
  38. { name = "jeija_hydro_turbine_turbine_top_bottom_on.png",
  39. animation = {type = "vertical_frames", aspect_w = 128, aspect_h = 16, length = 1.6} },
  40. { name = "jeija_hydro_turbine_turbine_misc_on.png",
  41. animation = {type = "vertical_frames", aspect_w = 256, aspect_h = 32, length = 0.4} }
  42. },
  43. inventory_image = "jeija_hydro_turbine_inv.png",
  44. drop = "mesecons_hydroturbine:hydro_turbine_off 1",
  45. groups = {dig_immediate=2,not_in_creative_inventory=1},
  46. description="Water Turbine",
  47. paramtype = "light",
  48. selection_box = {
  49. type = "fixed",
  50. fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 },
  51. },
  52. sounds = default.node_sound_metal_defaults(),
  53. mesecons = {receptor = {
  54. state = mesecon.state.on
  55. }},
  56. on_blast = mesecon.on_blastnode,
  57. })
  58. local function is_flowing_water(pos)
  59. local name = minetest.get_node(pos).name
  60. local is_water = minetest.get_item_group(name, "water") > 0
  61. local is_flowing = minetest.registered_items[name].liquidtype == "flowing"
  62. return (is_water and is_flowing)
  63. end
  64. minetest.register_abm({
  65. nodenames = {"mesecons_hydroturbine:hydro_turbine_off"},
  66. interval = 1,
  67. chance = 1,
  68. action = function(pos, node, active_object_count, active_object_count_wider)
  69. local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
  70. if is_flowing_water(waterpos) then
  71. minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"})
  72. mesecon.receptor_on(pos)
  73. end
  74. end,
  75. })
  76. minetest.register_abm({
  77. nodenames = {"mesecons_hydroturbine:hydro_turbine_on"},
  78. interval = 1,
  79. chance = 1,
  80. action = function(pos, node, active_object_count, active_object_count_wider)
  81. local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
  82. if not is_flowing_water(waterpos) then
  83. minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"})
  84. mesecon.receptor_off(pos)
  85. end
  86. end,
  87. })
  88. minetest.register_craft({
  89. output = "mesecons_hydroturbine:hydro_turbine_off 2",
  90. recipe = {
  91. {"","default:stick", ""},
  92. {"default:stick", "default:steel_ingot", "default:stick"},
  93. {"","default:stick", ""},
  94. }
  95. })