Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Created August 4, 2012 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjsingleton/3253903 to your computer and use it in GitHub Desktop.
Save tjsingleton/3253903 to your computer and use it in GitHub Desktop.
makes the turtle dig a cube
turn_right = true
function dig_forward()
turtle.dig()
turtle.forward()
end
function dig_down()
turtle.digDown()
turtle.down()
end
function next_row_and_dig()
if turn_right then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turn_right = false
else
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turn_right = true
end
end
function dig_row(length)
local times_dug = 0
repeat
dig_forward()
times_dug = times_dug + 1
until times_dug == length
end
function turn_around()
turtle.turnLeft()
turtle.turnLeft()
end
function down_level()
dig_down()
turn_around()
end
function up_level()
turtle.up()
turn_around()
end
function dig_rectangle(length, width)
local rows_dug = 0
repeat
dig_row(length)
rows_dug = rows_dug + 1
if rows_dug < width then
next_row_and_dig()
end
until rows_dug == width
end
function dig_cube(length, width, height)
local levels_dug = 0
repeat
dig_rectangle(length, width)
levels_dug = levels_dug + 1
if levels_dug < height then
down_level()
end
until levels_dug == height
end
function fill_forward()
turtle.placeDown()
turtle.forward()
end
function fill_row(length)
local times_dug = 0
repeat
fill_forward()
times_dug = times_dug + 1
until times_dug == length
end
function next_row_and_fill()
if turn_right then
turtle.turnRight()
turtle.placeDown()
turtle.forward()
turtle.turnRight()
turn_right = false
else
turtle.turnLeft()
turtle.placeDown()
turtle.forward()
turtle.turnLeft()
turn_right = true
end
end
function fill_rectangle(length, width)
local rows_dug = 0
repeat
fill_row(length)
rows_dug = rows_dug + 1
if rows_dug < width then
next_row_and_fill()
end
until rows_dug == width
end
function fill_cube(length, width, height)
local levels_dug = 0
repeat
fill_rectangle(length, width)
levels_dug = levels_dug + 1
if levels_dug < height then
up_level()
end
until levels_dug == height
end
function build_rect_wall(length, width, height)
local levels_built = 0
repeat
fill_row(length)
turtle.turnRight()
fill_row(width)
turtle.turnRight()
fill_row(length)
turtle.turnRight()
fill_row(width)
turtle.placeDown() -- we run into the wall we just built
turtle.up()
turtle.forward()
turtle.turnRight()
levels_built = levels_built + 1
until levels_built == height
end
function strafe_left()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
function strafe_right()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
build_rect_wall(5,5,5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment