Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sLight = ""
- sFloor = ""
- function MoveBack()
- while not turtle.back() do
- print("Cant move back, attempting to clear...")
- TurnAround()
- ClearAhead()
- TurnAround()
- end
- end
- function ClearAhead()
- while turtle.detect() do
- print("Found obstruction, removing...")
- turtle.dig()
- sleep(1)
- end
- local iCount = 0
- while turtle.attack() do
- if iCount % 5 == 0 then
- print("Found mob in path, removing...")
- end
- iCount = iCount + 1
- end
- end
- function TurnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function PlaceFloor()
- while not GetFloor() do
- print("Cant find floor object, waiting for more...")
- sleep(5)
- end
- local bSuccess, oBlockData = turtle.inspectDown()
- if bSuccess then
- if oBlockData.name == sFloor then
- --found flooring already in place, skipping
- else
- if turtle.digDown() then
- while not turtle.placeDown() do
- print("Cant place floor, need help!")
- sleep(5)
- end
- else
- print("Cant replace flooring, skipping...")
- end
- end
- else
- while not turtle.placeDown() do
- print("Cant place floor, need help!")
- sleep(5)
- end
- end
- end
- function PlaceLight()
- while not GetLight() do
- print("Cant find light object, waiting for more...")
- sleep(5)
- end
- while not turtle.place() do
- print("Cant place light, clearing...")
- ClearAhead()
- end
- end
- function GetItemTypes()
- local oItemDetails
- if turtle.getItemCount(1) > 0 then
- oItemDetails = turtle.getItemDetail(1)
- sLight = oItemDetails.name
- end
- if turtle.getItemCount(2) > 0 then
- oItemDetails = turtle.getItemDetail(2)
- sFloor = oItemDetails.name
- end
- if sLight == "" or sFloor == "" then
- return false
- else
- return true
- end
- end
- function GetLight()
- local oItemDetails
- local bFound = false
- local iSlot = 1
- while not bFound and iSlot <= 16 do
- if turtle.getItemCount(iSlot) > 0 then
- oItemDetails = turtle.getItemDetail(iSlot)
- if oItemDetails.name == sLight then
- bFound = true
- turtle.select(iSlot)
- else
- iSlot = iSlot + 1
- end
- else
- iSlot = iSlot + 1
- end
- end
- return bFound
- end
- function GetFloor()
- local oItemDetails
- local bFound = false
- local iSlot = 1
- while not bFound and iSlot <= 16 do
- if turtle.getItemCount(iSlot) > 0 then
- oItemDetails = turtle.getItemDetail(iSlot)
- if oItemDetails.name == sFloor then
- bFound = true
- turtle.select(iSlot)
- else
- iSlot = iSlot + 1
- end
- else
- iSlot = iSlot + 1
- end
- end
- return bFound
- end
- function CalcLight(a,b)
- if (b % 4) == 0 then
- if (b % 8) == 0 then
- if (a % 7) == 0 then
- return true
- end
- else
- if ((a + 4) % 7) == 0 then
- return true
- end
- end
- end
- return false
- end
- function PrintHelp()
- print( "Usage: mkFloor <length> [<width>]" )
- print("")
- print( "<length> Must be a positive number." )
- print( " How far forward to go." )
- print( "<width> Optional. how far to the")
- print( " right to go. if left blank" )
- print( " default to <length>." )
- print("")
- print( "Place light objects in slot 1 and" )
- print( "flooring in slot 2, so the tutrle can" )
- print( "detect their details. All other slots" )
- print( "can contain anything else in any order." )
- end
- function TurnAtEnd(w)
- if w % 2 == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- local tArgs = { ... }
- if not (#tArgs >= 1) then
- PrintHelp()
- return
- end
- iLength = tonumber( tArgs[1] )
- if iLength < 1 then
- print( "Tunnel length must be positive" )
- return
- end
- iWidth = iLength
- if #tArgs > 1 then
- iWidth = tonumber( tArgs[2] )
- if iWidth < 1 then iWidth = iLength end
- end
- print("Making floor area: "..tostring(iLength).."x"..tostring(iWidth))
- if GetItemTypes() then
- TurnAround()
- for w = 0, (iWidth - 1) do
- for q = 0, (iLength - 2) do
- PlaceFloor()
- MoveBack()
- if CalcLight(q,w) then
- PlaceLight()
- end
- end
- if not (w == (iWidth - 1)) then
- TurnAtEnd(w)
- PlaceFloor()
- MoveBack()
- if (w % 4) == 0 then
- PlaceLight()
- end
- TurnAtEnd(w)
- end
- end
- PlaceFloor()
- else
- print("Error: Cant find lights or flooring")
- print("")
- PrintHelp()
- end
Add Comment
Please, Sign In to add comment