Advertisement
Link712011

CC - Sand Miner

May 4th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.11 KB | None | 0 0
  1. function select_fuel()
  2.     local slot = 1
  3.     local data
  4.    
  5.     while slot <= 16 do
  6.         data = turtle.getItemDetail(slot)
  7.         if data and (data.name == "minecraft:lava_bucket" or data.name == "minecraft:coal" or data.name == "minecraft:planks" or data.name == "minecraft:log") then
  8.             turtle.select(slot)
  9.             return true
  10.         end
  11.         slot = slot + 1
  12.     end
  13.     return false
  14. end
  15. function is_inventory_full()
  16.     local slot = 1
  17.     local data
  18.    
  19.     while slot <= 16 do
  20.         data = turtle.getItemDetail(slot)
  21.         if not data then
  22.             return false
  23.         end
  24.         slot = slot + 1
  25.     end
  26.     return true
  27. end
  28. function check_fuel()
  29.     if turtle.getFuelLevel() < 10 then
  30.         while not select_fuel() do
  31.             print("Waiting fuel. Retrying refuel in 10 seconds.")
  32.             sleep(10)
  33.         end
  34.         turtle.refuel()
  35.     end
  36. end
  37. function avance()
  38.     local grav = 0
  39.     local success, data
  40.    
  41.     while not turtle.forward() do
  42.         success, data = turtle.inspect()
  43.         check_fuel()
  44.         if success then
  45.             turtle.dig()
  46.             if data.name == "minecraft:gravel" then
  47.                 grav = grav + 1
  48.             end
  49.         end
  50.     end
  51.     return grav
  52. end
  53. function recule()
  54.     while not turtle.back() do
  55.         check_fuel()
  56.         turtle.turnLeft()
  57.         turtle.turnLeft()
  58.         turtle.dig()
  59.         turtle.turnLeft()
  60.         turtle.turnLeft()
  61.     end
  62. end
  63. function dig_collumn(grav)
  64.     local z, ntp = 0, 0
  65.  
  66.     while turtle.detectUp() or grav > 0 or ntp > 0 do
  67.         check_fuel()
  68.         while not turtle.up() do
  69.             turtle.digUp()
  70.             turtle.suckUp()
  71.             ntp = ntp + 1
  72.         end
  73.         turtle.suckUp()
  74.         z = z + 1
  75.         if ntp > 0 then ntp = ntp - 1 end
  76.         if grav > 0 then grav = grav - 1 end
  77.     end
  78.     turtle.suck()
  79.     turtle.suckUp()
  80.     while z > 0 do
  81.         if not turtle.down() then
  82.             check_fuel()
  83.             turtle.digDown()
  84.         end
  85.         z = z - 1
  86.     end
  87. end
  88. function stone_down()
  89.     local success, data = turtle.inspectDown()
  90.     if success and data.name ~= "minecraft:dirt" and data.name ~= "minecraft:grass" then
  91.         return true
  92.     elseif not turtle.detectDown() then
  93.         return true
  94.     end
  95.     return false
  96. end
  97. function select_dirt()
  98.     local i = 1
  99.     local data
  100.    
  101.     while i < 16 do
  102.         data = turtle.getItemDetail(i)
  103.         if data and data.name == "minecraft:dirt" then
  104.             turtle.select(i)
  105.             return true
  106.         end
  107.         i = i + 1
  108.     end
  109.     return false
  110. end
  111. function replace_bloc_by_dirt()
  112.     if select_dirt() then
  113.         turtle.digDown()
  114.         turtle.placeDown()
  115.     end
  116. end
  117. function drop_all_bottom()
  118.     local slot = 1
  119.     local data
  120.    
  121.     while slot <= 16 do
  122.         data = turtle.getItemDetail(slot)
  123.         if data and data.name ~= "minecraft:coal" then
  124.             turtle.select(slot)
  125.             if not turtle.dropDown() then
  126.                 break
  127.             end
  128.         end
  129.         slot = slot + 1
  130.     end
  131. end
  132. function get_chest_presence()
  133.     local success, data = turlte.inspectDown()
  134.    
  135.     if success and data.name == "minecraft:chest" then
  136.         drop_all_bottom()
  137.     end
  138. end
  139. function multavance(x)
  140.     while x > 0 do
  141.         avance()
  142.         x = x - 1
  143.     end
  144. end
  145. function goto_base_and_drop(x, y)
  146.     turtle.turnLeft()
  147.     turtle.turnLeft()
  148.     multavance(x)
  149.     turtle.turnRight()
  150.     multavance(y)
  151.     turtle.turnRight()
  152.     drop_all_bottom()
  153.     turtle.turnRight()
  154.     multavance(y)
  155.     turtle.turnLeft()
  156.     multavance(x)
  157. end
  158. function select_next_item(slot, item)
  159.     local data
  160.    
  161.     while slot <= 16 do
  162.         data = turtle.getItemDetail(slot)
  163.         if data and data.name == item then
  164.             turtle.select(slot)
  165.             return true
  166.         end
  167.         slot = slot + 1
  168.     end
  169.     return false
  170. end
  171. function repack_item(item)
  172.     local slot = 1
  173.     local data
  174.    
  175.     while slot < 16 do
  176.         data = turtle.getItemDetail(slot)
  177.         if not data or (data.name == item and data.count < 64) then
  178.             if select_next_item(slot + 1, item) then
  179.                 turtle.transferTo(slot)
  180.                 data = turtle.getItemDetail(slot)
  181.             else
  182.                 return true
  183.             end
  184.         end
  185.         if data and ((data.name == item and data.count == 64) or data.name ~= item) then
  186.             slot = slot + 1
  187.         end
  188.     end
  189.     return true
  190. end
  191. function clean_inventory(x, y)
  192.     local slot = 1
  193.     local data
  194.    
  195.     while slot <= 16 do
  196.         data = turtle.getItemDetail(slot)
  197.         if data and (data.name == "minecraft:diamond" or data.name == "minecraft:emerald" or data.name == "minecraft:redstone" or data.name == "minecraft:iron_ore" or data.name == "minecraft:gold_ore" or data.name == "minecraft:coal" or (data.name == "minecraft:dye" and data.damage == 4) or data.name == "minecraft:lava_bucket" or data.name == "minecraft:coal" or data.name == "minecraft:planks" or data.name == "minecraft:log" or data.name == "minecraft:sand") then
  198.             repack_item(data.name)
  199.         elseif data then
  200.             turtle.select(slot)
  201.             turtle.drop()
  202.         end
  203.         slot = slot + 1
  204.     end
  205.     if is_inventory_full() then
  206.         goto_base_and_drop(x, y)
  207.     end
  208. end
  209.  
  210. local x, y = 0, 0
  211. print("How metters dig in front off ?")
  212. local xmax = tonumber(read())
  213. print("How metters dig at right ?")
  214. local ymax = tonumber(read())
  215. local grav = 0
  216.  
  217. while y < ymax or x < xmax do
  218.     check_fuel()
  219.     if turtle.detectUp() then dig_collumn(0) end
  220.     grav = 0
  221.     if x == xmax then
  222.         while x > 0 do
  223.             recule()
  224.             x = x - 1
  225.         end
  226.         turtle.turnRight()
  227.         avance()
  228.         turtle.turnLeft()
  229.         y = y + 1
  230.     else
  231.         grav = avance()
  232.         x = x + 1
  233.     if turtle.detectUp() or grav > 0 then dig_collumn(grav) end
  234.     if stone_down() then replace_bloc_by_dirt() end
  235.     if is_inventory_full() then clean_inventory(x, y) end
  236.     end
  237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement