Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #################################
- -- Obsidian/CobbleStone Generator with a Mining Turtle
- -- version 0.2
- -- http://hevohevo.hatenablog.com/
- -- Install
- -- > pastebin get fSLALH2v obsigen
- -- First, Use command to build a facility
- -- The facility size is x=3, y=4, z=5.
- -- > obsigen build
- -- Already exists.
- -- > obsigen cobble
- -- > obsigen obsidian
- -- config
- BLOCK = 13
- CHEST = 14
- WATER = 15
- FUEL = 16
- MIN_FUEL_LEVEL = 40
- REDSTONE = 1
- LAVE = 2
- GET_BLOCK = 3
- function placeLave()
- turtle.select(LAVE)
- turtle.place()
- os.sleep(3)
- turtle.place()
- end
- function digBlock()
- turtle.select(GET_BLOCK)
- return turtle.digDown() and assert(turtle.dropUp())
- end
- function init()
- digBlock()
- 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(GET_BLOCK)
- turtle.turnRight()
- turtle.dig()
- loop(2, turtle.turnRight)
- turtle.dig()
- turtle.turnRight()
- turtle.dropUp()
- end
- -- main
- local mode = false
- local args = {...}
- if args and args[1] == 'build' then
- mode = 'build'
- waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL)
- waitForEnoughItems("26 Blocks", 26, BLOCK)
- waitForEnoughItems("a Chest", 1, CHEST)
- waitForEnoughItems("a Water-Bucket", 1, WATER)
- print("Building Start!")
- build()
- build2()
- build3()
- print("Building Finished!")
- elseif args and args[1] == 'obsidian' then
- mode = 'obsidian'
- waitForEnoughItems("some Redstone(s)", 1, REDSTONE)
- waitForEnoughItems("a Lave-Bucket", 1, LAVE)
- init()
- local numRs = turtle.getItemCount(REDSTONE)
- print("I try to craft ",numRs," obsidian(s).")
- for i=1, numRs do
- placeRedstone()
- placeLave()
- if digBlock() then print(i) end
- end
- elseif args and args[1] == 'cobble' then
- waitForEnoughItems("a Lave-Bucket", 1, LAVE)
- init()
- turtle.select(LAVE)
- turtle.place()
- local num = 0
- while true do
- if digBlock() then
- num = num + 1
- end
- print(num)
- os.sleep(1)
- end
- else
- print("Need an argument:")
- print("> obsigen <build | cobble| obsidian>")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement