Knito

craftring

Oct 26th, 2019
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- craftring
  2. -- by Konitor 2019-09-27 from compact3x3
  3. -- minecraft computercraft turtle program
  4. -- used for: heavenparadiseplantmod
  5. --
  6. -- pastebin get wYfQkkU0 craftring
  7.  
  8. -- setup: front chest = input
  9. --        down chest = output and dropoff chest for cleanup
  10. --
  11. --        Example environment for "Gobber globettes to globs":
  12. --        The mod "Simple Storage Network" does export globettes to
  13. --        the front chest and import everything from the down chest.
  14. --        When there are globettes in the down chest they get
  15. --        exported again to the front chest. So no problem to clean the
  16. --        crafting area to the down chest on startup after an error
  17. --        has occured.
  18. --
  19. --        sustaining: can get stopped anytime and will startup safely
  20. --        after world reload, chunk reload, game crash etc.
  21. --        will sit and do nothing on error condition but tell you.
  22. --        Only error atm: I'm not a crafty turtle! That's a show stopper.
  23.  
  24. -- Program overview:
  25.  
  26. -- First check if the turtle is a crafty turtle.
  27. -- Then check for a label and label it when it has none.
  28. -- Then copy this program to "startup" for self sustain.
  29. -- Then start by cleaning up the internal buffer to the down chest.
  30.  
  31. -- Main loop:
  32. -- Get 8 same items from front chest
  33. -- Craft
  34. -- Drop to down chest
  35. -- Wait a little
  36. -- Do it again.
  37.  
  38. -- crafted how many items so far?
  39. crafted = 0
  40.  
  41. -- Check to see if I'm alright and ready for crafting
  42.  
  43. bCrafting = (peripheral.getType("left") == "workbench") or (peripheral.getType("right") == "workbench")
  44. if not bCrafting then
  45.   error("I want to be a crafty turtle! Craft me together with a crafting table.")
  46. end
  47.  
  48. --Auto Label
  49.  
  50. if os.getComputerLabel() == nil then
  51.   os.setComputerLabel("RingCrafter")
  52. end
  53.  
  54. -- copy this program to startup when its not "startup"
  55.  
  56. me = fs.getName( shell.getRunningProgram() )
  57.  
  58. if( me ~=  "startup") then
  59.     print( "Overwriting startup with "..me )
  60.     if( fs.exists("startup") ) then
  61.         fs.delete("startup")
  62.     end
  63.     fs.copy( me, "startup" )
  64. end
  65.  
  66. print( "Front chest = input" )
  67. print( "Down chest = output" )
  68.  
  69. sleep( 3 ) -- looking blankly at info, yeah!
  70.  
  71. -- cleaning up the crafting buffer after restart
  72. -- clear inventory to dropoff chest
  73.  
  74. for i = 1, 16 do
  75.     turtle.select(i)
  76.     turtle.dropDown()
  77. end
  78.  
  79.  
  80. -- Main loop
  81.  
  82. while true do
  83.  
  84.     -- fill up the crafting area
  85.     -- this can take more than one loop
  86.     -- break when docraft == false and
  87.     -- wait 3 secs for another attempt
  88.     -- to complete the rest of the 3x3 area
  89.    
  90.     -- craft only when docraft still true
  91.  
  92.     docraft = true
  93.    
  94.     -- 1st row of 3x3 grid
  95.  
  96.     if( turtle.getItemCount(1) == 0 ) then
  97.       turtle.select(1)
  98.       if not turtle.suck(1) then docraft = false end
  99.     end
  100.  
  101.     if( turtle.getItemCount(2) == 0 ) then
  102.       turtle.select(2)
  103.       if not turtle.suck(1) then docraft = false end
  104.     end
  105.  
  106.     if( turtle.getItemCount(3) == 0 ) then
  107.       turtle.select(3)
  108.       if not turtle.suck(1) then docraft = false end
  109.     end
  110.    
  111.     -- 2nd row of 3x3 grid
  112.    
  113.     if( turtle.getItemCount(5) == 0 ) then
  114.       turtle.select(5)
  115.       if not turtle.suck(1) then docraft = false end
  116.     end
  117.  
  118. --[[
  119.  
  120.     if( turtle.getItemCount(6) == 0 ) then
  121.       turtle.select(6)
  122.       if not turtle.suck(1) then docraft = false end
  123.     end
  124.   ]]   
  125.  
  126.     if( turtle.getItemCount(7) == 0 ) then
  127.       turtle.select(7)
  128.       if not turtle.suck(1) then docraft = false end
  129.     end
  130.    
  131.     -- 3th row of 3x3 grid
  132.    
  133.     if( turtle.getItemCount(9) == 0 ) then
  134.       turtle.select(9)
  135.       if not turtle.suck(1) then docraft = false end
  136.     end
  137.  
  138.     if( turtle.getItemCount(10) == 0 ) then
  139.       turtle.select(10)
  140.       if not turtle.suck(1) then docraft = false end
  141.     end
  142.  
  143.     if( turtle.getItemCount(11) == 0 ) then
  144.       turtle.select(11)
  145.       if not turtle.suck(1) then docraft = false end
  146.     end
  147.  
  148.     if docraft == true then
  149.    
  150.         -- just enough items
  151.    
  152.         if turtle.craft() then
  153.  
  154.             turtle.dropDown()
  155.             crafted = crafted + 1
  156.             print( "crafted "..crafted.." items" )
  157.            
  158.             -- give the system a break, don't harm fps
  159.            
  160.             sleep( 1 )
  161.            
  162.         else
  163.  
  164.             print ("Crafting failed after crafting "..crafted.." items.")
  165.            
  166.             -- cleaning up the crafting buffer after error
  167.             -- clear inventory to dropoff chest
  168.  
  169.             for i = 1, 16 do
  170.                 turtle.select(i)
  171.                 turtle.dropDown()
  172.             end
  173.            
  174.             sleep( 3 )
  175.            
  176.         end
  177.        
  178.     else
  179.    
  180.         -- not enough items
  181.         -- wait for items, don't insist too much, don't harm fps
  182.        
  183.         sleep( 3 )
  184.        
  185.     end
  186.  
  187.    
  188. end
RAW Paste Data