Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs < 3 then -- No size and name
- print( "Usage: branch <length> <width> <block_names>" )
- return
- end
- local length = tonumber(tArgs[1])
- local width = tonumber(tArgs[2])
- local names = {}
- for i = 1, #tArgs - 2 do
- table.insert(names, tArgs[2+i])
- end
- function table.contains(table, element)
- for _, value in pairs(table) do
- if value == element then
- return true
- end
- end
- return false
- end
- function trash(names)
- for i = 1, 16 do
- turtle.select(i)
- local details = turtle.getItemDetail();
- if details ~= nil then
- if not table.contains(names, details.name) then
- turtle.drop()
- end
- end
- end
- end
- function branch(size, names)
- for i=1,size do
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- local success, data = turtle.inspect()
- if success then
- if table.contains(names, data.name) then
- turtle.dig()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- local success, data = turtle.inspect()
- if success then
- if table.contains(names, data.name) then
- turtle.dig()
- end
- end
- turtle.turnLeft()
- local success, data = turtle.inspectUp()
- if success then
- if table.contains(names, data.name) then
- turtle.digUp()
- end
- end
- local success, data = turtle.inspectDown()
- if success then
- if table.contains(names, data.name) then
- turtle.digDown()
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, size do
- turtle.dig()
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function getFuel( walked )
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1, walked do
- turtle.dig()
- turtle.forward()
- end
- turtle.select(16)
- local refueled = false
- while not refueled do
- if turtle.getItemDetail() == nil then
- turtle.suck()
- turtle.refuel()
- if turtle.getFuelLevel() == turtle.getFuelLimit() then
- turtle.drop()
- refueled = true
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1, walked do
- turtle.dig()
- turtle.forward()
- end
- end
- function lowFuel(walked, width)
- if turtle.getFuelLevel() < walked*3 + 2*3 + 2*width then
- getFuel(walked)
- end
- end
- function branchMine(length, width, names)
- for i=1,length do
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- branch(width, names)
- turtle.turnRight()
- turtle.turnRight()
- branch(width, names)
- turtle.turnLeft()
- lowFuel()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i=1,length do
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- print("Starting branch of "..length.." length, "..width.." width.")
- branchMine(length, width, names)
- print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement