Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ################################
- -- Obsidian/Stone Generator
- -- version 0.1b
- -- http://hevohevo.hatenablog.com/
- -- If you want to get not Cobble-stones but Stones,
- -- require a SilkTouch Mining Turtle by "More Turtles" mod.
- -- See the CC forum.
- -- http://www.computercraft.info/forums2/index.php?/topic/16465-mc164152-more-turtles-v112/
- -- ChangeLog:
- -- 0.1b. bugfix: calculate second/piece
- -- 0.1a. bugfix: generate stone with silktouch mining turtle
- -- How to use:
- -- 0. Download and install.
- -- > pastebin get ZknGLgxE obsigen
- -- 1. Build a facility: x_size=4, z_size=4, y_size=3
- -- > obsigen build
- -- 2a. Generate Obsidians (Insert redstones into a right-side chest before executing)
- -- > obsigen obsidian
- -- 2b. Generate Cobble-stones
- -- > obsigen cobble
- -- 2c. Generate Stones (requires a SilkTouch mining turtle and fuel)
- -- > obsigen stone
- -- config
- LAVA_SLOT = 1
- GET_BLOCK_SLOT = 2
- REDSTONE_SLOT = 3
- BLOCK_SLOT = 4
- GLASS_SLOT = 13
- WATER_SLOT = 14
- CHEST_SLOT = 15
- FUEL_SLOT = 16
- MIN_FUEL_LEVEL = 60
- DEFAULT_GENERATE_QTY = 64
- -- functions
- 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(0.5)
- 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
- function assertByErrorMsg(func, error_msg)
- local status, msg = func()
- if not status and msg == error_msg then
- assert(status, msg)
- end
- end
- function getBlock(_digFunc)
- local digFunc = _digFunc or turtle.dig
- turtle.select(GET_BLOCK_SLOT)
- digFunc()
- assertByErrorMsg(turtle.dropDown, "Inventory full")
- end
- function placeItem(slot, _place_func)
- local place_func = _place_func or turtle.place
- turtle.select(slot)
- place_func()
- end
- function placeLava(sec)
- turtle.select(LAVA_SLOT)
- turtle.placeUp()
- if sec and type(sec)=="number" then
- os.sleep(sec)
- turtle.placeUp()
- end
- end
- function switchWaterDirection(key)
- if key == "obsidian" then
- turtle.turnLeft()
- turtle.select(BLOCK_SLOT)
- turtle.dig()
- turtle.turnRight()
- getBlock()
- else
- turtle.turnLeft()
- placeItem(BLOCK_SLOT)
- turtle.turnRight()
- getBlock()
- end
- end
- function isInclude(tbl, value)
- local status = false
- for k,v in pairs(tbl) do
- if v == value then
- status = true
- break
- end
- end
- return status
- end
- local sTime = 0
- function generateStone(maxCount, digFunc)
- local count = 0
- placeLava()
- sTime = os.clock()
- while count < maxCount do
- local unDetect = 0
- if turtle.detect() then
- getBlock(digFunc)
- count = count + 1
- print(count,'/',maxCount,': ',(os.clock() - sTime)/count,' sec/piece')
- else
- unDetect = unDetect + 1
- os.sleep(0.1)
- end
- if unDetect > 20 then
- getBlock()
- unDetect = 0
- end
- end
- placeLava()
- end
- function generateObsidian()
- local count = 0
- local function suckRedstone()
- turtle.turnRight()
- turtle.select(REDSTONE_SLOT)
- local status = turtle.suck()
- turtle.turnLeft()
- return status
- end
- sTime = os.clock()
- while turtle.getItemCount(REDSTONE_SLOT) > 0 or suckRedstone() do
- while turtle.getItemCount(REDSTONE_SLOT) > 0 do
- getBlock()
- placeItem(REDSTONE_SLOT)
- placeLava(2.5)
- turtle.select(BLOCK_SLOT)
- turtle.placeUp()
- turtle.digUp()
- getBlock()
- count = count + 1
- print(count,': ',(os.clock() - sTime)/count,' sec/piece')
- end
- end
- return count
- end
- -- functions for building
- function fwdAndPlaceDown(slot, _count)
- local count = _count or 1
- for i=1, count do
- turtle.forward()
- turtle.select(slot)
- turtle.placeDown()
- end
- end
- function loop(n, func)
- for i=1,n do func() end
- end
- function goRight()
- turtle.turnRight()
- turtle.forward()
- end
- function goLeft()
- turtle.turnLeft()
- turtle.forward()
- end
- function build1()
- turtle.up()
- fwdAndPlaceDown(BLOCK_SLOT, 4)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 3)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 2)
- goLeft()
- turtle.turnLeft()
- fwdAndPlaceDown(CHEST_SLOT, 2)
- loop(2, goRight)
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- end
- function build2()
- turtle.up()
- placeItem(BLOCK_SLOT, turtle.placeDown)
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 3)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 3)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- fwdAndPlaceDown(CHEST_SLOT, 1)
- turtle.back()
- goRight()
- fwdAndPlaceDown(WATER_SLOT, 1)
- goLeft()
- end
- function build3()
- turtle.up()
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 3)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 3)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- fwdAndPlaceDown(GLASS_SLOT, 1)
- fwdAndPlaceDown(BLOCK_SLOT, 1)
- turtle.turnRight()
- fwdAndPlaceDown(BLOCK_SLOT, 2)
- turtle.turnRight()
- fwdAndPlaceDown(GLASS_SLOT, 2)
- loop(2, goRight)
- loop(2, turtle.down)
- loop(2, turtle.turnRight)
- end
- -- main
- local args = {...}
- local targets = "cobble"
- if args and isInclude({"build", "cobble", "obsidian", "stone"}, args[1]) then
- target = args[1]
- else
- print("program-name arg1 arg2")
- print(" arg1: build/cobble/obsidian/stone")
- print(" arg2: quantity (optional)")
- assert(false, "Invalid argument(s)")
- end
- if target == "build" then
- print('Start: ',target)
- waitForEnoughFuel(MIN_FUEL_LEVEL, FUEL_SLOT)
- waitForEnoughItems("40 Blocks", 40, BLOCK_SLOT)
- waitForEnoughItems("3 Glasses", 3, GLASS_SLOT)
- waitForEnoughItems("a Water-Bucket", 1, WATER_SLOT)
- waitForEnoughItems("3 Chests", 3, CHEST_SLOT)
- build1()
- build2()
- build3()
- else
- local maxCount = tonumber(args[2]) or DEFAULT_GENERATE_QTY
- waitForEnoughItems("a Lava-Bucket", 1, LAVA_SLOT)
- waitForEnoughItems("a BLOCK", 1, BLOCK_SLOT)
- switchWaterDirection(target)
- if target == 'stone' then
- print('Start: ',target,' ',maxCount)
- local p = peripheral.wrap("right")
- assert((p and p.digSilkTouch), "required: SilkTouch Turtle")
- waitForEnoughFuel(maxCount,FUEL_SLOT)
- generateStone(maxCount, p.digSilkTouch)
- elseif target == 'cobble' then
- print('Start: ',target,' ',maxCount)
- generateStone(maxCount, turtle.dig)
- elseif target == 'obsidian' then
- print('Start: ',target)
- maxCount = generateObsidian()
- end
- print('Generate ',target,': ',maxCount)
- if maxCount > 0 then
- print((os.clock() - sTime)/maxCount,'(sec/piece)')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement