Advertisement
Twigister

ForAbby/Twig Amazon

Aug 15th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local function turn_around()
  2.     turtle.turnRight()
  3.     turtle.turnRight()
  4. end
  5.  
  6. local function wait_command()
  7.     local senderID, command = O, {}
  8.     senderID, command = rednet.receive()
  9.     return senderID, command
  10. end
  11.  
  12. local function go_to_chest()
  13.     local bool = true
  14.     local info = {}
  15.  
  16.     turtle.turnRight()
  17.     bool, info = turtle.inspectDown()
  18.     while info.state.color~="purple" do
  19.         turtle.forward()
  20.         bool, info = turtle.inspectDown()
  21.     end
  22. end
  23.  
  24. local function sort_inv()
  25.     local base_item = {}
  26.     local compared_item = {}
  27.     local i = 1
  28.  
  29.     turtle.select(1)
  30.     base_item = turtle.getItemDetail()
  31.     while i <= 16 do
  32.         compared_item = turtle.getItemDetail(i)
  33.         if compared_item and compared_item.name == base_item.name then
  34.             turtle.transferTo(i)
  35.         end
  36.         i = i + 1
  37.     end
  38. end
  39.  
  40. local function test_chest()
  41.     local base_count
  42.     local final_count
  43.     local bool
  44.     local i = 0
  45.     local number
  46.  
  47.     turtle.turnLeft()
  48.     turtle.select(1)
  49.     base_count = turtle.getItemCount()
  50.     while turtle.suck() do end
  51.     turtle.select(16)
  52.     if turtle.getItemCount()~=0 then
  53.         sort_inv()
  54.         i = 16
  55.         while i>1 do
  56.             turtle.select(i)
  57.             turtle.drop()
  58.             i = i - 1
  59.         end
  60.     else
  61.         i = 15
  62.         while i>0 do
  63.             turtle.select(i)
  64.             turtle.drop()
  65.             i = i - 1
  66.         end
  67.     end
  68.     turtle.select(1)
  69.     final_count = turtle.getItemCount()
  70.     if final_count~=base_count then
  71.         bool = true
  72.     else
  73.         bool = false
  74.     end
  75.     number = base_count - final_count      
  76.     return bool, number
  77. end
  78.  
  79. local function put_in_place()
  80.     local x, y, z = 1, 0, 1
  81.  
  82.     go_home()
  83. end
  84.  
  85. local function get_in_place()
  86.  
  87. end
  88.  
  89. local function go_home()
  90.     local bool = true
  91.     local info = {}
  92.  
  93.     turn_around()
  94.     bool, info = turtle.inspectDown()
  95.     while info.state.color~="lime" do
  96.         turtle.forward()
  97.         bool, info = turtle.inspectDown()
  98.     end
  99.     turtle.turnRight()
  100. end
  101.  
  102. local function seek()
  103.     local res_table = {}
  104.  
  105.     go_to_chest()
  106.     if turtle.suck() then
  107.         write(OMG)
  108.         put_in_place()
  109.         get_in_place()
  110.         seek()
  111.     else
  112.         go_home()
  113.     end
  114. end
  115.  
  116. local function interpret(senderID, command)
  117.     if command[1]=="seek" then
  118.         seek()
  119.     else if command[1]=="find" then
  120.         write("WIP\n")
  121.         rednet.send(senderID, "Error: Not yet implemented")
  122.     else
  123.         write(senderID.." sent something unknown !\n")
  124.         rednet.send(senderID, "Error: Command not found")
  125.     end
  126.     end
  127. end
  128.  
  129. local function main()
  130.     local command
  131.     local senderID
  132.  
  133.     while true do
  134.         senderID, command = wait_command()
  135.         interpret(senderID, command)
  136.     end
  137. end
  138.  
  139. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement