Advertisement
noobslayer09

Drilling attempt +2

Jun 24th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.55 KB | None | 0 0
  1. -- Variables
  2. d = 0 -- depth along the y axis
  3. w = 1 -- width along the z axis
  4. l = 0 -- length along the x axis
  5. f = 0 -- face direction of turtle
  6. s = 0 -- start variable to break chain of asking for depth/width/length values
  7.  
  8. local BlockTable = {
  9.                     ["minecraft:grass"] = false,
  10.                     ["minecraft:dirt"] = false,
  11.                     ["minecraft:stone"] = false,
  12.                     ["minecraft:sand"] = false,
  13.                     ["minecraft:gravel"] = false,
  14.                     ["minecraft:flint"] = false,
  15.                     ["minecraft:cobblestone"] = false,
  16.                     ["minecraft:iron_ore"] = true,
  17.                     ["minecraft:copper_ore"] = true,
  18.                     ["minecraft:coal_ore"] = true,
  19.                     ["minecraft:gold_ore"] = true,
  20.                     ["minecraft:lapis_ore"] = true,
  21.                     ["minecraft:obsidian"] = true,
  22.                     ["minecraft:diamond_ore"] = true,          
  23.                     ["minecraft:redstone_ore"] = true,
  24.                     ["chisel:granite"] = false,
  25.                     ["chisel:limestone"] = false,
  26.                     ["chisel:andesite"] = false,
  27.                     ["chisel:diorite"] = false,
  28.                     ["ThermalFoundation:Ore"] = true,
  29.                     ["BigReactors:YelloriteOre"] = true,
  30.                     ["appliedenergistics2:tile.OreQuartz"] = true,
  31.                     ["appliedenergistics2:tile.OreQuartzCharged"] = true,
  32.                   }
  33.                  
  34.  
  35. -- Movement Functions
  36. function TurtleUp()
  37.   if turtle.up() then
  38.     d = d - 1
  39.   end
  40. end
  41.  
  42. function TurtleDown()
  43.   if turtle.down() then
  44.     d = d + 1
  45.   end
  46. end
  47.  
  48. function TurtleForward()
  49.     if f == 2 then
  50.         if turtle.forward() then
  51.             l = l + 1
  52.         end
  53.     end
  54.     if f == 0 then
  55.         if turtle.forward() then
  56.             l = l - 1
  57.         end
  58.     end
  59.   if f == 1 then
  60.     if turtle.forward() then
  61.       w = w - 1
  62.     end
  63.   end
  64.   if f == 3 then
  65.     if turtle.forward() then
  66.       w = w + 1
  67.     end
  68.   end
  69. end
  70.  
  71. function TurtleLeft()
  72.     if turtle.turnLeft() then
  73.         f = f + 1
  74.         f = f % 4
  75.     end
  76. end
  77. function next()
  78.   local currX = l
  79.   local currZ = w
  80.   if l < inpLength then
  81.     CheckAlign(2)
  82.     while l > currX + 2 do
  83.       TurtleForward()
  84.     end
  85.   end
  86.  
  87.   if l > inpLength then
  88.     CheckAlign(0)
  89.     while l > inpLength do
  90.       TurtleForward()
  91.     end
  92.   end
  93.   if l == inpLength then
  94.     CheckAlign(3)
  95.     while w < currZ + 2 do
  96.       TurtleForward()
  97.     end
  98.     CheckAlign(0)
  99.     while l > 0 do
  100.       TurtleForward()
  101.     end
  102.   end
  103. end
  104. function Width()
  105.   io.write("Enter a width value:")
  106.   inpWidth = io.read()
  107.   print(inpWidth, " Thank You")
  108.   inpWidth = tonumber(inpWidth)
  109. end
  110. function Length()
  111.   io.write("Enter a Length Value: ")
  112.   inpLength = io.read()
  113.   print(inpLength, " Thank You")
  114.   inpLength = tonumber(inpLength)
  115. end
  116.  
  117. function ReturnAndEmpty()
  118.   local currLength = l
  119.   local currWidth = w
  120.   while d > 0 do
  121.     TurtleUp()
  122.   end
  123.   CheckAlign(0)
  124.   while l > 0 do
  125.     if not(TurtleForward()) then
  126.       turtle.dig()
  127.     end
  128.   end
  129.   CheckAlign(2)
  130.   while w > 1 do
  131.     if not(TurtleForward()) then
  132.       turtle.dig()
  133.     end
  134.   end
  135.   CheckAlign(0)
  136.   empty()
  137.   CheckAlign(3)
  138.   if currLength >= inpLength and currWidth >= inpWidth then
  139.     os.shutdown()
  140.   end
  141.   while w > currWidth do
  142.     if not(TurtleForward()) then
  143.       turtle.dig()
  144.     end
  145.   end
  146.   if w == currWidth and l > currLength then
  147.     while l > currLength do
  148.       if not(TurtleForward()) then
  149.         turtle.dig()
  150.       end
  151.     end
  152.   end
  153. end
  154.  
  155.   -- Checking Functions
  156.  
  157. function Scan()
  158.   while f ~= 3 do
  159.     turtle.inspect()
  160.     MineValue = BlockTable[blockdata.name]
  161.     if MineValue == true then
  162.       turtle.dig()
  163.     end
  164.     TurnLeft()
  165.   end
  166.   CheckAlign(0)
  167. end
  168.  
  169. function CheckFuel()
  170.     if turtle.getFuelLevel() < inpLength then
  171.         turtle.select(1)
  172.         turtle.refuel(1)
  173.     end
  174. end
  175.  
  176. function Count()
  177.     if turtle.getItemCount(16) > 0 then
  178.         ReturnAndEmpty()
  179.     end
  180. end
  181.  
  182. function CheckAlign(dir)
  183.     CheckFuel()
  184.     while f ~= dir do
  185.         TurtleLeft()
  186.     end
  187. end
  188. function empty()
  189.     for i = 2,16 do
  190.         turtle.select(i)
  191.         turtle.drop()
  192.     end
  193.     turtle.select(2)
  194. end
  195.  
  196. function dig()
  197.   while s = 0 do
  198.     Length()
  199.     Width()
  200.     s = s + 1
  201.   end
  202.   while turtle.inspectDown() ~= ["minecraft:bedrock"] do
  203.     turtle.digDown()
  204.     Scan()
  205.     TurtleDown()
  206.   end
  207.   if turtle.inspectDown() == ["minecraft:bedrock"] then
  208.     next()
  209.   end
  210.   if w >= inpWidth and l >= inpLength then
  211.     ReturnAndEmpty()
  212.   end
  213. end
  214.  
  215. while true do
  216.   dig()
  217. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement