-- #############################
-- seichi
-- version 0.2b
-- http://hevohevo.hatenablog.com/
-- #############################
-- config (default parameters)
DEPTH = 4 -- okuyuki
WIDTH =4 -- haba
HEIGHT = 4 -- takasa
-- #############################
-- functions
function surelyDigUp()
while turtle.digUp() do
os.sleep(0.4)
end
end
function surelyUp()
surelyDigUp()
return turtle.up()
end
function surelyDig()
while turtle.dig() do end
end
function surelyFwd()
for i=1,4 do
local status, err = turtle.forward()
if status then
return true -- success!
elseif err=="Out of fuel" then
return status, err
end
surelyDig() -- face to a normal block or a sand(gravel) hill
if turtle.detect() and not turtle.dig() then
return false, "bedrock!"
end
if turtle.forward() then return true end -- success!
if turtle.attack() then
-- face to monster-mob
while turtle.attack() do end
else
-- face to sand-blocks which is dropping long time
os.sleep(5) -- probably, adjustment is required
end
end
return turtle.forward()
end
function seichiThreeStep()
for i=1,HEIGHT-1 do
surelyUp()
end
surelyFwd()
for i=1,HEIGHT-1 do
surelyDig()
turtle.digDown()
turtle.down()
end
surelyFwd()
end
function seichiTwoStep()
for i=1,HEIGHT-1 do
surelyUp()
end
surelyFwd()
for i=1,HEIGHT-1 do
turtle.digDown()
turtle.down()
end
end
function seichiOneStep()
for i=1,HEIGHT-1 do
surelyUp()
end
for i=1,HEIGHT-1 do
turtle.down()
end
end
function seichiOneLine(d)
local d = d or DEPTH
for i=1, d/3 do
seichiThreeStep()
if i<(d/3) then surelyFwd() end
end
if d%3==1 then
seichiOneStep()
elseif d%3==2 then
seichiTwoStep()
end
end
function countAllItems()
local count = 0
for i=1,16 do
count = count+turtle.getItemCount(i)
end
return count
end
-- #############################
-- main
-- arguments setting
local args = {...}
if #args ~= 3 and #args ~=0 then error(\'seichi <DEPTH> <WIDTH> <HEIGHT>\') end
DEPTH = tonumber(args[1]) or DEPTH
WIDTH = tonumber(args[2]) or WIDTH
HEIGHT = tonumber(args[3]) or HEIGHT
print(string.format("D/W/H = %d/%d/%d", DEPTH, WIDTH, HEIGHT))
-- fuel check
local requiredFuelLevel = DEPTH*WIDTH*HEIGHT -- a rough estimate
if requiredFuelLevel > turtle.getFuelLevel() then
error(\'Not enough Fuel: \',turtle.getFuelLevel(),\'/\',requiredFUelLevel)
else
print(\'currnet/required = \',turtle.getFuelLevel(),\'/\',requiredFuelLevel)
end
-- start
local num_item = countAllItems() -- store qty of items
surelyFwd()
for w= 1,WIDTH do
seichiOneLine()
if WIDTH>w and w%2 == 1 then -- current width pos is odd number
turtle.turnRight()
surelyFwd()
turtle.turnRight()
elseif WIDTH>w and w%2 == 0 then -- current width pos is even number
turtle.turnLeft()
surelyFwd()
turtle.turnLeft()
end
end
print("current fuel: ",turtle.getFuelLevel())
print("acquired items: ", countAllItems()-num_item) -- calc qty of acquired items