LivioBrunner

myTurtleAPI

Aug 25th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. k = 1
  2. allitems = 0
  3. turtle.select(1)
  4. function tclear(x,y)
  5.     if x == nil then
  6.         x = 1
  7.     end
  8.     if y == nil then
  9.         y = 1
  10.     end
  11.     term.clear()
  12.     term.setCursorPos(x,y)
  13. end
  14. function load(name)
  15.     local file = fs.open(name,"r")
  16.     local data = file.readAll()
  17.     file.close()
  18.     return textutils.unserialize(data)
  19. end
  20. function save(table,name)
  21.     local file = fs.open(name,"w")
  22.     file.write(textutils.serialize(table))
  23.     file.close()
  24. end
  25. function useFuel(slotnum)
  26.   turtle.select(slotnum)
  27.   turtle.refuel(1)
  28. end
  29. function items()
  30.   for i = 1, 16 do
  31.     actitem = turtle.getItemCount(i)
  32.     allitems = allitems + actitem
  33.   end
  34.   return allitems
  35. end
  36. function refuel()
  37.   for i = 1,16 do
  38.   if turtle.getItemCount(i) > 0 then
  39.     for j = 1,turtle.getItemCount(i) do
  40.       useFuel(i)
  41.     end
  42.   end
  43.   end
  44. end
  45. function setforward()
  46.   if turtle.getItemCount(k) == 0 then
  47.    while turtle.getItemCount(k) == 0 do
  48.       k = k + 1
  49.       if k > 16 and items() > 0 then
  50.         k = 1
  51.       end
  52.       turtle.select(k)
  53.     end
  54.   end
  55.    if turtle.placeDown() == false then
  56.          turtle.digDown()
  57.          turtle.placeDown()
  58.   end
  59.   if turtle.forward() == false then
  60.       while turtle.forward() == false do
  61.          turtle.dig()
  62.       end
  63.   end
  64. end
  65. function mineforward()
  66.   if turtle.forward() == false then
  67.       while turtle.forward() == false do
  68.          turtle.dig()
  69.       end
  70.   end
  71. end
  72. function turnright()
  73.   turtle.turnRight()
  74.   turtle.dig()
  75.   mineforward()
  76.   turtle.turnRight()
  77. end
  78. function turnleft()
  79.   turtle.turnLeft()
  80.   turtle.dig()
  81.   mineforward()
  82.   turtle.turnLeft()
  83. end
  84.  
  85. function mineCube(high, width, length)
  86. high = tonumber(high)
  87. width = tonumber(width)
  88. length =tonumber(length)
  89. l = 0
  90.   for i = 1, high do
  91.     for j = 1, width do
  92.       for k = 1, length do
  93.         turtle.dig()
  94.         mineforward()
  95.       end
  96.       if j < width then
  97.       l = l + 1
  98.       if l < 2 then
  99.         turnright()
  100.       else
  101.         turnleft()
  102.       l = 0
  103.       end
  104.       end
  105.     end
  106.     turtle.digUp()
  107.     turtle.up()
  108.     turtle.turnLeft()
  109.     turtle.turnLeft()
  110.   end
  111. end
  112. function setCube(high, width, length)
  113. tonumber(high)
  114. tonumber(width)
  115. tonumber(length)
  116. l = 0
  117. turtle.up()
  118.   for i = 1, high do
  119.     for j = 1, width do
  120.       for k = 1, length do
  121.         setforward()
  122.       end
  123.       if j < width then
  124.       l = l + 1
  125.       if l < 2 then
  126.         turtle.turnRight()
  127.         mineforward()
  128.         turtle.turnRight()
  129.         mineforward()
  130.       else
  131.         turtle.turnLeft()
  132.         mineforward()
  133.         turtle.turnLeft()
  134.         mineforward()
  135.  
  136.       l = 0
  137.       end
  138.       end
  139.     end
  140.     turtle.up()
  141.     turtle.turnLeft()
  142.     turtle.turnLeft()
  143.     turtle.forward()
  144.   end
  145. end
  146. turtle.select(1)
Advertisement
Add Comment
Please, Sign In to add comment