qarm.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. function qarm_handle (a, b, target, stack, minv, obj)
  2. if target.name == "default:chest" or target.name == "default:chest_locked" then
  3. local meta = minetest.env:get_meta(b)
  4. local inv = meta:get_inventory()
  5. if inv:room_for_item("main", stack) then
  6. inv:add_item("main", stack)
  7. if obj~=nil then obj:remove() end
  8. elseif minv:room_for_item("main", stack) then
  9. minv:add_item("main", stack)
  10. if obj~=nil then obj:remove() end
  11. else
  12. if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
  13. end
  14. end
  15. if target.name == "factory:swapper" then
  16. local meta = minetest.env:get_meta(b)
  17. local inv = meta:get_inventory()
  18. if inv:room_for_item("input", stack) then
  19. inv:add_item("input", stack)
  20. if obj~=nil then obj:remove() end
  21. elseif minv:room_for_item("input", stack) then
  22. minv:add_item("input", stack)
  23. if obj~=nil then obj:remove() end
  24. else
  25. if obj~=nil then obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z }, false) end
  26. end
  27. end
  28. for i,v in ipairs(armDevicesFurnacelike) do
  29. if target.name == v then
  30. local meta = minetest.env:get_meta(b)
  31. local inv = meta:get_inventory()
  32. if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
  33. -- back, fuel
  34. if inv:room_for_item("fuel", stack) then
  35. inv:add_item("fuel", stack)
  36. if obj~=nil then obj:remove() end
  37. elseif minv:room_for_item("main", stack) then
  38. minv:add_item("main", stack)
  39. if obj~=nil then obj:remove() end
  40. else
  41. if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
  42. end
  43. else
  44. -- everytin else, src
  45. if inv:room_for_item("src", stack) then
  46. inv:add_item("src", stack)
  47. if obj~=nil then obj:remove() end
  48. elseif minv:room_for_item("main", stack) then
  49. minv:add_item("main", stack)
  50. if obj~=nil then obj:remove() end
  51. else
  52. if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
  53. end
  54. end
  55. end
  56. end
  57. end
  58. factory.qformspec =
  59. "size[8,8.5]"..
  60. factory_gui_bg..
  61. factory_gui_bg_img..
  62. factory_gui_slots..
  63. "list[current_name;main;0,0.3;8,3;]"..
  64. "list[current_player;main;0,4.25;8,1;]"..
  65. "list[current_player;main;0,5.5;8,3;8]"..
  66. factory.get_hotbar_bg(0,4.25)
  67. minetest.register_node("factory:queuedarm",{
  68. drawtype = "nodebox",
  69. tiles = {"factory_steel_noise.png"},
  70. paramtype = "light",
  71. description = "Queued Pneumatic Mover",
  72. groups = {cracky=3},
  73. paramtype2 = "facedir",
  74. legacy_facedir_simple = true,
  75. node_box = {
  76. type = "fixed",
  77. fixed = {
  78. {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
  79. {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
  80. {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
  81. {-0.375,-0.5,-0.1875,0.375,0.0625,0.0625}, --base3
  82. {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
  83. {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --nodebox6
  84. {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --nodebox7
  85. {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --nodebox8
  86. {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --nodebox9
  87. {-0.25,0.3125,-0.125,0.25,0.8,0.375}, --NodeBox10
  88. {-0.1875,0.1875,-0.5,-0.125,0.3125,0.375}, --NodeBox11
  89. {0.125,0.1875,-0.5,0.1875,0.3125,0.375}, --NodeBox12
  90. {-0.125,0.3125,-0.4375,0.125,0.5,-0.125}, --NodeBox13
  91. }
  92. },
  93. selection_box = {
  94. type = "fixed",
  95. fixed = {
  96. {-0.5,-0.5,-0.5,0.5,0.5,0.5},
  97. }
  98. },
  99. on_construct = function(pos)
  100. local meta = minetest.get_meta(pos)
  101. meta:set_string("formspec",factory.qformspec)
  102. meta:set_string("infotext", "Queued Pneumatic Mover")
  103. local inv = meta:get_inventory()
  104. inv:set_size("main", 8*3)
  105. end,
  106. can_dig = function(pos,player)
  107. local meta = minetest.get_meta(pos);
  108. local inv = meta:get_inventory()
  109. return inv:is_empty("main")
  110. end,
  111. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  112. minetest.log("action", player:get_player_name()..
  113. " moves stuff in queued mover at "..minetest.pos_to_string(pos))
  114. end,
  115. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  116. minetest.log("action", player:get_player_name()..
  117. " moves stuff to queued mover at "..minetest.pos_to_string(pos))
  118. end,
  119. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  120. minetest.log("action", player:get_player_name()..
  121. " takes stuff from queued mover at "..minetest.pos_to_string(pos))
  122. end,
  123. })
  124. minetest.register_abm({
  125. nodenames = {"factory:queuedarm"},
  126. neighbors = nil,
  127. interval = 1,
  128. chance = 1,
  129. action = function(pos, node, active_object_count, active_object_count_wider)
  130. local mmeta = minetest.env:get_meta(pos)
  131. local minv = mmeta:get_inventory()
  132. local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
  133. local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
  134. local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
  135. local target = minetest.get_node(b)
  136. for _,obj in ipairs(all_objects) do
  137. 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
  138. local stack = ItemStack(obj:get_luaentity().itemstring)
  139. qarm_handle(a, b, target, stack, minv, obj)
  140. end
  141. end
  142. for i,stack in ipairs(minv:get_list("main")) do
  143. if stack:get_name() ~= "" then
  144. minv:remove_item("main", stack)
  145. qarm_handle(a, b, target, stack, minv, nil)
  146. return
  147. end
  148. end
  149. end,
  150. })