SHARE
TWEET

downminer.lua

neo34rd Mar 25th, 2019 (edited) 165 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2. if #tArgs ~= 2 then
  3.   print("Requires length, width")
  4.   return
  5. end
  6.  
  7. local x = tonumber(tArgs[1])
  8. local z = tonumber(tArgs[2])
  9.  
  10. if x == nil or z == nil then
  11.   print("Invalid dimensions")
  12.   return
  13. end
  14.  
  15. if x < 0 or z < 0 then
  16.   print("Invalid (negative) dimensions")
  17.   return
  18. end
  19.  
  20. local fuel = turtle.getFuelLevel()
  21. local roomSize = x * z * 100
  22. while fuel < roomSize do
  23.   if not turtle.refuel(1) then
  24.     print("Not enough fuel")
  25.     return
  26.   end
  27. end
  28.  
  29.  
  30. os.loadAPI("dump")
  31. os.loadAPI("transformation")
  32. os.loadAPI("scanbranchminer")
  33. os.loadAPI("stack")
  34. os.loadAPI("inventory")
  35.  
  36. t = transformation.newTransform()
  37. position_stack = stack.newStack()
  38. forward_stack = stack.newStack()
  39. worthy_ores = scanbranchminer.loadWorthyOres()
  40.  
  41. worthless_ore = "minecraft:cobblestone"
  42.  
  43.  
  44. function select_worthless()
  45.   --inventory.sort()
  46.   for i = 1, 16 do
  47.     d = turtle.getItemDetail(i)
  48.     if d ~= nil and d.name == worthless_ore then
  49.       turtle.select(i)
  50.       return
  51.     end
  52.   end
  53. end
  54.  
  55.  
  56. function try_dig()
  57.   --- compare with blacklist ore
  58.   for i = 1, 4 do
  59.       turtle.select(i)
  60.       if turtle.compare() then
  61.           return false
  62.       end
  63.   end
  64.   turtle.dig()
  65.   return true
  66. end
  67.  
  68.  
  69. function crosswise_check()
  70.   try_dig()
  71.   for i = 1, 3 do
  72.       transformation.turnLeft(t)
  73.       try_dig()
  74.   end
  75. end
  76.  
  77.  
  78. function move_down()
  79.   turtle.digDown()
  80.   return transformation.down(t)
  81. end
  82.  
  83.  
  84. function dig_col()
  85.   while move_down() do
  86.     scanbranchminer.scanAllStart(t, position_stack, forward_stack, worthy_ores)
  87.   end
  88.   while t.position.y < 0 do
  89.     turtle.digUp()
  90.     transformation.up(t)
  91.   end
  92. end
  93.  
  94.  
  95. function deposit()
  96.   transformation.gotoPosition(t, vector.makeZero())
  97.   transformation.face(t, vector.make(0,0,-1))
  98.   dump_loot()
  99. end
  100.  
  101.  
  102. function dump_loot()
  103.   --- Dump all but 1 worthless item
  104.   for i = 1, 16 do
  105.       turtle.select(i)
  106.       d = turtle.getItemDetail(i)
  107.       if d then
  108.         if d.name == worthless_ore then
  109.           turtle.drop(d.count - 1)
  110.         else
  111.           turtle.drop()
  112.         end
  113.       end
  114.   end
  115. end
  116.  
  117.  
  118. function run()
  119.   x = x - 1
  120.   z = z - 1
  121.   for xI = 0, x do
  122.     for zI = 0, z do
  123.       --- Move to the XZ coordinate
  124.       _x = xI * 3
  125.       _z = zI * 3
  126.       local v = vector.make(_x, 0, _z)
  127.       transformation.gotoPosition(t, v)
  128.  
  129.       --- Place marker above
  130.       select_worthless()
  131.       turtle.placeUp()
  132.  
  133.       --- Dig a hole
  134.       dig_col()
  135.  
  136.       --- Return to the surface
  137.       topX = t.position.x
  138.       topZ = t.position.z
  139.       topV = vector.make(topX, 0, topZ)
  140.       transformation.gotoPosition(t, topV)
  141.  
  142.       --- Cover the hole
  143.       select_worthless()
  144.       turtle.placeDown()
  145.  
  146.       --- Deposite ores
  147.       deposit()
  148.     end
  149.   end
  150.   deposit()
  151. end
  152.  
  153. run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top