local shell = require("shell")
local robot = require("robot")
local sides = require("sides")
local args, ops = shell.parse(...)
local distance = {}
distance.x = tonumber(args[1])
distance.y = tonumber(args[2])
distance.z = tonumber(args[3])
local gone = {}
gone.x = 0
gone.y = 0
gone.z = 0
local slots = robot.inventorySize()
local chest_slot = slots
-- Mine the block in front of the robot.
function mineForward()
local blocked, type = robot.detect()
while (blocked) do
robot.swing()
blocked, type = robot.detect()
end
end
-- Mine the block below the robot.
function mineDown()
local blocked, type = robot.detectDown()
while (blocked) do
robot.swingDown()
blocked, type = robot.detectDown()
end
end
-- Dump inventory into the ender chest.
function dump(side)
robot.select(chest_slot)
if (side == sides.back) then
robot.turnAround()
robot.place()
else
robot.placeUp()
end
local pos = 1
while (pos <= slots) do
robot.select(pos)
if (side == sides.back) then
robot.drop()
else
robot.dropUp()
end
pos = pos + 1
end
if (side == sides.back) then
robot.swing()
robot.turnAround()
else
robot.swingUp()
end
end
-- Assume full if the last slot is non-empty.
function isFull()
return robot.count(slots - 1) > 0
end
-- Dump if full.
function maybeDump(side)
if (isFull()) then dump(side) end
end
-- Move forward one block.
function moveForward()
mineForward()
robot.forward()
maybeDump(sides.back)
end
-- Move down one block.
function moveDown()
mineDown()
robot.down()
maybeDump(sides.top)
end
-- Main loop.
function main()
while (gone.z < distance.z) do
while (gone.x < distance.x) do
if (gone.x ~= 0) then
if (gone.x % 2 == 0) then
robot.turnLeft()
moveForward()
robot.turnLeft()
else
robot.turnRight()
moveForward()
robot.turnRight()
end
end
while (gone.y < distance.y) do
moveForward()
gone.y = gone.y + 1
end
gone.y = 0
gone.x = gone.x + 1
end
moveDown()
robot.turnAround()
gone.y = 0
gone.x = 0
gone.z = gone.z + 1
end
end
main()
dump()
Comments
0 B
|👍
/👎