Advertisement
hevohevo

ComputerCraft Tutorial: obsidian_cobble_generator_0_2

Mar 3rd, 2014
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. -- #################################
  2. -- Obsidian/CobbleStone Generator with a Mining Turtle
  3. -- version 0.2
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- Install
  7. --  > pastebin get fSLALH2v obsigen
  8. -- First, Use command to build a facility
  9. --   The facility size is x=3, y=4, z=5.
  10. --  > obsigen build
  11. -- Already exists.
  12. --  > obsigen cobble
  13. --  > obsigen obsidian
  14.  
  15. -- config
  16. BLOCK = 13
  17. CHEST = 14
  18. WATER = 15
  19. FUEL = 16
  20. MIN_FUEL_LEVEL = 40
  21.  
  22. REDSTONE = 1
  23. LAVE = 2
  24. GET_BLOCK = 3
  25.  
  26. function placeLave()
  27.   turtle.select(LAVE)
  28.   turtle.place()
  29.   os.sleep(3)
  30.   turtle.place()
  31. end
  32.  
  33. function digBlock()
  34.   turtle.select(GET_BLOCK)
  35.   return turtle.digDown() and assert(turtle.dropUp())
  36. end
  37. function init()
  38.   digBlock()
  39. end
  40.  
  41. function placeRedstone()
  42.   turtle.select(REDSTONE)
  43.   turtle.placeDown()
  44. end
  45.  
  46. function waitForEnoughItems(itemName, n, slot)
  47.   turtle.select(slot)
  48.   while turtle.getItemCount(slot) < n do
  49.     if itemName then print(string.format("Insert %s into slot %d",itemName,slot)) end
  50.     os.sleep(1)
  51.     os.pullEvent("turtle_inventory")
  52.   end
  53. end
  54.  
  55. function waitForEnoughFuel(minLevel, slot)
  56.   local qty = 0
  57.   local refuel = function()
  58.     turtle.select(slot)
  59.     turtle.refuel()
  60.     qty = turtle.getFuelLevel()
  61.     print("fuel: ",qty)
  62.     return qty
  63.   end
  64.  
  65.   while refuel() < minLevel do
  66.     print(string.format("Insert fuel-items into slot %d: %d/%d", slot, qty, minLevel))
  67.     os.sleep(1)
  68.     os.pullEvent("turtle_inventory")
  69.   end
  70. end
  71.  
  72. -- functions to build
  73. function loop(n,func)
  74.   for i=1,n do func() end
  75. end
  76.  
  77. function placeDownForward()
  78.   turtle.placeDown()
  79.   turtle.forward()
  80. end
  81.  
  82. function build()
  83.   turtle.select(BLOCK)
  84.  
  85.   for y=1,3 do
  86.   turtle.up()
  87.     for i=1,2 do
  88.       turtle.forward()
  89.       loop(3, placeDownForward)
  90.       turtle.turnRight()
  91.       turtle.forward()
  92.       placeDownForward()
  93.       turtle.turnRight()
  94.     end
  95.   end
  96.  
  97.   turtle.turnRight()
  98.   turtle.forward()
  99.   turtle.turnLeft()
  100.   loop(2, turtle.forward)
  101.   loop(3, turtle.down)
  102.   turtle.place()
  103.   turtle.up()
  104.   turtle.placeDown()
  105.   turtle.up()
  106. end
  107.  
  108. function build2()
  109.   loop(2,turtle.turnRight)
  110.   turtle.select(WATER)
  111.   turtle.place()
  112.   loop(2,turtle.turnRight)
  113.   turtle.select(CHEST)
  114.   turtle.placeUp()
  115. end
  116.  
  117. function build3()
  118.   turtle.select(GET_BLOCK)
  119.   turtle.turnRight()
  120.   turtle.dig()
  121.   loop(2, turtle.turnRight)
  122.   turtle.dig()
  123.   turtle.turnRight()
  124.   turtle.dropUp()
  125. end
  126.  
  127. -- main
  128. local mode = false
  129. local args = {...}
  130. if args and args[1] == 'build' then
  131.   mode = 'build'
  132.   waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL)
  133.   waitForEnoughItems("26 Blocks", 26, BLOCK)
  134.   waitForEnoughItems("a Chest", 1, CHEST)
  135.   waitForEnoughItems("a Water-Bucket", 1, WATER)
  136.  
  137.   print("Building Start!")
  138.   build()
  139.   build2()
  140.   build3()
  141.   print("Building Finished!")
  142.  
  143. elseif args and args[1] == 'obsidian' then
  144.   mode = 'obsidian'
  145.   waitForEnoughItems("some Redstone(s)", 1, REDSTONE)
  146.   waitForEnoughItems("a Lave-Bucket", 1, LAVE)
  147.   init()
  148.   local numRs = turtle.getItemCount(REDSTONE)
  149.   print("I try to craft ",numRs," obsidian(s).")
  150.  
  151.   for i=1, numRs do
  152.     placeRedstone()
  153.     placeLave()
  154.     if digBlock() then print(i) end
  155.   end
  156.  
  157. elseif args and args[1] == 'cobble' then
  158.   waitForEnoughItems("a Lave-Bucket", 1, LAVE)
  159.   init()
  160.   turtle.select(LAVE)
  161.   turtle.place()
  162.   local num = 0
  163.   while true do
  164.     if digBlock() then
  165.       num = num + 1
  166.     end
  167.     print(num)
  168.     os.sleep(1)
  169.   end
  170. else
  171.   print("Need an argument:")
  172.   print("> obsigen <build | cobble| obsidian>")
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement