Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local forwardStep = 0
- local continue = true
- local goHome = false
- local goBack = false
- local atHome = true
- --functions for Preparing Work--
- function refuel()
- turtle.select(16)
- turtle.refuel()
- turtle.select(1)
- end
- function getWindmills()
- for i=1,14 do
- turtle.select(i)
- if turtle.getItemCount() == 0 then
- turtle.suck(1)
- end
- end
- turtle.select(15)
- end
- function getCablesAndBlocks()
- turtle.turnRight()
- turtle.select(15)
- if turtle.getItemCount() >= 1 then
- if turtle.getItemDetail().name == "mekanism:transmitter" then
- turtle.suck(turtle.getItemSpace())
- else
- os.exit()
- end
- else turtle.suck(turtle.getItemSpace())
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(16)
- if turtle.getItemCount() >= 1 then
- if turtle.getItemDetail().name == "minecraft:quartz_block" then
- turtle.suck(turtle.getItemSpace())
- else
- os.exit()
- end
- else turtle.suck(turtle.getItemSpace())
- end
- turtle.turnRight()
- end
- --Functions for Work
- function goToStart()
- turtle.down()
- turtle.down()
- turtle.down()
- while not turtle.detect() do
- turtle.forward()
- end
- while not turtle.detectDown() do
- turtle.down()
- end
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.select(16)
- if not turtle.detectUp() then
- turtle.placeUp()
- end
- end
- function goBackInLine()
- turtle.turnLeft()
- turtle.turnLeft()
- while not turtle.detectUp() do
- turtle.forward()
- end
- end
- function returnToHome()
- goBackInLine()
- if turtle.detect() then
- local atReturnPoint = false
- turtle.turnLeft()
- while not atReturnPoint do
- turtle.forward()
- if not turtle.detectUp() then
- turtle.forward()
- else
- turtle.turnRight()
- if turtle.detect() then
- atReturnPoint = false
- turtle.turnLeft()
- else
- atReturnPoint = true
- end
- end
- end
- turtle.forward()
- turtle.forward()
- turtle.forward()
- while not turtle.detectUp() do turtle.up() end
- while not turtle.detect() do turtle.forward() end
- turtle.up()
- turtle.up()
- turtle.up()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- goHome = false
- end
- local function getCurrentTurbineSlot()
- for i=1,14 do
- turtle.select(i)
- if turtle.getItemCount() >= 1 then
- return i
- end
- end
- return 16
- end
- local function checkIfSufficientLeft()
- if getCurrentTurbineSlot() >= 15 then
- write("Not enough Wind generators. \nGoing to return Home\n")
- goHome = true
- return false
- else
- write("Enough Wind generators available.\n")
- goHome = false
- return true
- end
- end
- function placeTurbines()
- turtle.down()
- turtle.down()
- turtle.turnRight()
- turtle.select(16)
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.place()
- turtle.up()
- turtle.select(getCurrentTurbineSlot())
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(getCurrentTurbineSlot())
- turtle.place()
- turtle.turnLeft()
- turtle.up()
- turtle.select(15)
- turtle.placeDown()
- end
- function toNextStop()
- for i=1,4 do
- if not turtle.detectDown() then
- turtle.select(15)
- turtle.placeDown()
- end
- turtle.forward()
- end
- end
- function doLine()
- toNextStop()
- forwardStep = 1
- while forwardStep <=21 and not goHome do
- if not turtle.detectDown() then
- placeTurbines()
- end
- checkIfSufficientLeft()
- if not goHome then
- toNextStop()
- end
- forwardStep = forwardStep + 1
- end
- if forwardStep > 21 then
- goBack = true
- end
- end
- function operateNormal()
- write("Starting Operation\n")
- checkIfSufficientLeft() --sets goHome to true if not enough Windmills left
- if not goHome and not goBack then
- write("sufficient Windmills left\n")
- -- Checking if active Line is to be used (defined by block)
- if not turtle.detect() and not turtle.detectUp() then --if block is detected means line is closed
- write("line is not yet started\n")
- --Placing block left and right
- turtle.turnLeft()
- turtle.select(16)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- doLine()
- elseif not turtle.detect() and turtle.detectUp() then
- write("this line is already active. continuing\n")
- doLine()
- else
- write("this line is done. looking for other line\n")
- --Turtle goes to furthest Station Left until hitting Block
- turtle.turnLeft()
- while not turtle.detect() do
- toNextStop()
- end
- write("Found End. Checking if Active line\n")
- turtle.turnRight()
- if turtle.detect() then
- write("Line not active. Starting new Line. \n Building new Station\n")
- turtle.turnLeft()
- --Turtle makes new Station (Station = point from which line goes)
- turtle.dig()
- toNextStop()
- turtle.select(16)
- turtle.placeUp()
- turtle.place()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- --Turtle does new line
- doLine()
- else
- write("Active Line detected. Continuing\n")
- doLine()
- end
- end
- elseif goBack then
- write("going back to start of Lane,\n")
- goBackInLine()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(16)
- turtle.place()
- goBack = false
- elseif goHome then
- write("going Home.\n")
- returnToHome()
- getCablesAndBlocks()
- getWindmills()
- atHome = true
- continue = not redstone.getInput("back")
- if continue then
- goToStart()
- atHome = false
- end
- end
- end
- --Calls for preparing work--
- --Optional:
- --refuel()
- --Calls for Starting to Work
- while true do
- if atHome then
- continue = not redstone.getInput("back")
- if continue then
- getCablesAndBlocks()
- getWindmills()
- goToStart()
- end
- else
- continue = true
- end
- while continue do
- operateNormal()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement