Advertisement
Frayna

Mine v0.35.Dev

Oct 24th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.93 KB | None | 0 0
  1. -- Beta
  2.  
  3. function name_mod (str)
  4. j = string.find(str, ":")
  5. return string.sub(str, 1, j - 1)
  6. end
  7.  
  8. function name_bloc (str)
  9. j = string.find(str, ":")
  10. return string.sub(str, j + 1, string.len(str))
  11. end
  12. -- Fill hole of the optimine
  13. function cln_mine()
  14.     for i=1 , 16 do
  15.         local data = turtle.getItemDetail(i)
  16.         if turtle.getItemDetail(i) ~= nil then
  17.             if ((data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt")) then
  18.                 turtle.select(i)
  19.                 turtle.placeDown()
  20.                 return
  21.             end
  22.         end
  23.     end
  24. turtle.select(1)
  25. end
  26.  
  27. -- Eject unwanted blocks (arguments: put true if optimine, else put false)
  28. function clean(opti)
  29.     for i=1 , 16 do
  30.         local data = turtle.getItemDetail(i)
  31.         if turtle.getItemDetail(i) ~= nil then
  32.             if ((data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt")) and opti then
  33.                 turtle.select(i)
  34.                 turtle.dropDown(data.count - 1)
  35.                 opti = false               
  36.             elseif ((data.name == "minecraft:cobblestone") or (data.name == "minecraft:dirt")
  37.             or (name_mod(data.name) == "chisel") or ((name_mod(data.name) ~= arg[1])
  38.             and (name_mod(data.name) ~= arg[2]) and (name_mod(data.name) ~= arg[3]))) then
  39.                 turtle.select(i)
  40.                 turtle.dropDown(data.count)
  41.             end
  42.         end
  43.     end
  44. turtle.select(1)
  45. end
  46. -- Print items in all slots
  47. function print_inv()
  48.     for i=1 , 16 do
  49.         local data = turtle.getItemDetail(i)
  50.         turtle.select(i)
  51.             if turtle.getItemDetail(i) ~= nil then
  52.                 write("Slot " .. i ..": ".. data.count .. " " .. data.name .. "\n")
  53.             else
  54.                 write("Slot " .. i ..": empty \n")
  55.             end
  56.         end
  57. turtle.select(1)
  58. end
  59.  
  60. -- functions for optimine and sugar canne farming (don't try to understand, except if you want cry)
  61. function ft_impr ()
  62. ft_fwd(1)
  63. turtle.turnRight()
  64. ft_fwd(2)
  65. end
  66.  
  67. function ft_pair ()
  68. ft_fwd(2)
  69. turtle.turnLeft()
  70. ft_fwd(1)
  71. end
  72.  
  73. -- mine to bedrock
  74. function mine()
  75.  
  76.  local success, data = turtle.inspectDown()
  77.  if (data.name == "minecraft:cobblestone") then
  78.     return;
  79.  elseif (data.name ~= "minecraft:bedrock") then
  80.     turtle.digDown()
  81.  
  82.     for i=1, 4
  83.   do
  84.     turtle.turnRight()
  85.     local success, data = turtle.inspect()
  86.  
  87.     if success then
  88.       if ((data.name ~= "minecraft:stone") and (data.name ~= "minecraft:grass")
  89.         and (data.name ~= "minecraft:cobblestone")
  90.         and (data.name ~= "minecraft:dirt") and (data.name ~= "TConstruct:GravelOre")
  91.         and (data.name ~= "minecraft:sand") and ((name_mod(data.name) == arg[1])
  92.         or (name_mod(data.name) == arg[2]) or (name_mod(data.name) == arg[3])))
  93.         then
  94.             turtle.dig()
  95.             print("Found : " .. name_bloc(data.name))
  96.       end
  97.     end
  98.   end
  99.     turtle.down()
  100.     mine()
  101.     turtle.up()
  102.   end
  103. end
  104.  
  105. -- optimised minning
  106. function optimine()
  107. turtle.select(1)
  108. print ("Attention !!! Ne prend pas en compte le surplus !!!")
  109. print ("Please define X")
  110. xmax = tonumber(read())
  111. print ("Please define Y")
  112. ymax = tonumber(read())
  113. print ("Press F3 and write the value of Y")
  114. height = tonumber(read())
  115. fuel = turtle.getFuelLevel()
  116. fneed = 3 * height * xmax * ymax
  117. print ("Estimated fuel required : " ..fneed)
  118. os.sleep(2)
  119. while fuel < fneed do
  120.     turtle.select(2)
  121.     print ("Put Fuel in slot 2\nStill Requiring : " ..(fneed - fuel))
  122.     os.sleep(3)
  123.     turtle.refuel()
  124.     fuel = turtle.getFuelLevel()
  125. end
  126. turtle.select(1)
  127. x = 1
  128. y = 1
  129. while ((x <= xmax) and (y <= ymax)) do
  130.     mine()
  131.     turtle.select(1)
  132.     clean(true)
  133.     cln_mine()
  134.     compact()
  135.         if (x == xmax) and (y == ymax) then break end
  136.         if ((x == xmax) and (y%2 == 0)) then
  137.             if xmax%2 == 1 then turtle.turnRight() end
  138.             ft_impr()
  139.             x = 1
  140.             y = y + 1
  141.         elseif ((x == xmax) and (y%2 == 1)) then
  142.             if xmax%2 == 0 then turtle.turnLeft() end
  143.             ft_pair()
  144.             turtle.turnLeft()
  145.             x = 1
  146.             y = y + 1
  147.         elseif x%2 == 1 then
  148.             ft_impr()
  149.             x = x + 1
  150.         elseif x%2 == 0 then
  151.             ft_pair()
  152.             x = x + 1
  153.         else print("EXTERMINATE !!!")
  154.         end
  155. end
  156. end
  157.  
  158. -- Final version
  159.  
  160. -- move forward (forced), break the blocks forward if there is one
  161. function ft_fwd(nb)
  162. i = 0
  163.     while i<nb do
  164.     local success, data = turtle.inspect()
  165.         if success then
  166.         turtle.dig()
  167.         turtle.forward()
  168.         else
  169.         turtle.forward()
  170.         end
  171.     i = i+1
  172.     end
  173. end
  174.  
  175. -- try to stack current slot with next slots
  176. function stack()
  177. local slot = turtle.getSelectedSlot()
  178. if turtle.getItemCount(slot) ~= 0 then
  179.     for i = slot + 1, 16 do
  180.     write (slot .. "   ")
  181.     turtle.select(i)
  182.         if turtle.compareTo(slot) then
  183.         turtle.transferTo(slot)
  184.         end
  185.         if turtle.getItemCount(slot) == 64 then
  186.         return
  187.         end
  188.     end
  189. end
  190. turtle.select(slot)
  191. end
  192.  
  193. -- try to compact inventory
  194. function compact ()
  195.     for slot = 1 , 16 do
  196.     write (slot .. "   ")
  197.         if turtle.getItemCount(slot) == 0 then
  198.             for i = slot + 1, 16 do
  199.             turtle.select(i)
  200.                 if turtle.getItemCount(i) ~= 0 then
  201.                     turtle.transferTo(slot)
  202.                     break
  203.                 end
  204.                 if i == 16 then
  205.                     turtle.select(1)
  206.                     return
  207.                 end
  208.             end
  209.             turtle.select(slot)
  210.         end
  211.     end
  212. turtle.select(1)
  213. end
  214.  
  215. -- stack all slots (require stack)
  216. function stack_all()
  217.     for i = 1, 16 do
  218.         turtle.select(i)
  219.         stack()
  220.         turtle.select(1)
  221.     end
  222. end
  223.  
  224. function help ()
  225. print ("Usage of mine :")
  226. print ("\t mine <name mod 1> <name mod 2> ...")
  227. print ("Limited to 3 mods")
  228. print ("If you need more help type: mine more")
  229. print ("it's case sensitive so check: mine list")
  230. end
  231.  
  232. function more ()
  233. print ("Example of usage : mine minecraft")
  234. print ("it will mine all minecraft blocs founds")
  235. print ("An other example : mine minecraft BigReactors")
  236. print ("it will mine all minecraft and BigReactors blocs founds")
  237. end
  238.  
  239. function list ()
  240. print("mods commands:\n")
  241. print("Tinkers' Construct: TConstruct")
  242. print("Pam's Haverstcraft : harvestcraft")
  243. print("Thermal Foundation: ThermalFoundation")
  244. print("Thaumcraft: Thaumcraft")
  245. print("Chisel 2: chisel")
  246. end
  247. arg = {...}
  248. local i = #arg
  249.  
  250. while i < 3 do
  251. arg[i + 1] = "none"
  252. i = i + 1
  253. end
  254.  
  255. if arg [1] == "none" then help()
  256. elseif arg[1] == "more" then
  257. more()
  258. elseif arg[1] == "list" then
  259. list()
  260. else optimine()
  261. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement