Klazam33

KAPI

Mar 27th, 2013 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. function clear()
  2.  term.clear()
  3.  term.setCursorPos(1,1)
  4. end
  5.  
  6. function rawread(x)
  7.  while true do
  8.   local sEvent, param = os.pullEvent("key")
  9.   if sEvent == "key" then
  10.    if param == x then
  11.     break
  12.    end                                        
  13.   end
  14.  end
  15. end
  16.  
  17. function keyread()
  18.  while true do
  19.   local sEvent, param = os.pullEvent("key")
  20.   if sEvent == "key" then
  21.    return(param)
  22.   end
  23.    break
  24.   end
  25. end
  26.  
  27. function menu(text)
  28.  term.clear()
  29.  term.setCursorPos(1,1)
  30.  print(text)
  31. end
  32.  
  33. function printFuel()
  34.  local f = turtle.getFuelLevel()
  35. print("Current Fuel Level:" .. f)
  36. end
  37.  
  38. function mine(n) -- n is u, d, f
  39.  if n == "f" then
  40.   turtle.dig()
  41.  elseif n == "u" then
  42.   turtle.digUp()
  43.  elseif n == "d" then
  44.   turtle.digDown()
  45.  else
  46.   print("Not valid mine(dir)")
  47.  end
  48. end
  49.  
  50. function forward(n)
  51.  if n == nil then
  52.   n = 1
  53.  end
  54.  if n > 0 then
  55.   repeat
  56.    turtle.forward()
  57.    n = n - 1
  58.   until n == 0
  59.  else
  60.   print("n too low!")
  61.  end
  62. end
  63.  
  64. function turn(dir)
  65.  if dir == "l" then
  66.   turtle.turnLeft()
  67.  elseif dir == "r" then
  68.   turtle.turnRight()
  69.  elseif dir == "b" then
  70.   turtle.turnLeft()
  71.   turtle.turnLeft()
  72.  else
  73.   print("Not valid turn(dir)")
  74.  end
  75. end
  76.  
  77. function up(n)
  78.  if n == nil then
  79.    n = 1
  80.   end
  81.  if n > 0 then
  82.   repeat
  83.    turtle.up()
  84.    n = n - 1
  85.   until n == 0
  86.  else
  87.   print("n too low!")
  88.  end
  89. end
  90.  
  91. function down(n)
  92.  if n == nil then
  93.   n = 1
  94.  end
  95.  if n > 0 then
  96.   repeat
  97.    turtle.down()
  98.    n = n - 1
  99.   until n == 0
  100.  else
  101.   print("n too low!")
  102.  end
  103. end
  104.  
  105. function dump(n)
  106.  if turtle.detect() == true then
  107.   if n == nil then
  108.    i = 1
  109.   else
  110.    i = n
  111.   end
  112.   repeat
  113.    turtle.select(i)
  114.    turtle.drop()
  115.    i = i + 1
  116.    sleep(0)
  117.   until i == 17
  118.  else
  119.   print("Can't place inventory here!")
  120.  end
  121. end
  122.  
  123. function dumpUp(n)
  124.  if turtle.detectUp() == true then
  125.   if n == nil then
  126.    i = 1
  127.   else
  128.    i = n
  129.   end
  130.   repeat
  131.    turtle.select(i)
  132.    turtle.dropUp()
  133.    i = i + 1
  134.   until i == 17
  135.  else
  136.   print("Can't place inventory here!")
  137.  end
  138. end
  139.  
  140. function endDumpUp(n)
  141.  turtle.select(n)
  142.  mine("u")
  143.  turtle.select(3)
  144.  place("u")
  145.  if turtle.detectUp() == true then
  146.   if n == nil then
  147.    i = 1
  148.    n = 1
  149.   else
  150.    i = n
  151.   end
  152.   repeat
  153.    turtle.select(i)
  154.    turtle.dropUp()
  155.    i = i + 1
  156.   until i == 17 -- inventory has 16 slots
  157.  else
  158.   print("Can't place inventory here!")
  159.   rawread(keys.enter)
  160.  end
  161.  turtle.select(3)
  162.  mine("u")
  163. end
  164.  
  165. function chestDumpUp(n)
  166.  turtle.select(2)
  167.  mine("u")
  168.  turtle.select(1)
  169.  place("u")
  170.  if turtle.detectUp() == true then
  171.   if n == nil then
  172.    i = 1
  173.   else
  174.    i = n
  175.   end
  176.   repeat
  177.    turtle.select(i)
  178.    turtle.dropUp()
  179.    i = i + 1
  180.   until i == 17 -- inventory has 16 slots
  181.  else
  182.   print("Can't place inventory here!")
  183.   rawread(enter)
  184.  end
  185. end
  186.  
  187. function place(dir) -- dir is u, d, f
  188.  if dir == "f" then
  189.   turtle.place()
  190.  elseif dir == "u" then
  191.   turtle.placeUp()
  192.  elseif dir == "d" then
  193.   turtle.placeDown()
  194.  else
  195.   print("Not valid place(dir)")
  196.  end
  197. end
  198.  
  199. function chop()
  200. while turtle.detect() do
  201.  mine("f")
  202.  mine("u")
  203.  up()
  204. end
  205. while not turtle.detectDown() do
  206.  down()
  207. end
  208. end
Add Comment
Please, Sign In to add comment