Frayna

FraynAPI (ccraft)

Sep 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.53 KB | None | 0 0
  1. -- Beta
  2. -- Fill hole of the optimine
  3. function cln_mine()
  4.     for i=1 , 16 do
  5.         local data = turtle.getItemDetail(i)
  6.         if turtle.getItemDetail(i) ~= nil then
  7.             if ((data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt")) then
  8.                 turtle.select(i)
  9.                 turtle.placeDown()
  10.                 return
  11.             end
  12.         end
  13.     end
  14. turtle.select(1)
  15. end
  16.  
  17. -- Eject unwanted blocks (arguments: put true if optimine, else put false)
  18. function clean(opti)
  19.     for i=1 , 16 do
  20.         local data = turtle.getItemDetail(i)
  21.         if turtle.getItemDetail(i) ~= nil then
  22.             if ((data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt")) and opti then
  23.                 turtle.select(i)
  24.                 turtle.dropDown(data.count - 1)
  25.                 opti = false               
  26.             elseif (data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt") then
  27.                 turtle.select(i)
  28.                 turtle.dropDown(data.count)
  29.             end
  30.         end
  31.     end
  32. turtle.select(1)
  33. end
  34. -- Print items in all slots
  35. function print_inv()
  36.     for i=1 , 16 do
  37.         local data = turtle.getItemDetail(i)
  38.         turtle.select(i)
  39.             if turtle.getItemDetail(i) ~= nil then
  40.                 write("Slot " .. i ..": ".. data.count .. " " .. data.name .. "\n")
  41.             else
  42.                 write("Slot " .. i ..": empty \n")
  43.             end
  44.         end
  45. turtle.select(1)
  46. end
  47.  
  48. -- functions for optimine and sugar canne farming (don't try to understand, except if you want cry)
  49. function ft_impr ()
  50. ft_fwd(1)
  51. turtle.turnRight()
  52. ft_fwd(2)
  53. end
  54.  
  55. function ft_pair ()
  56. ft_fwd(2)
  57. turtle.turnLeft()
  58. ft_fwd(1)
  59. end
  60.  
  61. -- mine to bedrock
  62. function mine()
  63.  
  64.  local success, data = turtle.inspectDown()
  65.  if (data.name == "minecraft:cobblestone") then
  66.     return;
  67.  elseif (data.name ~= "minecraft:bedrock") then
  68.     turtle.digDown()
  69.  
  70.     for i=1, 4
  71.   do
  72.     turtle.turnRight()
  73.     local success, data = turtle.inspect()
  74.  
  75.     if success then
  76.       print(data.name)
  77.       if ((data.name ~= "minecraft:stone") and (data.name ~= "minecraft:grass")
  78.       and (data.name ~= "minecraft:dirt") and (data.name ~= "TConstruct:GravelOre")
  79.       and (data.name ~= "minecraft:sand"))
  80.         then turtle.dig()
  81.       end
  82.     else
  83.       print("minecraft:air")
  84.     end
  85.   end
  86.     turtle.down()
  87.     mine()
  88.     turtle.up()
  89.   end
  90. end
  91.  
  92. -- optimised minning
  93. function optimine()
  94. turtle.select(1)
  95. print ("Attention !!! Ne prend pas en compte le surplus !!!")
  96. print ("Please define X")
  97. xmax = tonumber(read())
  98. print ("Please define Y")
  99. ymax = tonumber(read())
  100. print ("Press F3 and write the value of Y")
  101. height = tonumber(read())
  102. fuel = turtle.getFuelLevel()
  103. fneed = 3 * height * xmax * ymax
  104. print ("Estimated fuel required : " ..fneed)
  105. os.sleep(2)
  106. while fuel < fneed do
  107.     turtle.select(2)
  108.     print ("Put Fuel in slot 2\nStill Requiring : " ..(fneed - fuel))
  109.     os.sleep(3)
  110.     turtle.refuel()
  111.     fuel = turtle.getFuelLevel()
  112. end
  113. turtle.select(1)
  114. x = 1
  115. y = 1
  116. while ((x <= xmax) and (y <= ymax)) do
  117.     mine()
  118.     clean(true)
  119.     cln_mine()
  120.         if (x == xmax) and (y == ymax) then break end
  121.         if ((x == xmax) and (y%2 == 0)) then
  122.             if xmax%2 == 1 then turtle.turnRight() end
  123.             ft_impr()
  124.             x = 1
  125.             y = y + 1
  126.         elseif ((x == xmax) and (y%2 == 1)) then
  127.             if xmax%2 == 0 then turtle.turnLeft() end
  128.             ft_pair()
  129.             turtle.turnLeft()
  130.             x = 1
  131.             y = y + 1
  132.         elseif x%2 == 1 then
  133.             ft_impr()
  134.             x = x + 1
  135.         elseif x%2 == 0 then
  136.             ft_pair()
  137.             x = x + 1
  138.         else print("EXTERMINATE !!!")
  139.         end
  140. end
  141. end
  142.  
  143. -- Final version
  144.  
  145. -- move forward (forced), break the blocks forward if there is one
  146. function ft_fwd(nb)
  147. i = 0
  148.     while i<nb do
  149.     local success, data = turtle.inspect()
  150.         if success then
  151.         turtle.dig()
  152.         turtle.forward()
  153.         else
  154.         turtle.forward()
  155.         end
  156.     i = i+1
  157.     end
  158. end
  159.  
  160. -- try to stack current slot with next slots
  161. function stack()
  162. local slot = turtle.getSelectedSlot()
  163. if turtle.getItemCount(slot) ~= 0 then
  164.     for i = slot + 1, 16 do
  165.     write (slot .. "   ")
  166.     turtle.select(i)
  167.         if turtle.compareTo(slot) then
  168.         turtle.transferTo(slot)
  169.         end
  170.         if turtle.getItemCount(slot) == 64 then
  171.         return
  172.         end
  173.     end
  174. end
  175. turtle.select(slot)
  176. end
  177.  
  178. -- try to compact inventory
  179. function compact ()
  180.     for slot = 1 , 16 do
  181.     write (slot .. "   ")
  182.         if turtle.getItemCount(slot) == 0 then
  183.             for i = slot + 1, 16 do
  184.             turtle.select(i)
  185.                 if turtle.getItemCount(i) ~= 0 then
  186.                     turtle.transferTo(slot)
  187.                     break
  188.                 end
  189.                 if i == 16 then
  190.                     turtle.select(1)
  191.                     return
  192.                 end
  193.             end
  194.             turtle.select(slot)
  195.         end
  196.     end
  197. turtle.select(1)
  198. end
  199.  
  200. -- stack all slots (require stack)
  201. function stack_all()
  202.     for i = 1, 16 do
  203.         turtle.select(i)
  204.         stack()
  205.         turtle.select(1)
  206.     end
  207. end
Advertisement
Add Comment
Please, Sign In to add comment