Advertisement
m3Zz

Enclosed Staircase Builder

Mar 3rd, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. function clear()
  2.  term.clear()
  3.  term.setCursorPos(1,1)
  4. end
  5.  
  6. function nofuel()
  7.  clear()
  8.  for i=1,x-1 do
  9.   write("-")
  10.  end
  11.  print("Please insert some fuel first!")
  12.  print("Make sure to put in enough for the task.")
  13.  print("")
  14.  print("Returning...")
  15.  for i=1,x-1 do
  16.   write("-")
  17.  end
  18.  sleep(1)
  19.  start()
  20. end
  21.  
  22. function checkfuel()
  23.  if turtle.getFuelLevel() < 5 then
  24.   return true
  25.  else
  26.   return false
  27.  end
  28. end
  29.  
  30. function refuel(quantity)
  31.  fuelpre = turtle.getFuelLevel()
  32.  for i4=0,13 do
  33.   turtle.select(16-i4)
  34.   if turtle.refuel(quantity) then
  35.    break
  36.   else
  37.    if 16-i4==3 then
  38.     fuelpost = turtle.getFuelLevel()
  39.     turtle.select(1)
  40.     if fuelpre == fuelpost then
  41.      nofuel()
  42.     end
  43.    end
  44.   end
  45.  end
  46.  turtle.select(tmp)
  47. end
  48.  
  49. function findcobble()
  50.  for i1 = 3,16 do
  51.   turtle.select(i1)
  52.   if turtle.compareTo(1) then
  53.    tmp = i1
  54.    break
  55.   end
  56.  end
  57. end
  58.  
  59. function findstairs()
  60.  for i3 = 3,16 do
  61.   turtle.select(i3)
  62.   if turtle.compareTo(2) then
  63.    tmp = i3
  64.    break
  65.   end
  66.  end
  67. end
  68.  
  69. function dig()
  70.  turtle.select(1)
  71.  if not turtle.compare() then
  72.   turtle.dig()
  73.  end
  74.  turtle.digUp()
  75.  turtle.select(tmp)
  76. end
  77.  
  78. function buildwallsegment()
  79.  findcobble()
  80.  for i2 = 1,3 do
  81.   output()
  82.   if checkfuel() then
  83.    refuel(1)
  84.   end
  85.   dig()
  86.   turtle.place()
  87.   turtle.turnRight()
  88.   dig()
  89.   if i2 < 3 then
  90.    turtle.forward()
  91.    turtle.turnLeft()
  92.   end
  93.  end
  94. end
  95.  
  96. function buildfullsegment()
  97.  for i5 = 1,4 do
  98.   buildwallsegment()
  99.  end
  100. end
  101.  
  102. function placestairs()
  103.  if checkfuel() then
  104.   refuel(1)
  105.  end
  106.  findcobble()
  107.  turtle.forward()
  108.  output()
  109.  turtle.place()
  110.  findstairs()
  111.  turtle.back()
  112.  output()
  113.  turtle.place()
  114.  turtle.up()
  115.  output()
  116.  turtle.forward()
  117.  output()
  118.  turtle.place()
  119.  turtle.up()
  120.  output()
  121.  turtle.forward()
  122.  output()
  123. end
  124.  
  125. function staircase()
  126.  buildfullsegment()
  127.  turtle.up()
  128.  output()
  129.  buildfullsegment()
  130.  turtle.down()
  131.  output()
  132.  turtle.turnRight()
  133.  placestairs()
  134. end
  135.  
  136. function confirm()
  137.  clear()
  138.  x,y=term.getSize()
  139.  for i=1,x-1 do
  140.   write("-")
  141.  end
  142.  print("Stairs v0.1a by m3Zz")
  143.  print("")
  144.  print("Alright, building a "..(height*2).." blocks high staircase!")
  145.  for i=1,x-1 do
  146.   write("-")
  147.  end
  148.  sleep(1)
  149. end
  150.  
  151. function getinfo()
  152.  clear()
  153.  x,y=term.getSize()
  154.  for i=1,x-1 do
  155.   write("-")
  156.  end
  157.  print("Stairs v0.1a by m3Zz")
  158.  print("")
  159.  print("How high shall the staircase be?")
  160.  for i=1,x-1 do
  161.   write("-")
  162.  end
  163.  print("")
  164.  height=read()
  165.  confirm()
  166. end
  167.  
  168. function output()
  169.  clear()
  170.  x,y=term.getSize()
  171.  for i=1,x-1 do
  172.   write("-")
  173.  end
  174.  print("Stairs v0.1a by m3Zz")
  175.  print("")
  176.  print("Fuel Level: "..turtle.getFuelLevel())
  177.  print("Building...")
  178.  for i=1,x-1 do
  179.   write("-")
  180.  end
  181. end
  182.  
  183. function setup()
  184.  clear()
  185.  getinfo()
  186. end
  187.  
  188. function main()
  189.  clear()
  190.  output()
  191.  for i = 1,height do
  192.   staircase()
  193.  end
  194.  start()
  195. end
  196.  
  197. function start()
  198.  setup()
  199.  main()
  200. end
  201.  
  202. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement