Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin run FuQ3WvPs NJWn1GC5 pathBuilder
- -- config
- print ("Enter path width (must be odd): ")
- local pathWidth = tonumber(read())
- print ("\nEnter path length: ")
- local pathLength = tonumber(read())
- print ("\nPress Enter to start!")
- local start = read("")
- --local pathWidth = 3 -- has to be odd, but can be changed
- local placeTorchAt = 8
- --local pathLength = 32
- -- DONT CHANGE (JUST YET)
- local ceiling = true -- unused right now
- local wallHeight = 2 -- not variable yet
- local errorLv = 0
- local torches = turtle.getItemCount(1)
- local fuel = turtle.getItemCount(2)
- local maxFuel = fuel
- local torchType = turtle.getItemDetail(1).name
- local fuelType = turtle.getItemDetail(2).name
- local buildingBlockType = turtle.getItemDetail(3).name
- local distance = 0
- local buildSlot = 3
- function selectBuildingBlockSlot ()
- buildingMaterial = 0
- local maxMaterial = -1
- local maxSlot = 3
- for i = 3, 16, 1 do
- local det = turtle.getItemDetail(i)
- if det and det.name == buildingBlockType then
- if det.count > maxMaterial then maxSlot = i end
- buildingMaterial = buildingMaterial + det.count
- end
- end
- buildSlot = maxSlot
- if buildingMaterial <= ((pathWidth * 2) + (wallHeight * 2)) then
- print ("Not enough building material!\n")
- errorLv = 1
- end
- return buildSlot
- end
- function placeBlock (direction)
- if direction == "down" then
- local _, data = turtle.inspectDown()
- if data.name == buildingBlockType then return end
- while turtle.detectDown() do turtle.digDown() end
- checkSlot()
- if not turtle.placeDown() then
- turtle.select(selectBuildingBlockSlot())
- turtle.placeDown()
- end
- elseif direction == "up" then
- local _, data = turtle.inspectUp()
- if data.name == buildingBlockType then return end
- while turtle.detectUp() do turtle.digUp() end
- checkSlot()
- if not turtle.placeUp() then
- turtle.select(selectBuildingBlockSlot())
- turtle.placeUp()
- end
- else
- local _, data = turtle.inspect()
- if data.name == buildingBlockType then return end
- while turtle.detect() do turtle.dig() end
- checkSlot()
- if not turtle.place() then
- turtle.select(selectBuildingBlockSlot())
- turtle.place()
- end
- end
- end
- function checkInventory ()
- print ("Checking inventory...\n")
- torches = turtle.getItemCount(1)
- fuel = turtle.getItemCount(2)
- selectBuildingBlockSlot()
- print ("Torches: " .. tostring(torches) .. "\nFuel: " .. tostring(fuel) .. "\nBuilding Material: " .. tostring(buildingMaterial) .. "\n")
- if pathWidth > 1 and torches <= 1 or turtle.getItemDetail(1).name ~= torchType then
- print ("Not enough torches!\n")
- errorLv = 1
- end
- if turtle.getFuelLevel() <= distance and turtle.getItemDetail(2).name ~= fuelType then
- print ("Not enough fuel!\n")
- errorLv = 1
- end
- print ("Error Level: " .. tostring(errorLv) .. "\n")
- end
- function home ()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, distance, 1 do
- turtle.forward()
- end
- end
- function checkSlot ()
- if turtle.getItemCount(turtle.getSelectedSlot()) == 0 or turtle.getItemCount(turtle.getSelectedSlot()) > 0 and turtle.getItemDetail(turtle.getSelectedSlot()) ~= buildingBlockType then
- turtle.select(selectBuildingBlockSlot())
- end
- end
- function run ()
- print ("Starting Program...\n")
- while (true) do
- checkInventory ()
- if errorLv ~= 0 or distance >= pathLength then
- home()
- return
- end
- -- Refuel
- if turtle.getFuelLevel() == 0 then
- turtle.select(2)
- turtle.refuel()
- end
- -- Dig width
- --print ("dig width\n")
- turtle.select(selectBuildingBlockSlot())
- while turtle.detectUp() do
- turtle.digUp()
- end
- placeBlock("down")
- -- right side
- --print ("right side\n")
- turtle.turnRight()
- for i = 1, (pathWidth - 1) / 2, 1 do
- while not turtle.forward() do
- turtle.dig()
- end
- placeBlock("down")
- end
- placeBlock()
- while not turtle.up() do
- turtle.digUp()
- end
- placeBlock("up")
- placeBlock()
- -- check if torch should be placed
- if pathWidth > 1 and distance % placeTorchAt == 0 then
- turtle.select(1)
- turtle.placeDown()
- turtle.select(selectBuildingBlockSlot())
- end
- -- go back
- --print ("go back\n")
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, (pathWidth - 1) / 2, 1 do
- while not turtle.forward() do
- turtle.dig()
- end
- placeBlock ("up")
- end
- -- left side
- --print ("left side\n")
- for i = 1, (pathWidth - 1) / 2, 1 do
- while not turtle.forward() do
- turtle.dig()
- end
- placeBlock("up")
- end
- placeBlock()
- while not turtle.down() do
- turtle.digDown()
- end
- placeBlock("down")
- placeBlock()
- -- go back
- --print ("go back 2\n")
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, (pathWidth - 1) / 2, 1 do
- while not turtle.forward() do
- turtle.dig()
- end
- if i < ((pathWidth - 1) / 2) then
- placeBlock("down")
- end
- end
- --print ("Turn left\n")
- turtle.turnLeft()
- -- Move forward
- --print ("move forward\n")
- while not turtle.forward() do
- turtle.dig()
- end
- distance = distance + 1
- print ("Current distance: " .. tostring(distance) .. " / " .. tostring(pathLength) .. "\n")
- end
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement