TheKojent

OreCrafter

Dec 25th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. --Automatic crafting system. Used for crafting ore blocks.
  2.  
  3. local tableSlots = {1,2,3,5,6,7,9,10,11}
  4. local a = 1
  5.  
  6. local function craft(slot)
  7.     local b = turtle.getItemCount(slot)
  8.     local reps = (b - math.fmod(b,9)) / 9    --Figure out amount of blocks to create
  9.     if slot ~= 16 then    --Make sure the crafting materials are in slot 16
  10.         turtle.select(16)
  11.         turtle.dropDown()
  12.         turtle.select(slot)
  13.         turtle.transferTo(16)
  14.     end
  15.     for i = 1,16 do    --Set up the crafting grid
  16.         turtle.select(i)
  17.         turtle.dropDown()    --Clear the slots
  18.         if i == tableSlots[a] then         
  19.             turtle.select(16)
  20.             turtle.transferTo(tableSlots[a], reps)          --Transfer materials to the crafting slots
  21.             a = a + 1
  22.         end
  23.     end
  24.     turtle.select(1)
  25.     a = 1
  26.     if turtle.craft() then    --If it crafted, move to a chest in front
  27.         turtle.drop()
  28.     else                      --If not, empty grid
  29.         for i = 1,9 do
  30.             turtle.select(tableSlots[i])
  31.             turtle.drop()
  32.         end
  33.     end
  34.     for i = 1,16 do
  35.         turtle.suckDown()
  36.     end
  37. end
  38.  
  39. while true do
  40.     turtle.suckDown()
  41.     for j = 1,16 do
  42.         if turtle.getItemCount(j) >= 9 then
  43.             craft(j)
  44.             break
  45.         end
  46.     end
  47.     sleep(5)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment