Advertisement
Inlife

crafter-dustseeds.lua

Apr 15th, 2024
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local CRAFT_BATCH_SIZE = 16;
  2. local CRAFT_SLEEP_WAIT = 2;
  3.  
  4. local craftTable = {
  5.     {"f", "t", 0, 0},
  6.     {0, 0, 0, 0},
  7.     {0, 0, 0, 0},
  8.     {0, 0, 0, 0}
  9. }
  10.  
  11. function cleanUpInventory()
  12.     print("[cr] cleaning up the inventory")
  13.     for i=1,16 do
  14.         turtle.select(i)
  15.         turtle.dropDown()
  16.     end
  17. end
  18.  
  19. function loadIngridient(slot, direction)
  20.     if direction == 0 then
  21.         return
  22.     end
  23.  
  24.     print("[cr] loading item to slot " .. slot)
  25.     turtle.select(slot)
  26.  
  27.     local res
  28.     local count = turtle.getItemCount()
  29.  
  30.     if direction == "t" then
  31.         res = turtle.suckUp(CRAFT_BATCH_SIZE - count)
  32.     elseif direction == "b" then
  33.         res = turtle.suckDown(CRAFT_BATCH_SIZE - count)
  34.     elseif direction == "f" then
  35.         res = turtle.suck(CRAFT_BATCH_SIZE - count)
  36.     end
  37.  
  38.     if not res then
  39.         print("[cr] could not get items to the slot, waiting and trying again...")
  40.         sleep(CRAFT_SLEEP_WAIT)
  41.         return loadIngridient(slot, direction)
  42.     end
  43.  
  44.     if turtle.getItemCount() < CRAFT_BATCH_SIZE then
  45.         print("[cr] loaded less items then expected, waiting to try fill up fully...")
  46.         sleep(CRAFT_SLEEP_WAIT)
  47.         return loadIngridient(slot, direction)
  48.     end
  49. end
  50.  
  51. function iterate()
  52.     print("[cr] getting ingredients")
  53.     for i,row in ipairs(craftTable) do
  54.         for j,col in ipairs(row) do
  55.             print("[cr] loading into slot " .. j .. ';' .. i);
  56.             loadIngridient(i*4+j, col)
  57.         end
  58.     end
  59.  
  60.     print("[cr] crafting")
  61.     turtle.select(1)
  62.     turtle.craft()
  63.  
  64.     print("[cr] pooping out results ...")
  65.     while turtle.getItemCount() > 0 do
  66.         sleep(CRAFT_SLEEP_WAIT)
  67.     end
  68. end
  69.  
  70. function main()
  71.     print("\n\n-------------------------------")
  72.     print("[cr] starting the program; v1.0")
  73.     print("-------------------------------\n\n");
  74.     cleanUpInventory()
  75.  
  76.     while true do
  77.         iterate()
  78.     end
  79. end
  80.  
  81. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement