-- #################################
-- Obsidian Generator with a Mining Turtle
-- version 0.1a
-- http://hevohevo.hatenablog.com/
-- Use command, if you want to build a facility.
-- > obsidian_generator build
-- Already exists.
-- > obsidian_generator
-- The facility size is 3, 4, 5 (X,Y,Z)
BLOCK = 13
CHEST = 14
WATER = 15
FUEL = 16
MIN_FUEL_LEVEL = 40
REDSTONE = 1
LAVE = 2
OBSIDIAN = 3
function placeLave()
turtle.select(LAVE)
turtle.place()
os.sleep(3)
turtle.place()
end
function digObsidian()
turtle.select(OBSIDIAN)
turtle.digDown()
turtle.dropUp()
end
function placeRedstone()
turtle.select(REDSTONE)
turtle.placeDown()
end
function waitForEnoughItems(itemName, n, slot)
turtle.select(slot)
while turtle.getItemCount(slot) < n do
if itemName then print(string.format("Insert %s into slot %d",itemName,slot)) end
os.sleep(1)
os.pullEvent("turtle_inventory")
end
end
function waitForEnoughFuel(minLevel, slot)
local qty = 0
local refuel = function()
turtle.select(slot)
turtle.refuel()
qty = turtle.getFuelLevel()
print("fuel: ",qty)
return qty
end
while refuel() < minLevel do
print(string.format("Insert fuel-items into slot %d: %d/%d", slot, qty, minLevel))
os.sleep(1)
os.pullEvent("turtle_inventory")
end
end
-- functions to build
function loop(n,func)
for i=1,n do func() end
end
function placeDownForward()
turtle.placeDown()
turtle.forward()
end
function build()
turtle.select(BLOCK)
for y=1,3 do
turtle.up()
for i=1,2 do
turtle.forward()
loop(3, placeDownForward)
turtle.turnRight()
turtle.forward()
placeDownForward()
turtle.turnRight()
end
end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
loop(2, turtle.forward)
loop(3, turtle.down)
turtle.place()
turtle.up()
turtle.placeDown()
turtle.up()
end
function build2()
loop(2,turtle.turnRight)
turtle.select(WATER)
turtle.place()
loop(2,turtle.turnRight)
turtle.select(CHEST)
turtle.placeUp()
end
function build3()
turtle.select(OBSIDIAN)
turtle.turnRight()
turtle.dig()
loop(2, turtle.turnRight)
turtle.dig()
turtle.turnRight()
turtle.dropUp()
end
-- main
local args = {...}
if args and #args > 0 then
waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL)
waitForEnoughItems("26 Blocks", 26, BLOCK)
waitForEnoughItems("a Chest", 1, CHEST)
waitForEnoughItems("a Water-Bucket", 1, WATER)
end
waitForEnoughItems("some Redstone(s)", 1, REDSTONE)
waitForEnoughItems("a Lave-Bucket", 1, LAVE)
if args and #args > 0 then
print("Building Start!")
build()
build2()
build3()
print("Building Finished!")
end
local numRs = turtle.getItemCount(REDSTONE)
print("I try to craft ",numRs," obsidian(s).")
for i=1, numRs do
placeRedstone()
placeLave()
digObsidian()
end