Created
March 12, 2013 01:55
-
-
Save NelsonMinar/5139658 to your computer and use it in GitHub Desktop.
Minecraft turtle program to make tubes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Build a tube, a safe passage for someone to move (as through the Nether) | |
-- Usage: "tube N", where N is the number of squares forward to build the tube | |
-- Fuel goes in slot 16 | |
-- Torches in slot 15 | |
-- Building materials in 1-14 | |
-- Utility function: refuel, move forward, dig out if necessary | |
function go(dig) | |
-- refuel | |
if turtle.getFuelLevel() < 5 then | |
turtle.select(16) | |
turtle.refuel(1) | |
end | |
-- dig forward if necessary | |
while (dig and turtle.detect()) do | |
turtle.dig() | |
sleep(0.5) | |
end | |
-- move forward | |
local moveSucceeded = turtle.forward() | |
-- dig up if necessary | |
while (dig and turtle.detectUp()) do | |
turtle.digUp() | |
sleep(0.5) | |
end | |
return moveSucceeded | |
end | |
-- Drop a torch | |
function torch() | |
turtle.select(15) | |
turtle.turnRight() | |
turtle.turnRight() | |
turtle.place() | |
turtle.turnLeft() | |
turtle.turnLeft() | |
end | |
-- select a slot that has some stone in it | |
function selectStone() | |
local slot | |
for i=1,14 do | |
turtle.select(i) | |
if turtle.getItemCount(i) > 0 then | |
slot = i | |
break | |
end | |
end | |
return turtle.getItemCount(slot) > 0 | |
end | |
-- Place stones to left and right of turtle | |
function placeLeftRight() | |
selectStone() | |
turtle.turnLeft() | |
turtle.place() | |
selectStone() | |
turtle.turnRight() | |
turtle.turnRight() | |
turtle.place() | |
turtle.turnLeft() | |
end | |
-- Place a ring of stones around the tube where the turtle is | |
function place() | |
-- Place bottom part | |
selectStone() | |
turtle.placeDown() | |
placeLeftRight() | |
-- Place top part | |
turtle.up() | |
selectStone() | |
turtle.placeUp() | |
placeLeftRight() | |
turtle.down() | |
end | |
-- Parse command line | |
args={...} | |
maxZ=tonumber(args[1]) | |
-- Move forward, digging and building the tube | |
for z=0,maxZ-1 do | |
go(true) | |
place() | |
end | |
-- Turn around and come home | |
turtle.turnRight() | |
turtle.turnRight() | |
torchIndex = 0 | |
for z=0,maxZ-1 do | |
go(false) | |
torchIndex = torchIndex + 1 | |
if (torchIndex % 15) == 1 then | |
torch() | |
end | |
end | |
turtle.turnRight() | |
turtle.turnRight() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment