Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuel = {}
- fuel['chest'] = 1
- fuel['material'] = 2
- local fill = {}
- fill['chest'] = 3
- fill['material'] = 4
- local loot = {}
- loot['chest'] = 5
- loot['material'] = 6
- loot['lastItem'] = true
- local firstSlot = 6
- local function placeChest(item)
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.detect() then
- error("Block behind us")
- end
- turtle.select(item.chest)
- if turtle.place() == false then
- error("Failed to place chest from slot " .. item.chest)
- end
- end
- local function getChest(item)
- turtle.select(item.chest)
- if turtle.dig() == false then
- error("Failed to retreive chest to slot " .. item.chest)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- local function unload(item)
- placeChest(item)
- if item.lastItem then
- for n=item.material,16 do
- turtle.select(n)
- turtle.drop()
- end
- else
- turtle.select(item.material)
- turtle.drop()
- end
- getChest(item)
- end
- local function reload(item)
- placeChest(item)
- turtle.select(item.material)
- while turtle.getItemSpace() > 0 do
- if turtle.suck(turtle.getItemSpace()) == false then
- error("Couldn't get an item for slot " .. item.material)
- end
- end
- getChest(item)
- end
- local function refuel(item, fuelLimit)
- if fuelLimit == nil then
- fuelLimit = turtle.getFuelLimit()
- end
- while turtle.getFuelLevel() < fuelLimit do
- turtle.select(item.material)
- if turtle.getItemCount() > 1 then
- turtle.refuel(turtle.getItemCount() - 1)
- else
- reload(item)
- end
- end
- end
- local Item = {}
- Item["detect"] = {}
- Item["detect"]["forward"] = turtle.detect
- Item["detect"]["left"] = turtle.detect
- Item["detect"]["right"] = turtle.detect
- Item["detect"]["up"] = turtle.detectUp
- Item["detect"]["down"] = turtle.detectDown
- Item["place"] = {}
- Item["place"]["forward"] = turtle.place
- Item["place"]["left"] = turtle.place
- Item["place"]["right"] = turtle.place
- Item["place"]["up"] = turtle.placeUp
- Item["place"]["down"] = turtle.placeDown
- local function place(item, direction)
- turtle.select(item.material)
- if turtle.getItemCount() <= 1 then
- reload(item)
- end
- if direction == "left" then
- turtle.turnLeft()
- elseif direction == "right" then
- turtle.turnRight()
- end
- if Item["detect"][direction]() == false then
- if Item["place"][direction]() == false then
- error("Failed to place an item from slot " .. item.material)
- end
- end
- if direction == "left" then
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnLeft()
- end
- end
- local function isFull()
- for n=firstSlot,16 do
- if turtle.getItemCount(n) == 0 then
- --Empty slots
- return false;
- end
- end
- print( "No empty slots left." )
- return true;
- end
- local function forwards()
- if turtle.getFuelLimit() ~= 0 and turtle.getFuelLevel() < 10000 then
- refuel(fuel, 20000)
- end
- if isFull() then
- unload(loot)
- end
- turtle.select(loot.material)
- while not turtle.forward() do
- if not turtle.dig() then
- if turtle.attack() then
- -- Do Nothing
- else
- sleep( 0.5 )
- end
- end
- end
- return true
- end
- -----------------------------------------------------------------------------
- --Main Program
- -----------------------------------------------------------------------------
- local tArgs = { ... }
- if #tArgs < 1 then
- print( "My Version Usage: straight length [number]" )
- return
- end
- local length = tonumber( tArgs[1] )
- local turtleNumber
- if tArgs[2] ~= nil then
- turtleNumber = tonumber( tArgs[2] )
- else
- turtle = tonumber( os.getComputerLabel() )
- end
- print( "Tunneling..." )
- reload(fuel)
- reload(fill)
- --Tunnel forward filling in the edge
- for tunnelLength=1,length do
- print("Mining " .. tunnelLength .. " / " .. length)
- forwards()
- --Fill your edge
- if turtleNumber == 1 then
- place(fill, "up")
- place(fill, "left")
- elseif turtleNumber == 2 then
- place(fill, "up")
- elseif turtleNumber == 3 then
- place(fill, "up")
- place(fill, "right")
- elseif turtleNumber == 4 then
- place(fill, "left")
- elseif turtleNumber == 5 then
- -- Place Nothing
- elseif turtleNumber == 6 then
- place(fill, "right")
- elseif turtleNumber == 7 then
- place(fill, "down")
- place(fill, "left")
- elseif turtleNumber == 8 then
- place(fill, "down")
- elseif turtleNumber == 9 then
- place(fill, "right")
- place(fill, "down")
- end
- end
- print( "Emptying" )
- unload(fuel)
- unload(fill)
- unload(loot)
- print( "Done" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement