Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AskTorch()
- shell.run("clear")
- print "My name is Sebastian, I would be happy to serve you."
- print ("I have the strength to go ".. turtle.getFuelLevel().. " blocks today.")
- io.write "Would you like me to place torches as well? (y/n) "
- torchperm = io.read()
- if torchperm == "y" then
- print "If you have any torches, I would advise you to place them in my last slot,"
- if turtle.getItemCount(16) == 0 then
- print "but they do not seem to be there at the moment. Might I advise you to place them now?"
- print ""
- end
- end
- if torchperm ~= "y" then
- if torchperm ~= "n" then
- print ""
- print "Your commands are obscure. Could you repeat that please?"
- print ""
- end
- end
- return torchperm
- end
- function AskChest()
- io.write "Would you like me to empty out my inventory every so often? (y/n) "
- chestperm = io.read()
- if chestperm == "y" then
- print ""
- print "Please place chests in my second slot."
- print ""
- end
- if chestperm ~= "y" then
- if chestperm ~= "n" then
- print ""
- print "Your commands are obscure. Could you repeat that please?"
- print ""
- AskChest()
- end
- end
- return chestperm
- end
- function AskFuel()
- io.write "Would you like me to use fuel in my inventory to keep working? (y/n) "
- fuelperm = io.read()
- if fuelperm == "y" then
- print ""
- print "I will use them to your bidding."
- print ""
- end
- if fuelperm ~= "y" then
- if fuelperm ~= "n" then
- print ""
- print "Your commands are obscure. Could you repeat that please?"
- print ""
- AskFuel()
- end
- end
- return fuelperm
- end
- function AskSide()
- io.write "Shall I dig it to the right or to the left? "
- side = io.read()
- if side ~= "right" then
- if side ~= "left" then
- print ""
- print "Your commands are obscure. Could you repeat that please?"
- print ""
- AskSide()
- end
- end
- return side
- end
- function AskHeight()
- io.write "How high of a tunnel would you like me to dig? "
- height = io.read()
- if not tonumber(height) then
- print ""
- print "That is not a number."
- print ""
- AskHeight()
- else
- height = tonumber(height)
- end
- if height > 256 then
- print ""
- print "You give me impossible tasks."
- print ""
- AskHeight()
- end
- if height < 1 then
- print ""
- print "I'm afraid I can not dig that way."
- print ""
- AskHeight()
- end
- return height
- end
- function AskWidth()
- io.write "How wide would you like it to be? "
- width = io.read()
- if not tonumber(width) then
- print ""
- print "That is not a number."
- print ""
- AskWidth()
- else
- width = tonumber(width)
- end
- if width < 1 then
- print ""
- print "I'm afraid I can not dig that way. "
- print ""
- AskWidth()
- end
- return width
- end
- function AskLength()
- io.write "How long should the tunnel be dug? "
- length = io.read()
- if not tonumber(length) then
- print ""
- print "That is not a number."
- print ""
- AskLength()
- else
- length = tonumber(length)
- end
- if length < 1 then
- print ""
- print "I'm afraid I can not dig that way."
- print ""
- AskLength()
- end
- return length
- end
- function point()
- while not turtle.forward() do
- turtle.dig()
- end
- autofuel()
- end
- function line(width)
- p = 1
- while width > p do
- point()
- p = p + 1
- end
- end
- function raise()
- while not turtle.up() do
- turtle.digUp()
- end
- autofuel()
- end
- function drop()
- while not turtle.down() do
- turtle.digDown()
- end
- autofuel()
- end
- function degreeangle()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function layer()
- line(width)
- degreeangle()
- end
- function store()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- if torchperm == "y" then
- for slot = 3, 15 do
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- if torchperm ~= "y" then
- for slot = 3, 16 do
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- turtle.select(1)
- end
- function returnodd()
- yreturn = 1
- zreturn = 1
- while zreturn < width do
- point()
- zreturn = zreturn + 1
- end
- while yreturn < height do
- drop()
- yreturn = yreturn + 1
- end
- end
- function returneven()
- yreturn = 1
- while yreturn < height do
- drop()
- yreturn = yreturn + 1
- end
- end
- function squareright(height,width)
- y = 0
- loop = 0
- point()
- turtle.turnRight()
- while y < height do
- layer()
- if loop == 0 then
- loop = loop + 1
- else
- loop = loop - 1
- end
- y = y + 1
- if height > y then
- raise()
- end
- if y == height then
- if loop == 0 then
- returneven()
- turtle.turnLeft()
- else
- returnodd()
- turtle.turnRight()
- end
- end
- end
- end
- function squareleft(height,width)
- y = 0
- loop = 0
- point()
- turtle.turnLeft()
- while y < height do
- layer()
- if loop == 0 then
- loop = loop + 1
- else
- loop = loop - 1
- end
- y = y + 1
- if height > y then
- raise()
- end
- if y == height then
- if loop == 0 then
- returneven()
- turtle.turnRight()
- else
- returnodd()
- turtle.turnLeft()
- end
- end
- end
- end
- function prism(length,height,width)
- x = 0
- t = 1
- c = 1
- StartFuel()
- if side == "right" then
- while length > x do
- squareright(height,width)
- x = x + 1
- autotorch()
- autostore()
- end
- end
- if side ~= "right" then
- if side == "left" then
- while length > x do
- squareleft(height,width)
- x = x + 1
- autotorch()
- autostore()
- end
- end
- end
- end
- function autostore()
- if chestperm == "y" then
- c = c + 1
- end
- if c == 5 then
- store()
- c = 1
- end
- end
- function autotorch()
- if torchperm == "y" then
- t = t + 1
- end
- if t == 5 then
- degreeangle()
- raise()
- turtle.select(16)
- turtle.place()
- turtle.select(1)
- drop()
- degreeangle()
- t = 1
- end
- end
- function autofuel()
- while turtle.getFuelLevel() < 1 do
- if fuelperm == "y" then
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.refuel(1)
- if turtle.getFuelLevel() > 0 then
- turtle.select(1)
- break
- end
- end
- end
- NeedFuel()
- end
- end
- function NeedFuel()
- if turtle.getFuelLevel() == 0 then
- print ""
- print "I will not be able to work until I receive fuel."
- print ""
- while turtle.getFuelLevel() == 0 do
- turtle.refuel(1)
- sleep(1)
- end
- end
- print ""
- print "I will start working immediately."
- print ""
- end
- function StartFuel()
- turtle.select(1)
- if turtle.getFuelLevel() == 0 then
- print ""
- print "Please place some fuel in my first slot so that I can start working."
- print ""
- while turtle.getFuelLevel() == 0 do
- turtle.refuel()
- sleep(1)
- end
- end
- print ""
- print "I will begin immediately."
- print ""
- end
- function backtostart()
- displacement = 0
- degreeangle()
- while displacement < length do
- point()
- displacement = displacement + 1
- end
- degreeangle()
- print ""
- print "I have finished my task. I await your next command."
- print ""
- end
- AskTorch()
- AskFuel()
- AskChest()
- AskSide()
- AskHeight()
- AskWidth()
- AskLength()
- prism(length,height,width)
- backtostart(length)
Advertisement
Add Comment
Please, Sign In to add comment