stp.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. factory.stp_formspec =
  2. "size[8,8.5]"..
  3. factory_gui_bg..
  4. factory_gui_bg_img_2..
  5. factory_gui_slots..
  6. "list[current_name;src;2.75,0.5;1,1;]"..
  7. "list[current_name;fuel;2.75,2.5;1,1;]"..
  8. "image[3.75,1.5;1,1;gui_ind_furnace_arrow_bg.png^[transformR270]"..
  9. "list[current_name;dst;4.75,0.5;2,2;]"..
  10. "list[current_player;main;0,4.25;8,1;]"..
  11. "list[current_player;main;0,5.5;8,3;8]"..
  12. factory.get_hotbar_bg(0,4.25)
  13. minetest.register_node("factory:sapling_fertilizer", {
  14. tiles = {
  15. "default_dirt.png"
  16. },
  17. inventory_image = "factory_sapling_fertilizer.png",
  18. description = "Sapling Fertilizer",
  19. drawtype = "nodebox",
  20. paramtype = "light",
  21. is_ground_content = true,
  22. groups = {seed = 1, snappy = 3, attached_node = 1},
  23. node_box = {
  24. type = "fixed",
  25. fixed = {
  26. {-0.1875, -0.5, -0.1875, 0.1875, -0.4375, 0.1875},
  27. {-0.125, -0.4375, -0.125, 0.125, -0.375, 0.125},
  28. {0, -0.375, -0.0625, 0.0625, -0.3125, 0.0625},
  29. {0, -0.3125, -0.0625, 0.0625, -0.25, 0},
  30. {-0.0625, -0.375, -0.0625, 0, -0.3125, 0},
  31. }
  32. }
  33. })
  34. minetest.register_abm({
  35. nodenames = {"factory:sapling_fertilizer"},
  36. neighbors = nil,
  37. interval = 3,
  38. chance = 6,
  39. action = function(pos, node, active_object_count, active_object_count_wider)
  40. minetest.add_particlespawner({
  41. amount = 3,
  42. time = 1,
  43. minpos = {x = pos.x - 0.05, y = pos.y, z = pos.z - 0.05},
  44. maxpos = {x = pos.x + 0.05, y = pos.y, z = pos.z + 0.05},
  45. minvel = {x=-0.25, y=0.02, z=-0.25},
  46. maxvel = {x=0.25, y=0.10, z=0.25},
  47. minacc = {x=0, y=0, z=0},
  48. maxacc = {x=0, y=0, z=0},
  49. minexptime = 0.8,
  50. maxexptime = 2,
  51. minsize = 0.05,
  52. maxsize = 0.23,
  53. collisiondetection = true,
  54. vertical = false,
  55. texture = "factory_flies.png",
  56. playername = nil,
  57. })
  58. end,
  59. })
  60. minetest.register_node("factory:stp", {
  61. description = "Sapling Treatment Plant",
  62. tiles = {"factory_machine_brick_1.png", "factory_machine_brick_2.png", "factory_machine_side_1.png",
  63. "factory_machine_side_1.png", "factory_machine_side_1.png", "factory_stp_front.png"},
  64. paramtype2 = "facedir",
  65. groups = {cracky=3},
  66. legacy_facedir_simple = true,
  67. is_ground_content = false,
  68. on_construct = function(pos)
  69. local meta = minetest.get_meta(pos)
  70. meta:set_string("formspec", factory.ind_furnace_inactive_formspec)
  71. meta:set_string("infotext", "Sapling Treatment Plant")
  72. local inv = meta:get_inventory()
  73. inv:set_size("fuel", 1)
  74. inv:set_size("src", 1)
  75. inv:set_size("dst", 4)
  76. end,
  77. can_dig = function(pos,player)
  78. local meta = minetest.get_meta(pos);
  79. local inv = meta:get_inventory()
  80. if not inv:is_empty("fuel") then
  81. return false
  82. elseif not inv:is_empty("dst") then
  83. return false
  84. elseif not inv:is_empty("src") then
  85. return false
  86. end
  87. return true
  88. end,
  89. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  90. local meta = minetest.get_meta(pos)
  91. local inv = meta:get_inventory()
  92. if listname == "fuel" then
  93. if stack:get_name() == "factory:sapling_fertilizer" then
  94. return stack:get_count()
  95. end
  96. elseif listname == "src" then
  97. return stack:get_count()
  98. elseif listname == "dst" then
  99. return 0
  100. end
  101. end,
  102. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  103. local meta = minetest.get_meta(pos)
  104. local inv = meta:get_inventory()
  105. local stack = inv:get_stack(from_list, from_index)
  106. if to_list == "fuel" then
  107. return count
  108. elseif to_list == "src" then
  109. return count
  110. elseif to_list == "dst" then
  111. return 0
  112. end
  113. end,
  114. })
  115. minetest.register_abm({
  116. nodenames = {"factory:stp"},
  117. interval = 2.5,
  118. chance = 1,
  119. action = function(pos, node, active_object_count, active_object_count_wider)
  120. local meta = minetest.get_meta(pos)
  121. local inv = meta:get_inventory()
  122. local srclist = inv:get_list("src")
  123. if inv:contains_item("fuel", ItemStack("factory:sapling_fertilizer 1")) then
  124. for i,v in ipairs(factory.stpIO) do
  125. local rand = math.random(v.min, v.max)
  126. if inv:contains_item("src", ItemStack({name = v.input})) and inv:room_for_item("dst", {name = v.output, count = rand}) then
  127. minetest.add_particlespawner({
  128. amount = 4,
  129. time = 1,
  130. minpos = {x = pos.x - 0.2, y = pos.y, z = pos.z - 0.2},
  131. maxpos = {x = pos.x + 0.2, y = pos.y, z = pos.z + 0.2},
  132. minvel = {x=-0.4, y=0.4, z=-0.4},
  133. maxvel = {x=0.4, y=0.7, z=0.4},
  134. minacc = {x=0, y=0, z=0},
  135. maxacc = {x=0, y=0, z=0},
  136. minexptime = 0.8,
  137. maxexptime = 2,
  138. minsize = 2,
  139. maxsize = 4,
  140. collisiondetection = false,
  141. vertical = false,
  142. texture = "factory_smoke.png",
  143. playername = nil,
  144. })
  145. inv:add_item("dst", ItemStack({name = v.output, count = rand}))
  146. inv:remove_item("src", ItemStack({name = inv:get_stack("src", 1):get_name(), count = 1}))
  147. inv:remove_item("fuel", ItemStack({name = inv:get_stack("fuel", 1):get_name(), count = 1}))
  148. end
  149. end
  150. end
  151. end,
  152. })