config.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. local S = minetest.get_translator("default")
  2. technic_farming.full_flow = 120
  3. local defaultfurnace = minetest.registered_items["default:furnace"]
  4. --print(dump(defaultfurnace.can_dig))
  5. function technic_farming.can_dig(pos, player)
  6. local meta = minetest.get_meta(pos);
  7. local inv = meta:get_inventory()
  8. return inv:is_empty("dst") and inv:is_empty("src")
  9. end
  10. function technic_farming.allow_metadata_inventory_put(pos, listname, index, stack, player)
  11. if minetest.is_protected(pos, player:get_player_name()) then
  12. return 0
  13. end
  14. local meta = minetest.get_meta(pos)
  15. local inv = meta:get_inventory()
  16. if listname == "src" then
  17. return stack:get_count()
  18. elseif listname == "dst" then
  19. return 0
  20. end
  21. end
  22. function technic_farming.allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
  23. local meta = minetest.get_meta(pos)
  24. local inv = meta:get_inventory()
  25. local stack = inv:get_stack(from_list, from_index)
  26. return technic_farming.allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  27. end
  28. function technic_farming.allow_metadata_inventory_take(pos, listname, index, stack, player)
  29. if minetest.is_protected(pos, player:get_player_name()) then
  30. return 0
  31. end
  32. return stack:get_count()
  33. end
  34. function technic_farming.swap_node(pos, name)
  35. local node = minetest.get_node(pos)
  36. if node.name ~= name then
  37. node.name = name
  38. minetest.swap_node(pos, node)
  39. end
  40. end
  41. function technic_farming.check_node_around_mill(pos)
  42. local node = minetest.get_node(pos)
  43. if node.name == "default:water_flowing"
  44. or node.name == "default:river_water_flowing" then
  45. return node.param2 or 0-- returns approx. water flow, if any
  46. end
  47. return 0
  48. end
  49. function technic_farming.check_node_around_windmill(pos)
  50. local node = minetest.get_node(pos)
  51. if node.name == "air" then
  52. return math.random(5,12)-- returns approx. air flow, if air node
  53. end
  54. return 0
  55. end
  56. function technic_farming.get_water_flow(pos)
  57. local pos_lower = {x=pos.x, y=pos.y-1, z=pos.z} -- get position directly under the machine
  58. local node_lower = minetest.get_node(pos_lower)
  59. local water_flow = 0
  60. if node_lower.name == "technic_farming:mp_water_mill" then
  61. local metawatermill = minetest.get_meta(pos_lower)
  62. local positions = {
  63. {x=pos_lower.x+1, y=pos_lower.y, z=pos_lower.z},
  64. {x=pos_lower.x-1, y=pos_lower.y, z=pos_lower.z},
  65. {x=pos_lower.x, y=pos_lower.y, z=pos_lower.z+1},
  66. {x=pos_lower.x, y=pos_lower.y, z=pos_lower.z-1},
  67. }
  68. for _, p in pairs(positions) do
  69. water_flow = water_flow + technic_farming.check_node_around_mill(p)
  70. end
  71. water_flow = math.min(4 * water_flow, technic_farming.full_flow)
  72. local infotext = S("water mill inactive")
  73. if water_flow > 0 then
  74. infotext = S("water mill active")
  75. end
  76. infotext = infotext .. "\n" .. S("(Power: @1)", water_flow)
  77. metawatermill:set_int("mp_water_power",water_flow)
  78. metawatermill:set_string("infotext", infotext)
  79. end
  80. return water_flow
  81. end
  82. function technic_farming.get_air_flow(pos)
  83. local pos_upper = {x=pos.x, y=pos.y+1, z=pos.z}
  84. local node_upper = minetest.get_node(pos_upper)
  85. local air_flow = 0
  86. if node_upper.name == "technic_farming:mp_wind_mill" then
  87. local metawindmill = minetest.get_meta(pos_upper)
  88. local positions = {
  89. {x=pos.x+1, y=pos.y+1, z=pos.z},
  90. {x=pos.x-1, y=pos.y+1, z=pos.z},
  91. {x=pos.x+1, y=pos.y+1, z=pos.z+1},
  92. {x=pos.x-1, y=pos.y+1, z=pos.z+1},
  93. {x=pos.x+1, y=pos.y+1, z=pos.z-1},
  94. {x=pos.x-1, y=pos.y+1, z=pos.z-1},
  95. {x=pos.x, y=pos.y+1, z=pos.z+1},
  96. {x=pos.x, y=pos.y+1, z=pos.z-1},
  97. }
  98. for _, p in pairs(positions) do
  99. air_flow = air_flow + technic_farming.check_node_around_windmill(p)
  100. end
  101. air_flow = math.min(4 * air_flow, technic_farming.full_flow)
  102. local infotext = S("wind mill inactive")
  103. if air_flow > 0 then
  104. infotext = S("wind mill active")
  105. end
  106. infotext = infotext .. "\n" .. S("(Power: @1)", air_flow)
  107. metawindmill:set_int("mp_wind_power",air_flow)
  108. metawindmill:set_string("infotext", infotext)
  109. end
  110. return air_flow
  111. end