Advertisement
pluggeman

mine

May 28th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. os.loadAPI("robot")
  2.  
  3. function init()
  4.     term.write('Neue Position? [j/n]')
  5.     i = read()
  6.     if i == 'j' then
  7.         robot.initGPS()
  8.     elseif i == 'n' then
  9.         robot.load()
  10.     else
  11.         term.clear()
  12.         term.setCursorPos(0, 0)
  13.         init()
  14.     end
  15. end
  16. init()
  17.  
  18. IGNORE_COUNT = 4
  19.  
  20. CHUNKS = 1
  21. MIN_HEIGHT = 8
  22. MAX_HEIGHT = 38
  23. Y_STEPS = 3
  24. LAYERS = math.floor((MAX_HEIGHT - MIN_HEIGHT) / Y_STEPS)
  25.  
  26. STEPS_PER_CHUNK = 16
  27.  
  28. LENGTH = CHUNKS * STEPS_PER_CHUNK
  29. STEPS = LENGTH - 1
  30.  
  31. X_START = robot.getX()
  32. Y_START = robot.getY()
  33. Z_START = robot.getZ()
  34. DIR_START = robot.getDirection()
  35.  
  36. current_layer = 0
  37.  
  38. moves_per_layer = LENGTH * LENGTH + LENGTH - 2
  39. moves_y = (Y_START - (MAX_HEIGHT - MIN_HEIGHT)) * LAYERS * 2
  40. moves = moves_per_layer * LAYERS + moves_y
  41. fuel_level_start = turtle.getFuelLevel()
  42.  
  43. function checkDown()
  44.     for i = 1, IGNORE_COUNT do
  45.         if robot.compareDownTo(i) then
  46.             return false
  47.         end
  48.     end
  49.     return true
  50. end
  51.  
  52. function checkUp()
  53.     for i = 1, IGNORE_COUNT do
  54.         if robot.compareUpTo(i) then
  55.             return false
  56.         end
  57.     end
  58.     return true
  59. end
  60.  
  61. function compare()
  62.     if checkUp() then turtle.digUp() end
  63.     if checkDown() then turtle.digDown() end
  64. end
  65.  
  66. function mine()
  67.     for current_layer = 0, LAYERS - 1 do
  68.        
  69.         robot.moveToY(MIN_HEIGHT + current_layer * Y_STEPS)
  70.        
  71.         for i = 1, LENGTH / 2 do
  72.             robot.moveZ(STEPS, compare)
  73.             robot.moveX(1, compare)
  74.             robot.moveZ(-STEPS, compare)
  75.  
  76.             if i < LENGTH / 2 then
  77.                 robot.moveX(1, compare)
  78.             end
  79.             for j = 1, IGNORE_COUNT do
  80.                 robot.drop(j, -1)
  81.                 for k = IGNORE_COUNT  + 1, 16 do
  82.                     if robot.compareItems(j, k) then
  83.                         robot.drop(k)
  84.                     end
  85.                 end
  86.             end
  87.         end
  88.  
  89.         robot.moveToX(X_START)
  90.         robot.moveToZ(Z_START)
  91.        
  92.         robot.turnTo(DIR_START)
  93.  
  94.         robot.moveToY(Y_START)
  95.  
  96.         term.clear()
  97.         term.setCursorPos(1, 1)
  98.         cur_layer = current_layer + 1
  99.         moves_done = fuel_level_start - turtle.getFuelLevel()
  100.         print("layer "..cur_layer.."/"..LAYERS)
  101.         print(moves_done.."/"..moves.." moves")
  102.  
  103.         for j = IGNORE_COUNT+1, 16 do
  104.             robot.drop(j)
  105.         end
  106.     end
  107. end
  108.  
  109. term.clear()
  110. term.setCursorPos(1, 1)
  111. print("Total moves: " .. moves)
  112. print("Fuel: " .. fuel_level_start)
  113. fuel = fuel_level_start - moves
  114.  
  115. if fuel < 0 then
  116.     fuel = math.abs(fuel)
  117.     coal_needed = math.ceil(fuel/80)
  118.     print("Not enough fuel - "..fuel.." fuel needed. ("..coal_needed.." coal)")
  119. else
  120.     os.sleep(3)
  121.     mine()
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement