Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require "component"
- local computer = require "computer"
- local generator = component.generator
- local term = require "term"
- local robot = require "robot"
- local sides = require "sides"
- local ISGENERATOR = component.isAvailable("generator")
- local TORCHSLOT = 1
- local SECTIONENERGY
- local SUBTUNNELLENGTH, SECTIONLENGTH --TODO
- local energy = computer.energy()
- local function detect(type, direction) --Обнаружение определенноо типа [направления] роботом. Возвращает boolean.
- local detection
- if direction == "up" then detection = select(2, robot.detectUp())
- elseif direction == "down" then detection = select(2, robot.detectDown())
- else
- detection = select(2, robot.detect())
- end
- if detection == type then
- return true
- end
- end
- local function unloading() --TODO
- robot.turnAround()
- for i = 4, 16 do
- robot.select(i)
- robot.drop()
- end
- robot.turnAround()
- end
- local function gen(slot) --TODO
- if math.floor(computer.energy()) <= 200000 and generator.count() == 0 then
- robot.select(slot)
- generator.insert()
- end
- --while generator.count() ~= 0 do os.sleep(1) end
- end
- local function checkEnergy(sectCount)
- if math.floor(computer.energy()) <= 1000*sectCount + SECTIONENERGY then
- while math.floor(computer.energy()) <= 1000*sectCount + SECTIONENERGY + 30000 do
- print(math.floor(computer.energy()))
- os.sleep(20)
- end
- end
- end
- local function placeBlock(types, slot, direction)
- robot.select(slot)
- for _, type in pairs(types) do
- if detect(type,direction) then
- if direction == "up" then
- robot.placeUp()
- elseif direction == "down"then
- robot.placeDown()
- else robot.place()
- end
- end
- end
- end
- local function killLiquid(slot)
- types = {"liquid", "replaceable"}
- placeBlock(types, slot, "up")
- placeBlock(types, slot,"down")
- placeBlock(types, slot)
- robot.turnRight()
- placeBlock(types, slot)
- robot.turnAround()
- placeBlock(types, slot)
- robot.turnRight()
- end
- function placeTorch()
- robot.turnAround()
- robot.select(TORCHSLOT)
- robot.place()
- robot.turnAround()
- end
- local function tunnel(numSteps, height, isBack) --REFACTOR!!
- local types = {"air", "liquid", "replaceable"}
- for i = 1, numSteps do
- if robot.durability() == nil then
- print("Place pickaxe and input something")
- term.read()
- end
- while robot.detect() do robot.swing() end
- robot.forward()
- if not isBack then placeBlock(types, 2, "down") end
- if (i%13 == 0 or i == 2) and height > 1 then placeTorch() end
- for i = 1, height-1 do
- while robot.detectUp() do robot.swingUp() end
- robot.up()
- end
- for i = 1, height-1 do
- while robot.detectDown() do robot.swingDown() end
- robot.down()
- end
- end
- end
- local function section(length)
- local function subTunnels(length)
- robot.turnLeft()
- tunnel(length,1)
- robot.turnAround()
- tunnel(length,1,true)
- tunnel(length,1)
- robot.turnAround()
- tunnel(length,1,true)
- robot.turnRight()
- end
- tunnel(length, 2)
- placeTorch()
- robot.up()
- robot.turnAround()
- local count = math.floor(length/4)
- repeat
- subTunnels(5)
- tunnel(4, 1, true)
- count = count - 1
- until count == 0
- robot.turnAround()
- robot.down()
- end
- local function miner(sectionCount,sectionLength)
- SECTIONENERGY = computer.energy()
- gen(3)
- section(sectionLength)
- unloading()
- SECTIONENERGY = SECTIONENERGY - computer.energy() + 1000
- for i = 1, sectionCount do
- robot.turnLeft()
- tunnel(11*i, 2)
- robot.turnRight()
- section(sectionLength)
- robot.up()
- robot.turnRight()
- tunnel(11*i, 1, true)
- robot.turnLeft()
- robot.down()
- unloading()
- checkEnergy(i)
- end
- end
- term.clear()
- print("Input section count: ")
- local secCount = term.read()
- print("Input section length: ")
- local secLength = term.read()
- print('Start energy: '..energy)
- miner(secCount,secLength)
- print('Energy used : ' .. math.floor(energy - computer.energy()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement