Advertisement
hevohevo

rasen

Apr 4th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1. STAIR = 1
  2. SLAB = 2
  3. FUEL = 16
  4.  
  5. N = 3
  6.  
  7. function wait_for_enough_fuel(minLevel, slot)
  8.   local qty = 0
  9.   local refuel = function()
  10.     turtle.select(slot)
  11.     turtle.refuel()
  12.     qty = turtle.getFuelLevel()
  13.     print("fuel: ",qty)
  14.     return qty
  15.   end
  16.  
  17.   while refuel() < minLevel do
  18.     print(string.format("Insert fuel-items into slot %d: %d/%d", slot, qty, minLevel))
  19.     os.sleep(1)
  20.     os.pullEvent("turtle_inventory")
  21.   end
  22. end
  23.  
  24. function set_block(slot, direction)
  25.   turtle.select(slot)
  26.   if direction==nil then
  27.   turtle.place()
  28.   elseif direction=="bottom" then
  29.     turtle.placeDown()
  30.   elseif direction=="top" then
  31.     turtle.placeUp()
  32.   end
  33. end
  34.  
  35. function slide(direction, n)
  36.   if direction == "left" then
  37.     turtle.turnLeft()
  38.     turtle.forward()
  39.     turtle.turnRight()
  40.   elseif direction=="right" then
  41.     turtle.turnRight()
  42.     turtle.forward()
  43.     turtle.turnLeft()
  44.   end
  45. end
  46.  
  47. function stair3()
  48.     turtle.forward()
  49.     if not turtle.detectDown() then set_block(SLAB, "bottom") end
  50.     turtle.back()
  51.     set_block(STAIR)
  52.     slide("left")
  53.     turtle.forward()
  54.     if not turtle.detectDown() then set_block(SLAB, "bottom") end
  55.     turtle.back()
  56.     set_block(STAIR)
  57.     slide("left")
  58.     turtle.forward()
  59.     if not turtle.detectDown() then set_block(SLAB, "bottom") end
  60.     turtle.back()
  61.     set_block(STAIR)
  62. end
  63. -- main
  64. local args = {...}
  65. if args and args[1] then N = tonumber(args[1]) end
  66.  
  67. wait_for_enough_fuel(100, FUEL)
  68.  
  69. for i=1,N do
  70. stair3()
  71. turtle.up()
  72. turtle.forward()
  73. turtle.forward()
  74. set_block(SLAB, "bottom")
  75. set_block(SLAB, "bottom")
  76. slide("right")
  77. set_block(SLAB)
  78. turtle.turnRight()
  79. turtle.forward()
  80. set_block(SLAB,"bottom")
  81. set_block(SLAB,"bottom")
  82. turtle.back()
  83. set_block(STAIR)
  84. turtle.turnLeft()
  85. set_block(SLAB,"bottom")
  86. set_block(SLAB,"bottom")
  87. turtle.back()
  88. slide("right")
  89. turtle.up()
  90. turtle.forward()
  91. turtle.forward()
  92. turtle.turnRight()
  93. set_block(SLAB, "bottom")
  94. slide("left")
  95. set_block(SLAB, "bottom")
  96. slide("right")
  97. slide("right")
  98. end
  99.  
  100. --[[
  101. while true do
  102. local text = read()
  103. if text == "exit()" then break end
  104. local func = loadstring(text)
  105. setfenv(func, getfenv()) -- change func's environment(_G) to current one.
  106. local results = {pcall(func)} -- table: 1) exist_status, 2) run_status, 3) err_msg
  107. end
  108. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement