
clear
By: a guest on
May 5th, 2012 | syntax:
Lua | size: 2.86 KB | hits: 12 | expires: Never
local origin = {0,0,0}
local max = {72,2,144}
local dir = 0;
local modX = {0,1,0,-1}
local modZ = {-1,0,1,0}
local location = {0,0,0}
function turnAround()
right()
right()
end
function right()
dir = dir + 1 % 4
end
function left()
dir = dir - 1
if dir < 0 then
dir = 0
end
function down(dig=false)
while true do
if turtle.down() then
break
end
if turtle.detectDown() then
if dig then
turtle.digDown()
end
end
sleep(0)
end
location[1]=location[1]-1
end
function up(dig=false)
while true do
if turtle.up() then
break
end
if dig then
if turtle.detectUp() then
turtle.digUp()
end
end
sleep(0)
end
location[2] = location[2] + 1
end
function forward(dig=false)
while true do
if turtle.forward() then
break
end
if turtle.detect() then
if dig then
turtle.dig()
end
end
sleep(0)
end
location[1] = location[1] + modX[dir];
location[3] = location[3] + modZ[dir];
end
function back()
while true do
if turtle.back() then
break
end
if dig then
turnAround()
if turlte.detect() then
turtle.dig()
end
turnAround()
end
sleep(0)
end
location[1] = location[1]+modX[dir];
location[3] = location[3]+modZ[dir];
end
function getLocCopy()
local copy = {}
for i,n in ipairs(location) do
copy[i]=n
end
return copy;
end
function checkInventory()
if turtle.getItemCount(9> > 0 then
return true
end
return false
end
function dropOff(x,y,z)
local org = getLocCopy()
if z%2 == 1 then
left()
forward()
right()
end
while not dir==2 do
left()
sleep(0)
end
while not location[3] == origin[3]
forward()
sleep(0)
end
if not location[1] == origin[1] then
local left = false
if location[1] <0 then
left()
left = ture
end
elseif location[1]>0 then
right()
end
while not location[1] == origin[1]
forward()
sleep(0)
end
if left then
right()
else
left()
end
end
forward()
forward()
dropAll()
turnAround()
forward()
forward()
end
function dropAll()
for i=1,9,1 do
turtle.select(i)
if turtle.getItemCount(i) >0 then
turtle.drop(turtle.getItemCount(i);
end
end
end
local in = ""
while not in == "start" do
in = io.read()
sleep(0)
end
local location = {0,0,0}
for x=0,max[1],1 do
for z=0,max[2],1 do
for y=1,max[3],1 do
up(true);
checkInventory()
down(false);
end
forward(true);
checkInventory()
end
left()
forward(true)
left()
back(true)
checkInventory()
end