Knito

compact3x3

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