Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- printError( "Requires a Turtle" )
- return
- end
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: sfb <length> <width> <material>" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- local length = tonumber( tArgs[1] )
- local width = tonumber( tArgs[2] )
- local material = tArgs[3]
- if length < 1 then
- print( "Floor length must be natural number" )
- return
- end
- if width < 1 then
- print( "Floor width must be natural number" )
- return
- end
- local depth = 0
- local item = 1
- local function count()
- length = length + 1
- if math.fmod(length, 10) == 0 then
- print( "Faced "..length.." section." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming floor building..." )
- end
- end
- local function charge()
- local function tryCharge()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- if turtle.getItemDetail(n).name == material then
- turtle.select(n)
- return true
- end
- end
- end
- turtle.select(2)
- return false
- end
- if not tryCharge() then
- print( "Add more material to continue." )
- while not tryCharge() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming floor building..." )
- end
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryPlaceDown()
- refuel()
- charge()
- while not turtle.detectDown() do
- if turtle.placeDown() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- print( "Building the floor..." )
- local function buildForward(dir)
- for n=1,dir do
- tryForward()
- tryPlaceDown()
- end
- end
- local frwDir = true;
- while (length > 0 or width > 0) do
- if frwDir == true then
- buildForward(length)
- width = width - 1
- frwDir = false
- else
- buildForward(width)
- length = length- 1
- frwDir = true
- end
- turtle.turnRight()
- end
- print( "Floor building complete" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement