arm.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. minetest.register_node("factory:arm",{
  2. drawtype = "nodebox",
  3. tiles = {"factory_steel_noise.png"},
  4. paramtype = "light",
  5. description = "Pneumatic Mover",
  6. groups = {cracky=3},
  7. paramtype2 = "facedir",
  8. legacy_facedir_simple = true,
  9. node_box = {
  10. type = "fixed",
  11. fixed = {
  12. {-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
  13. {-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
  14. {-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
  15. {-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
  16. {-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
  17. {-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
  18. {-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
  19. {0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
  20. {-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
  21. }
  22. },
  23. selection_box = {
  24. type = "fixed",
  25. fixed = {
  26. {-0.5,-0.5,-0.5,0.5,0.5,0.5},
  27. }
  28. },
  29. })
  30. minetest.register_abm({
  31. nodenames = {"factory:arm"},
  32. neighbors = nil,
  33. interval = 1,
  34. chance = 1,
  35. action = function(pos, node, active_object_count, active_object_count_wider)
  36. local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
  37. local _,obj
  38. for _,obj in ipairs(all_objects) do
  39. 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
  40. local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
  41. local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
  42. local target = minetest.get_node(b)
  43. local stack = ItemStack(obj:get_luaentity().itemstring)
  44. if target.name == "default:chest" or target.name == "default:chest_locked" then
  45. local meta = minetest.env:get_meta(b)
  46. local inv = meta:get_inventory()
  47. if inv:room_for_item("main", stack) then
  48. inv:add_item("main", stack)
  49. obj:remove()
  50. else
  51. obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
  52. end
  53. end
  54. if target.name == "factory:swapper" then
  55. local meta = minetest.env:get_meta(b)
  56. local inv = meta:get_inventory()
  57. if inv:room_for_item("input", stack) then
  58. inv:add_item("input", stack)
  59. obj:remove()
  60. else
  61. obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z}, false)
  62. end
  63. end
  64. for i,v in ipairs(armDevicesFurnacelike) do
  65. if target.name == v then
  66. local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
  67. local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
  68. local meta = minetest.env:get_meta(b)
  69. local inv = meta:get_inventory()
  70. if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
  71. -- back, fuel
  72. if inv:room_for_item("fuel", stack) then
  73. inv:add_item("fuel", stack)
  74. obj:remove()
  75. else
  76. obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
  77. end
  78. else
  79. -- everytin else, src
  80. if inv:room_for_item("src", stack) then
  81. inv:add_item("src", stack)
  82. obj:remove()
  83. else
  84. obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
  85. end
  86. end
  87. end
  88. end
  89. end
  90. end
  91. end,
  92. })