Driftix

3D mining managed modded

Mar 29th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. -- sourcecode : https://pastebin.com/RvykLz7g
  2. item_blacklist = {"minecraft:cobblestone","chisel:granite","chisel:limestone","chisel:andesite","chisel:diorite","minecraft:dirt", "minecraft:stone", "minecraft:clay_ball", "minecraft:torch", "minecraft:gravel", "minecraft:flint",}
  3.  
  4. function sleep(s)
  5.   local ntime = os.clock() + s
  6.   repeat until os.clock() > ntime
  7. end
  8.  
  9. local select_slot = function(id)
  10.   local i = 1
  11.   local data
  12.   while i < 17 do
  13.     turtle.select(i)
  14.     if turtle.getItemCount() > 0 then
  15.       data = turtle.getItemDetail()
  16.       if data.name == id then
  17.         return true
  18.       end
  19.     end
  20.     i = i + 1
  21.   end
  22.   turtle.select(1)
  23.   return false
  24. end
  25.  
  26. local special_refuel = function()
  27.   if select_slot("minecraft:coal") == true then
  28.     if turtle.getItemCount() >= 5 then
  29.       turtle.refuel(5)
  30.       print("[*] Refuel 5 coal")
  31.     else
  32.       print("[*] Refuel " .. turtle.getItemCount() .. " coal")
  33.       turtle.refuel()
  34.     end
  35.     return true
  36.   end
  37.   return false
  38. end
  39.  
  40. local is_in_blacklist = function(name)
  41.   local i = 1
  42.   while i <= table.getn(item_blacklist) do
  43.     if name == item_blacklist[i] then
  44.       return true
  45.     end
  46.     i = i + 1
  47.   end
  48.   return false
  49. end
  50.  
  51. local check_refuel = function()
  52.   if turtle.getFuelLevel() == 0 then
  53.     if not special_refuel() then
  54.       print("[*] Wating for fuel")
  55.       while not special_refuel() do
  56.         sleep(1)
  57.       end
  58.     end
  59.   end
  60. end
  61.  
  62. local verif_stuff = function()
  63.   local i = 1
  64.   print("[*] Stuff verification")
  65.   check_refuel()
  66.   while i < 17 do
  67.     turtle.select(i)
  68.     if turtle.getItemCount() > 0 then
  69.       data = turtle.getItemDetail()
  70.       if is_in_blacklist(data.name) then
  71.         print("[*] Drop " .. turtle.getItemCount() .. " " .. data.name)
  72.         turtle.drop()
  73.       end
  74.     end
  75.     i = i + 1
  76.   end
  77. end
  78.  
  79. local mine_x = function(x, total)
  80.   local i = 0
  81.   while i < x do
  82.     check_refuel()
  83.     if (total + i) % 20 == 0 then
  84.       verif_stuff()
  85.     end
  86.     while turtle.forward() == false do
  87.       turtle.dig()
  88.     end
  89.     i = i + 1
  90.   end
  91.   return total + i
  92. end
  93.  
  94. local mine_y = function(x, y, bool, total)
  95.   local i = 0
  96.   while i < y do
  97.     total = mine_x(x - 1, total)
  98.     if total % 20 == 0 then
  99.       verif_stuff()
  100.     end
  101.     if bool == false and not (i ==  y - 1) then
  102.       --print("turnRight")
  103.       turtle.turnRight()
  104.       total = mine_x(1, total)
  105.       turtle.turnRight()
  106.     elseif not (i ==  y - 1) then
  107.       --print("turnLeft")
  108.       turtle.turnLeft()
  109.       total = mine_x(1, total)
  110.       turtle.turnLeft()
  111.     end
  112.     bool = not bool
  113.     i = i + 1
  114.   end
  115.   return bool, total
  116. end
  117.  
  118. local mine_z = function(x, y, z)
  119.   local i = 0
  120.   local gobool = false
  121.   local retbool = false
  122.   local total = 0
  123.   verif_stuff()
  124.   while i < z do
  125.     retbool, total = mine_y(x, y, gobool, total)
  126.     if total % 20 == 0 then
  127.       verif_stuff()
  128.     end
  129.     --print("down")
  130.     if not (i == z - 1) then
  131.       turtle.digDown()
  132.       turtle.down()
  133.       turtle.turnRight()
  134.       turtle.turnRight()
  135.     end
  136.     gobool = not retbool
  137.     i = i + 1
  138.   end
  139.   verif_stuff()
  140. end
  141.  
  142. local arg = { ... }
  143. if not (table.getn(arg) == 3) then
  144.   print("[*] Please use command like this:")
  145.   print("    program x y z")
  146.   print("    program 10 10 5")
  147. else
  148.   mine_z(tonumber(arg[1]), tonumber(arg[2]), tonumber(arg[3]))
  149. end
Advertisement
Add Comment
Please, Sign In to add comment