Advertisement
theluksabm

[Carlos 2.1a] - Computer Craft Script - Lua

Apr 7th, 2020
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. --Quarry Program
  2. --@author: dlks
  3. --@version: 2.1a
  4.  
  5. local movef = turtle.forward
  6. local moved = turtle.down
  7. local digf = turtle.dig
  8. local digd = turtle.digDown
  9. local canmovef  = turtle.detect
  10. local canmoved = turtle.detectDown
  11. local lookr = turtle.turnRight
  12. local lookl = turtle.turnLeft
  13. local prefix = "[Carlos 2.1a] "
  14.  
  15.  
  16. -- Funcao printf
  17. local function printf(...) print(string.format(...)) end
  18.  
  19.  
  20. -- Funcao combustivel
  21. local function combustivel()
  22.     local restante = turtle.getFuelLevel() -- Combustivel restante
  23.     local suficiente = false
  24.  
  25.     while true do
  26.         if restante == 0 then
  27.             suficiente = false
  28.             printf("%sSem combustivel restante, tentando reabastecer.", prefix)
  29.             for i = 1, 16 do
  30.                 turtle.select(i)
  31.                 if turtle.refuel(0) then
  32.                     local halfStack = math.ceil(turtle.getItemCount(i)/2)
  33.                     turtle.refuel(halfStack)
  34.                     restante = turtle.getFuelLevel()
  35.                     suficiente = true
  36.                     break
  37.                 end
  38.             end
  39.         else
  40.             printf("%sCombustivel restante: %s", prefix, restante)
  41.             suficiente = true
  42.             break
  43.         end
  44.     end
  45.     return suficiente
  46.  
  47. end
  48.  
  49.  
  50. local function walk()
  51.     if canmovef ~= true then digf() end
  52.     movef()
  53.     combustivel()
  54. end
  55.  
  56.  
  57. local function godown()
  58.     if canmoved ~= true then digd() end
  59.     moved()
  60.     combustivel()
  61. end
  62.  
  63.  
  64. local function walkline(x)
  65.     for i=1, x do walk() end
  66. end
  67.  
  68.  
  69. local function turnline(direction)
  70.     if direction == 1 then
  71.         lookr()
  72.         walk()
  73.         lookr()
  74.     end
  75.     if direction == 2 then
  76.         lookl()
  77.         walk()
  78.         lookl()
  79.     end
  80. end
  81.  
  82.  
  83. local function walk2d(x, y, layersmoved)
  84.     local linesmoved = 1
  85.  
  86.     for i=2, y do
  87.  
  88.         if linesmoved == 1 then
  89.             walkline(x)
  90.             linesmoved = linesmoved + 1
  91.         end
  92.  
  93.         if (y % 2) ~= 0 then
  94.             if (linesmoved % 2) == 0 then
  95.                 turnline(1)
  96.                 walkline(x - 1)
  97.                 linesmoved = linesmoved + 1
  98.             else
  99.                 turnline(2)
  100.                 walkline(x - 1)
  101.                 linesmoved = linesmoved + 1
  102.             end
  103.         end
  104.  
  105.         if (y % 2) == 0 then
  106.  
  107.             if layersmoved == 1 then
  108.                 if (linesmoved % 2) == 0 then
  109.                     turnline(1)
  110.                     walkline(x - 1)
  111.                     linesmoved = linesmoved + 1
  112.                 else
  113.                     turnline(2)
  114.                     walkline(x - 1)
  115.                     linesmoved = linesmoved + 1
  116.                 end
  117.             end
  118.  
  119.             if (layersmoved % 2) == 0 then
  120.                 if (linesmoved % 2) == 0 then
  121.                     turnline(2)
  122.                     walkline(x - 1)
  123.                     linesmoved = linesmoved + 1
  124.                 else
  125.                     turnline(1)
  126.                     walkline(x - 1)
  127.                     linesmoved = linesmoved + 1
  128.                 end
  129.             end
  130.  
  131.  
  132.         end
  133.  
  134.     end
  135. end
  136.  
  137.  
  138. local function walk3d(x, y, z)
  139.  
  140.     local layersmoved = 1
  141.  
  142.     for i=1, z do
  143.         walk2d(x, y, layersmoved)
  144.         layersmoved = layersmoved + 1
  145.         walk()
  146.         lookl()
  147.         lookl()
  148.         godown()
  149.     end
  150.    
  151. end
  152.  
  153.  
  154. print(prefix .. "Digite a area para ser minerada: ")
  155. local a = tonumber(read())
  156. local b = tonumber(read())
  157. local c = tonumber(read())
  158.  
  159. walk3d(a, b, c)
  160. print(prefix .. "A area foi minerada.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement