You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
local robot = require("robot")
|
|
|
|
local torch = require("torch")
|
|
|
|
---Moves forward n blocks.
|
|
---Waits if there is an obstruction
|
|
---@param n number how many block to go forward
|
|
---@param mine boolean|nil whether to mine block to go through
|
|
---@param place_torches boolean|nil whether to place torches in intervals
|
|
local function forward(n, mine, place_torches)
|
|
for i = 1, n do
|
|
while true do
|
|
local result, error = robot.forward()
|
|
if result then
|
|
break
|
|
else
|
|
if mine and error == "solid" then
|
|
robot.swing()
|
|
else
|
|
print("Cannot move: " .. error)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- place a torch every 11 blocks to keep the tunnel lit
|
|
if i % 11 == 0 and place_torches then
|
|
torch.place_torch(nil)
|
|
end
|
|
end
|
|
end
|
|
|
|
---Move until it runs into a solid block.
|
|
---Waits if there is an entity obstrucion
|
|
---@return number n number of blocks moved.
|
|
local function forward_until_solid()
|
|
local moved = 0
|
|
while true do
|
|
local result, error = robot.forward()
|
|
if result then
|
|
moved = moved + 1
|
|
else
|
|
if error == "solid" then
|
|
return moved
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return {
|
|
forward = forward,
|
|
forward_until_solid = forward_until_solid,
|
|
}
|