Advertisement
Guest User

mine.lua

a guest
Dec 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. local geo = component.geolyzer
  4. local term = require("term")
  5. local computer =  require("computer")
  6. local currX = 0
  7. local currZ = 0
  8. local currY = 0
  9.  
  10. function scan()
  11.   for i = 0, 5 do
  12.     local block = geo.analyze(i)
  13.     local blockName = block["name"]
  14.     local ores = require("lib/ores")
  15.     for k,v in pairs(ores) do
  16.       if blockName == v then
  17.         if i == 4 then
  18.           robot.turnRight()
  19.           robot.swing(0)
  20.           robot.turnLeft()
  21.         elseif i == 5 then
  22.           robot.turnLeft()
  23.           robot.swing(0)
  24.           robot.turnRight()
  25.         end
  26.       end
  27.     end
  28.     --for k, v in pairs(block) do
  29.     --  print(k,":",v)
  30.     --end
  31.   end
  32. end
  33.  
  34. function statusCheck()
  35.   local power = computer.energy()
  36.   local maxPower = computer.maxEnergy()
  37.   print("Current power: ", power)
  38.   if(power < 20500) then
  39.     print("Refueling!")
  40.     print("X: ",currX," Z: ",currZ," Y ",currY)
  41.   end
  42. end
  43.  
  44. function digDown(distY)
  45.   local move
  46.   for i = 1, distY do
  47.     move = nil
  48.     currY = currY - 1
  49.     while(move == nil) do
  50.       robot.swingDown()
  51.       move = robot.down()
  52.     end
  53.   end
  54. end
  55.  
  56. function digUp(distY)
  57.   local move
  58.   for i = 1, distY do
  59.     currY = curr + 1
  60.     move = nil
  61.     while(move == nil) do
  62.       robot.swingUp()
  63.       move = robot.up()
  64.     end
  65.   end
  66. end
  67.  
  68. function digForward(distX, axis)
  69.   local move
  70.   for i = 1, distX do
  71.     if axis == "+x" then
  72.       currX = currX + 1
  73.     elseif axis == "-x" then
  74.       currX = currX - 1
  75.     elseif axis == "+z" then
  76.       currZ = currZ + 1
  77.     elseif axis == "-z" then
  78.       currZ = currZ - 1
  79.     end
  80.  
  81.     move = nil
  82.     while(move == nil) do
  83.       robot.swing(0)
  84.       move = robot.forward()
  85.       statusCheck()
  86.     end
  87.     scan()
  88.   end
  89. end
  90.  
  91. function row(distX)
  92.   robot.turnLeft()
  93.   digForward(distX, "+x")
  94.   robot.turnAround()
  95.   digForward(distX, "-x")
  96.   robot.turnLeft()
  97. end
  98.  
  99. function plane(distX, distZ)
  100.   row(distX)
  101.   for i = 1, distZ do
  102.     digForward(1, "+z")
  103.     if(i % 3 == 0) then
  104.       row(distX)
  105.     end
  106.   end
  107.   robot.turnAround()
  108.   digForward(distZ, "-z")
  109.   robot.turnAround()
  110. end
  111.  
  112. function start(distX, distZ, distY)
  113.   distY = distY - 1
  114.   distX = distX - 1
  115.   distZ = distZ - 1
  116.   digDown(1)
  117.   robot.turnRight()
  118.   plane(distX, distZ)
  119.   for i = 1, distY do
  120.     digDown(1)
  121.     plane(distX, distZ)
  122.   end
  123.   robot.turnLeft()
  124.   digUp(distY+1)  
  125. end
  126.  
  127. term.write("X: ")
  128. x = term.read()
  129. term.write("Z: ")
  130. z = term.read()
  131. term.write("Y: ")
  132. y = term.read()
  133.  
  134. start(x,z,y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement