QuicksilverBoy

turtle.lua

Oct 17th, 2021
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --v 0.3
  2. rednet.open("right")
  3.  
  4. function dropAll()
  5.     for i = 1, 16 do
  6.         turtle.select(i)
  7.         turtle.dropUp()
  8.     end
  9. end
  10.  
  11. function craft(t, count)
  12.     assert(#t == 9, "error recept")
  13.     local i = 1
  14.     local craftSlot = {
  15.         [1] = 1, [2] = 2, [3] = 3,
  16.         [4] = 5, [5] = 6, [6] = 7,
  17.         [7] = 9, [8] = 10, [9] = 11
  18.     }
  19.     turtle.select(4)
  20.     while turtle.suckUp() do
  21.         local item = turtle.getItemDetail()
  22.         for i = 1, 9 do
  23.             if item.name == t[i] then
  24.                 turtle.transferTo(craftSlot[i], count)
  25.             end
  26.         end
  27.     end
  28.    
  29.     turtle.craft()
  30.     dropAll()
  31. end
  32.  
  33. function read()
  34.     local craftSlot = {
  35.         [1] = 1, [2] = 2, [3] = 3,
  36.         [4] = 5, [5] = 6, [6] = 7,
  37.         [7] = 9, [8] = 10, [9] = 11
  38.     }
  39.     local slots = {}
  40.     for i, numSlot in pairs(craftSlot) do
  41.         turtle.select(numSlot)
  42.         local item = turtle.getItemDetail()
  43.         if item then
  44.             table.insert(slots, item.name)
  45.         else
  46.             table.insert(slots, "air")
  47.         end
  48.     end
  49.     return slots
  50. end
  51.  
  52. while true do
  53.     local id, recept = rednet.receive()
  54.     if type(recept) == "table" and recept.type == "crafting" then
  55.         craft(recept.slots, recept.count or 1)
  56.     elseif recept == "read" then
  57.         local bench = read()
  58.         --try to craft
  59.         turtle.select(4)
  60.         if turtle.craft() then
  61.             local anItem = turtle.getItemDetail()
  62.             rednet.send(id, {craft = bench, result=anItem.name})
  63.         else
  64.             rednet.send(id, false)
  65.         end
  66.     end
  67. end
  68.  
Add Comment
Please, Sign In to add comment