Skip to content

Instantly share code, notes, and snippets.

@dillmo
Last active August 29, 2015 13:56
Show Gist options
  • Save dillmo/9100578 to your computer and use it in GitHub Desktop.
Save dillmo/9100578 to your computer and use it in GitHub Desktop.
A ComputerCraft program to dig a hole of your desired dimensions and place ladders along the way
-- Hole Digger by dillmo --
--[[
This program will dig a hole of your description and place ladders for
you. To begin with, place your mining turtle in the bottom left corner of
your hole. Be sure to place ladders in slot one of your turtle's
inventory and specify configuration variables before beginning.
--]]
-- Configuration --
local current_height = 70 -- The current y value of your turtle. This should be
-- the y value of your feet, not your head.
local desired_height = 67 -- The y value you want to dig down to.
local length = 4 -- The length of your hole. Your turtle is facing
-- this way.
local width = 5 -- The width of your hole. This should be
-- perpendicular to the direction your turtle is
-- facing.
-- Function Definitions --
local function turnAround()
turtle.turnRight()
turtle.turnRight()
end
-- Program --
for i = desired_height, current_height - 1 do
if width % 2 == 0 then
middle_of_width = width / 2
else
middle_of_width = width / 2 + 0.5
end
turtle.digDown()
turtle.down()
for i2 = 1, width do
if i2 == middle_of_width then
for i3 = 2, length do
turtle.dig()
turtle.forward()
end
turnAround()
for i3 = 3, length do
turtle.forward()
end
turtle.select(1)
turtle.place()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turnAround()
else
for i3 = 2, length do
turtle.dig()
turtle.forward()
end
turnAround()
for i3 = 2, length do
turtle.forward()
end
turnAround()
if i2 < width then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
end
if i2 == width then
turtle.forward()
turtle.turnLeft()
for i3 = 2, width do
turtle.forward()
end
turtle.turnLeft()
turtle.forward()
turnAround()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment