fan.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. minetest.register_node("factory:fan_on", {
  2. description = "Fan",
  3. tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png",
  4. "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
  5. groups = {cracky=3, mesecon_effector_off = 1},
  6. drawtype = "nodebox",
  7. paramtype = "light",
  8. is_ground_content = true,
  9. node_box = {
  10. type = "fixed",
  11. fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},}
  12. },
  13. mesecons = {effector = {
  14. action_on = function(pos, node)
  15. minetest.swap_node(pos, {name = "factory:fan_off", param2 = node.param2})
  16. end
  17. }}
  18. })
  19. minetest.register_node("factory:fan_off", {
  20. description = "Fan",
  21. tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png", "factory_belt_side.png",
  22. "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
  23. groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1},
  24. drawtype = "nodebox",
  25. paramtype = "light",
  26. is_ground_content = true,
  27. drop="factory:fan_on",
  28. node_box = {
  29. type = "fixed",
  30. fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},}
  31. },
  32. mesecons = {effector = {
  33. action_off = function(pos, node)
  34. minetest.swap_node(pos, {name = "factory:fan_on", param2 = node.param2})
  35. end
  36. }}
  37. })
  38. minetest.register_abm({
  39. nodenames = {"factory:fan_on"},
  40. neighbors = nil,
  41. interval = 1,
  42. chance = 1,
  43. action = function(pos, node, active_object_count, active_object_count_wider)
  44. local all_objects = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
  45. local _,obj
  46. for _,obj in ipairs(all_objects) do
  47. if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
  48. obj:moveto({x = obj:getpos().x, y = obj:getpos().y + 3, z = obj:getpos().z})
  49. end
  50. end
  51. end,
  52. })
  53. minetest.register_node("factory:fan_wall_on", {
  54. description = "Wall Fan",
  55. tiles = {"factory_belt_side.png^[transformFY", "factory_belt_side.png", "factory_belt_side.png^[transformR90",
  56. "factory_belt_side.png^[transformR270", "factory_belt_bottom.png", {name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}},
  57. groups = {cracky=3, mesecon_effector_off = 1},
  58. drawtype = "nodebox",
  59. paramtype = "light",
  60. paramtype2 = "facedir",
  61. is_ground_content = true,
  62. legacy_facedir_simple = true,
  63. node_box = {
  64. type = "fixed",
  65. fixed = {
  66. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.5},
  67. }
  68. },
  69. mesecons = {effector = {
  70. action_on = function(pos, node)
  71. minetest.swap_node(pos, {name = "factory:fan_wall_off", param2 = node.param2})
  72. end
  73. }}
  74. })
  75. minetest.register_node("factory:fan_wall_off", {
  76. description = "Wall Fan",
  77. tiles = {"factory_belt_side.png^[transformFY", "factory_belt_side.png", "factory_belt_side.png^[transformR90",
  78. "factory_belt_side.png^[transformR270", "factory_belt_bottom.png", {name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}},
  79. groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1},
  80. drawtype = "nodebox",
  81. paramtype = "light",
  82. paramtype2 = "facedir",
  83. is_ground_content = true,
  84. legacy_facedir_simple = true,
  85. drop="factory:fan_wall_on",
  86. node_box = {
  87. type = "fixed",
  88. fixed = {
  89. {-0.5, -0.5, -0.0625, 0.5, 0.5, 0.5},
  90. }
  91. },
  92. mesecons = {effector = {
  93. action_off = function(pos, node)
  94. minetest.swap_node(pos, {name = "factory:fan_wall_on", param2 = node.param2})
  95. end
  96. }}
  97. })
  98. minetest.register_abm({
  99. nodenames = {"factory:fan_wall_on"},
  100. neighbors = nil,
  101. interval = 1,
  102. chance = 1,
  103. action = function(pos, node, active_object_count, active_object_count_wider)
  104. local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
  105. local all_objects = minetest.get_objects_inside_radius({x = pos.x - a.x/2, y = pos.y, z = pos.z - a.z/2}, 1)
  106. local _,obj
  107. for _,obj in ipairs(all_objects) do
  108. if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
  109. obj:moveto({x = obj:getpos().x - a.x*2.0, y = obj:getpos().y, z = obj:getpos().z - a.z*2.0})
  110. end
  111. end
  112. end,
  113. })