AxxiD

CC - Eltrut API - Fixxed by AxxiD

Oct 25th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.45 KB | None | 0 0
  1. --ELTRUT 0.1.0
  2. --Fixxed by AxxiD
  3.  
  4. -- PRINT
  5.  
  6. OSwidth, OSheight = term.getSize()
  7.  
  8. -- SCREEN
  9.  
  10. function clearScreen()
  11.  term.clear()
  12.  term.setCursorPos(1,1)
  13. end
  14.  
  15. function cS() -- shortcut for clearScreen()
  16.   clearScreen()
  17. end
  18.  
  19. function clearLine(line)
  20.  printCentered(string.rep(" ", OSwidth), line)
  21. end
  22.  
  23.  
  24. function clearColumn(column)
  25.  for i=1, OSheight, 1 do
  26.   term.setCursorPos(column,i)
  27.   term.write(" ")
  28.  end
  29. end
  30.  
  31. function clearColumnFromTo(column, start, last)
  32.  for i=start, last do
  33.   term.setCursorPos(column,i)
  34.   term.write(" ")
  35.  end
  36. end
  37.  
  38. function centerCursor(line)
  39.  term.setCursorPos(OSwidth/2,line)
  40. end
  41.  
  42. function leftCursor(line)
  43.  term.setCursorPos(1,line)
  44. end
  45.  
  46. function rightCursor(line)
  47.  term.setCursorPos(OSwidth,line)
  48. end
  49.  
  50. -- PRINT
  51.  
  52. function print(text, line, column)
  53.  term.setCursorPos(column,line)
  54.  term.write(text)
  55. end
  56.  
  57. function printCentered(text, line)
  58.  term.setCursorPos(OSwidth/2,line)
  59.  term.write(text)
  60. end
  61.  
  62. function printCenteredR(text,line)
  63.  clearLine(line)
  64.  printCentered(text,line)
  65. end
  66.  
  67. function printRight(text, line)
  68.  term.setCursorPos(OSwidth-#text,line)
  69.  term.write(text)
  70. end
  71.  
  72. function printRightR(text, line)
  73.  clearLine(line)
  74.  printRight(text,line)
  75. end
  76.  
  77. function printLeft(text, line)
  78.  term.setCursorPos(1,line)
  79.  term.write(text)
  80. end
  81.  
  82. function printLeftR(text, line)
  83.  clearLine(line)
  84.  printLeft(text, line)
  85. end
  86.  
  87. function printVertical(text, column)
  88.  for i=1, #text do
  89.   term.setCursorPos(column,i)
  90.   term.write(string.sub(text,i,i))
  91.  end
  92. end
  93.  
  94. function printVerticalR(text, column)
  95.  clearColumn(column)
  96.  printVertical(text, column)
  97. end
  98.  
  99. function printHeader(text,line)
  100.  printCentered(text, line)
  101.  printCentered(string.rep("-", OSwidth), line+1)
  102. end
  103.  
  104. -- FUEL
  105.  
  106. function refuel(slot ,level)
  107.  turtle.select(slot)
  108.  while turtle.getFuelLevel() <= level do
  109.   if turtle.refuel(0) then
  110.    turtle.refuel(1)
  111.   else
  112.    sleep(1)
  113.   end
  114.  end
  115. end
  116.  
  117.  
  118. --INVENTORY
  119.  
  120. function countSlots(first, last)
  121.  local amount = 0
  122.  for i=first, last do
  123.   local slotAmount = turtle.getItemCount(i)
  124.   if slotAmount > 0 then
  125.    amount = amount + slotAmount
  126.   end
  127.  end
  128.  return amount
  129. end
  130.  
  131. function countInventory()
  132.  return countSlots(1,16)
  133. end
  134.  
  135. function compareToSlot(first, second)
  136.  turtle.select(first)
  137.  return turtle.compareTo(second)
  138. end
  139.  
  140. function compareToSlots(selected, first, last)
  141.  local same = true
  142.  turtle.select(selected)
  143.  for i=first, last do
  144.   local check = turtle.compareTo(i)
  145.   if not check then same = false end
  146.  end
  147.  return same
  148. end
  149.  
  150. function transferTo(first, second, quantity)
  151.  quantity = quantity or 64
  152.  turtle.select(first)
  153.  turtle.transferTo(second,quantity)
  154. end
  155.  
  156. function transferToSlots(start, last, startTo)
  157.  for i=0, last-start-1 do
  158.   local startSlot = start + i
  159.   if startSlot > 16 then
  160.    startSlot = startSlot - 16
  161.   end
  162.   if turtle.getItemCount(startSlot) > 0 then
  163.    local slot = startTo + i
  164.    if slot > 16 then
  165.     slot = slot - 16
  166.    end
  167.    transferTo(startSlot, slot)
  168.   end
  169.  end
  170.  if countSlots(start, last) > 0 then
  171.   return false
  172.  end
  173.  return true
  174. end
  175.  
  176. -- DROP
  177.  
  178. function drop(slot,quantity)
  179.  quantitiy = quantity or 64
  180.  turtle.select(slot)
  181.  return turtle.drop(quantity)
  182. end
  183.  
  184. function dropUp(slot, quantity)
  185.  quantitiy = quantity or 64
  186.  turtle.select(slot)
  187.  return turtle.dropUp(quantity)
  188. end
  189.  
  190. function dropDown(slot, quantity)
  191.  quantity = quantity or 64
  192.  turtle.select(slot)
  193.  return turtle.dropDown(quantity)
  194. end
  195.  
  196. function dropSlots(dStart, dEnd)
  197.  local success = true
  198.  for i=dStart, dEnd do
  199.   if turtle.getItemCount(i) > 0 then
  200.    turtle.select(i)
  201.    local var = turtle.drop()
  202.    if not var then success = false end
  203.   end
  204.  end
  205.  return success
  206. end
  207.  
  208. function dropUpSlots(dStart, dEnd)
  209.  local success = true
  210.  for i=dStart, dEnd do
  211.   if turtle.getItemCount(i) > 0 then
  212.    turtle.select(i)
  213.    local var = turtle.dropUp()
  214.    if not var then success = false end
  215.   end
  216.  end
  217.  return success
  218. end
  219.  
  220. function dropDownSlots(dStart, dEnd)
  221.  local success = true
  222.  for i=dStart, dEnd do
  223.   if turtle.getItemCount(i) > 0 then
  224.    turtle.select(i)
  225.    local var = turtle.dropDown()
  226.    if not var then success = false end
  227.   end
  228.  end
  229.  return success
  230. end
  231.  
  232. function dropSameTo(slot)
  233.  local amount = 0
  234.  turtle.select(slot)
  235.  for i=1, 16 do
  236.   if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
  237.    turtle.select(i)
  238.    amount = amount + turtle.getItemCount(i)
  239.    turtle.drop()
  240.   end
  241.  end
  242.  return amount
  243. end
  244.  
  245. function dropUpSameTo(slot)
  246.  local amount = 0
  247.  turtle.select(slot)
  248.  for i=1, 16 do
  249.   if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
  250.    turtle.select(i)
  251.    amount = amount + turtle.getItemCount(i)
  252.    turtle.dropUp()
  253.   end
  254.  end
  255.  return amount
  256. end
  257.  
  258. function dropDownSameTo(slot)
  259.  local amount = 0
  260.  turtle.select(slot)
  261.  for i=1, 16 do
  262.   if turtle.getItemCount(i) > 0 and turtle.compareTo(i) and not slot == i then
  263.    turtle.select(i)
  264.    amount = amount + turtle.getItemCount(i)
  265.    turtle.dropDown()
  266.   end
  267.  end
  268.  return amount
  269. end
  270.  
  271.  
  272. -- SUCK
  273.  
  274. function suck(slot)
  275.  turtle.select(slot)
  276.  turtle.suck()
  277.  return turtle.getItemCount(slot)
  278. end
  279.  
  280. function suckUp(slot)
  281.  turtle.select(slot)
  282.  turtle.suckUp()
  283.  return turtle.getItemCount(slot)
  284. end
  285.  
  286. function suckDown(slot)
  287.  turtle.select(slot)
  288.  turtle.suckDown()
  289.  return turtle.getItemCount(slot)
  290. end
  291.  
  292. function suckSlots(sStart, sEnd)
  293.  local amount = countSlots(sStart, sEnd)
  294.  for i=sStart, sEnd do
  295.   if turtle.getItemCount(i) == 0 then
  296.    turtle.select(i)
  297.    turtle.suck()
  298.   end
  299.  end
  300.  return countSlots(sStart, sEnd) - amount
  301. end
  302.  
  303. function suckUpSlots(sStart, sEnd)
  304.  local amount = countSlots(sStart, sEnd)
  305.  for i=sStart, sEnd do
  306.   if turtle.getItemCount(i) == 0 then
  307.    turtle.select(i)
  308.    turtle.suckUp()
  309.   end
  310.  end
  311.  return countSlots(sStart, sEnd) - amount
  312. end
  313.  
  314. function suckDownSlots(sStart, sEnd)
  315.  local amount = countSlots(sStart, sEnd)
  316.  for i=sStart, sEnd do
  317.   if turtle.getItemCount(i) == 0 then
  318.    turtle.select(i)
  319.    turtle.suckDown()
  320.   end
  321.  end
  322.  return countSlots(sStart, sEnd) - amount
  323. end
  324.  
  325. -- DIG
  326.  
  327. function dig()
  328.  while turtle.detect() do
  329.   turtle.dig()
  330.   sleep(0.4)
  331.  end
  332. end
  333.  
  334. function digUp()
  335.  while turtle.detectUp() do
  336.   turtle.digUp()
  337.   if turtle.detectUp() then
  338.    sleep(0.4)
  339.   end
  340.  end
  341. end
  342.  
  343. function digDown()
  344.  while turtle.detectDown() do
  345.   turtle.digDown()
  346.   if turtle.detectDown() then
  347.    sleep(0.4)
  348.   end
  349.  end
  350. end
  351.  
  352. -- MOVEMENT
  353.  
  354. function turnAround()
  355.  if math.ceil(math.random()*2) == 1 then
  356.   turtle.turnLeft()
  357.   turtle.turnLeft()
  358.  else
  359.   turtle.turnRight()
  360.   turtle.turnRight()
  361.  end
  362. end
  363.  
  364. function forward(length)
  365.  for i=1,length do
  366.   while not turtle.forward() do sleep(1) end
  367.  end
  368. end
  369.  
  370. function forwardDig(length)
  371.  length = length or 1
  372.  for i=1,length do
  373.   while not turtle.forward() do turtle.dig() end
  374.  end
  375. end
  376.  
  377. function forwardExtreme(length)
  378.  length = length or 1
  379.  for i=1,length do
  380.   while not turtle.forward() do
  381.    if turtle.detect() then
  382.     dig()
  383.    else
  384.     turtle.attack()
  385.    end
  386.   end
  387.  end
  388. end
  389.  
  390. function back(length)
  391.  length = length or 1
  392.  for i=1,length do
  393.   while not turtle.back() do sleep(1) end
  394.  end
  395. end
  396.  
  397. function backDig(length)
  398.  length = length or 1
  399.  for i=1,length do
  400.   while not turtle.back() do
  401.    turnAround()
  402.    dig()
  403.    turnAround()
  404.   end
  405.  end
  406. end
  407.  
  408. function backExtreme(length)
  409.  length = length or 1
  410.  for i=1,length do
  411.   while not turtle.back() do
  412.    turnAround()
  413.    if turtle.detect() then
  414.     turtle.dig()
  415.    else
  416.     turtle.attack()
  417.    end
  418.    turnAround()
  419.   end
  420.  end
  421. end
  422.  
  423. function up(length)
  424.  length = length or 1
  425.  for i=1,length do
  426.   while not turtle.up() do sleep(1) end
  427.  end
  428. end
  429.  
  430. function upDig(length)
  431.  length = length or 1
  432.  for i=1,length do
  433.   while not turtle.up() do turtle.digUp() end
  434.  end
  435. end
  436.  
  437. function upExtreme(length)
  438.  length = length or 1
  439.  for i=1,length do
  440.   while not turtle.up() do
  441.    if turtle.detectUp() then
  442.     digUp()
  443.    else
  444.     turtle.attackUp()
  445.    end
  446.   end
  447.  end
  448. end
  449.  
  450. function down(length)
  451.  length = length or 1
  452.  for i=1,length do
  453.   while not turtle.down() do sleep(1) end
  454.  end
  455. end
  456.  
  457. function downDig(length)
  458.  length = length or 1
  459.  for i=1,length do
  460.   while not turtle.down() do turtle.digDown() end
  461.  end
  462. end
  463.  
  464. function downExtreme(length)
  465.  length = length or 1
  466.  for i=1,length do
  467.   while not turtle.down() do
  468.    if turtle.detectDown() then
  469.     turtle.digDown()
  470.    else
  471.     turtle.attackDown()
  472.    end
  473.   end
  474.  end
  475. end
Advertisement
Add Comment
Please, Sign In to add comment