-- #############################
-- seichi
-- version 0.3a
-- http://hevohevo.hatenablog.com/
-- > seichi 16 8 3
-- this means, depth=16, width=8, height=3
-- #############################
-- config (default parameters)
DEPTH = 4 -- okuyuki
WIDTH =4 -- haba
HEIGHT = 4 -- takasa
TOARCH_SLOT = 15
CHEST_SLOT = 16
-- #############################
-- 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
-- face to a normal block or a sand(gravel) hill
surelyDig()
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() -- run to get error msg
end
-- (digUP(); up()) * HEIGHT --> forward()
-- --> (dig(); digDown(); down()) * HEIGHT
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
-- (digUP(), up())*HEIGHT --> forward()
-- --> (digDown(), down()) * HEIGHT
function seichiTwoStep()
for i=1,HEIGHT-1 do
surelyUp()
end
surelyFwd()
for i=1,HEIGHT-1 do
turtle.digDown()
turtle.down()
end
end
-- (digUP(); up()) * HEIGHT --> down()*HEIGHT
function seichiOneStep()
for i=1,HEIGHT-1 do
surelyUp()
end
for i=1,HEIGHT-1 do
turtle.down()
end
end
-- use seichiThreeStep() as much as possible
function seichiOneLine(current_w)
local div3 = math.floor(DEPTH/3)
local mod3 = DEPTH%3
local current_d = 1
for i=1, div3 do
seichiThreeStep()
current_d = current_d + 2 -- seichiThreeStep() increase two depth
-- turn around and place() toarch, if needed
placeToarch(i, current_w)
-- placeUp() a chest and dropUp() items, if needed
putItemsInChest()
if current_d<DEPTH then
surelyFwd()
current_d = current_d + 1 -- surelyFwd() increase one depth
end
end
if mod3==1 then
seichiOneStep()
elseif mod3==2 then
seichiTwoStep()
end
end
-- placeItem(TOARCH_SLOT): place() TOARCH_SLOT\'s item
-- placeItem(CHEST_SLOT, turtle.placeUp): use placeUp()
function placeItem(slot, place_func)
local place_func = place_func or turtle.place
if turtle.getItemCount(slot)==0 then return false end
turtle.select(slot)
local status, error_msg = place_func()
turtle.select(1)
return status, error_msg
end
-- dropUp() items(slots 1-14)
function dropAllItems()
for i=1, 14 do
if turtle.getItemCount(i)>0 then
turtle.select(i)
turtle.dropUp()
end
end
turtle.select(1)
end
-- turn around and place() a toarch at regular spaces
-- default spaces are 5 blocks
function placeToarch(i, current_w)
if i%2==0 and current_w%6==1 and turtle.getItemCount(TOARCH_SLOT)>0 then
turtle.turnRight(); turtle.turnRight()
print(\'place a toarch: \', placeItem(TOARCH_SLOT))
turtle.turnRight(); turtle.turnRight()
end
end
-- if slot 12 has some items, placeUp() a chest and put items in it
function putItemsInChest()
if turtle.getItemCount(12)>0 then
if placeItem(CHEST_SLOT, turtle.placeUp) then
dropAllItems()
elseif turtle.getItemCount(14)>0 then
error("Inventory is full!")
end
end
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
surelyFwd()
for w= 1,WIDTH do
seichiOneLine(w)
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())