Knito

craftlumberaxes.lua

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