Knito

craftpickaxes.lua

Jun 10th, 2019
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- craftpickaxes
  2. -- by Konitor 2019 - 06 - 09
  3. -- pastebin get nhsYX824 craftpickaxes
  4.  
  5. -- setup: left chest = sticks
  6. --        right chest = cobble
  7. --        front = dropper, hopper (output which must be empty)
  8. --        down = Error DropOff Chest
  9.  
  10. -- First check if the dropper is full.
  11. -- If the turtle sucks anything in from
  12. -- there, then drop it back and wait.
  13.  
  14.  
  15. crafted = 0
  16. docraft = true
  17. sleeptime = 2
  18.  
  19. --Auto Label
  20.  
  21. if os.getComputerLabel() == nil then
  22.   os.setComputerLabel("Nameless Stonepickaxe Crafter")
  23. end
  24.  
  25. -- Check to see if I'm alright and ready for crafting
  26.  
  27. bCrafting = (peripheral.getType("left") == "workbench") or (peripheral.getType("right") == "workbench")
  28. if not bCrafting then
  29.   error("No Crafting Table Equipped")
  30. end
  31.  
  32. -- Copy this code to startup
  33. -- Delete existing startup to avoid error
  34.  
  35. me = fs.getName( shell.getRunningProgram() )
  36. print( "Running program = "..me )
  37. if( me ~=  "startup") then
  38.     if( fs.exists("startup") ) then
  39.         fs.delete("startup")
  40.     end
  41.     fs.copy( me, "startup" )
  42. end
  43. sleep( 3 ) -- looking blankly at info, yeah!
  44.  
  45. -- clear inventory to dropoff chest
  46.  
  47. for i = 1, 16 do
  48.     turtle.select(i)
  49.     turtle.dropDown()
  50. end
  51.  
  52.  
  53. while true do
  54.  
  55. sleeping = 0
  56.  
  57. while turtle.suck(1) do
  58.   turtle.drop()
  59.   sleep(sleeptime)
  60.   -- print("Waiting for Queue to be empty...")
  61.   sleeping = sleeping + sleeptime
  62.   print("Wait: "..sleeping.." secs / crafted: "..crafted.." picks")
  63. end
  64.  
  65. -- select cobble chest
  66.  
  67. turtle.turnRight()
  68.  
  69. -- 1st cobble
  70.  
  71. if( turtle.getItemCount(1) == 0 ) then
  72.   turtle.select(1)
  73.   if not turtle.suck(1) then docraft = false end
  74. end
  75.  
  76. -- 2nd cobble  
  77. if( turtle.getItemCount(2) == 0 ) then
  78.   turtle.select(2)
  79.   if not turtle.suck(1) then docraft = false end
  80. end
  81.  
  82. -- 3rd cobble
  83. if( turtle.getItemCount(3) == 0 ) then
  84.   turtle.select(3)
  85.   if not turtle.suck(1) then docraft = false end
  86. end
  87.  
  88.  
  89. if docraft == false then
  90.     -- facing dropper again
  91.     turtle.turnLeft()
  92.     -- exit program
  93.     error("No more cobble after "..crafted.." picks.")
  94. end
  95.  
  96.  
  97. -- select sticks chest
  98.  
  99. turtle.turnLeft()
  100. turtle.turnLeft()
  101.  
  102. if( turtle.getItemCount(6) == 0 ) then
  103.   turtle.select(6)
  104.   if not turtle.suck(1) then docraft = false end
  105. end
  106. if( turtle.getItemCount(10) == 0 ) then
  107.   turtle.select(10)
  108.   if not turtle.suck(1) then docraft = false end
  109. end
  110.  
  111. if docraft == false then
  112.     -- facing dropper again
  113.     turtle.turnRight()
  114.     -- exit program
  115.     error("No more sticks after "..crafted.." picks.")
  116. end
  117.  
  118. -- facing dropper again
  119.  
  120. turtle.turnRight()
  121.  
  122. if turtle.craft() then
  123. --    print("Crafting...")
  124.     turtle.drop()
  125.     crafted = crafted + 1
  126.     print( "crafted "..crafted.." pickaxes" )
  127. else
  128.     error("Crafting failed after crafting "..crafted.." picks.")
  129.    
  130. end
  131.  
  132.  
  133. end
RAW Paste Data