Advertisement
hevohevo

ComputerCraft Tutorial: obsidian_generator_0_1

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