Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HeightOfTunnel=4
- WidthOfTunnel=4
- TorchEvery=5
- LengthCount=0
- MaxLength=0
- SpaceWithBlock=2
- SpaceWithTorch=1
- SpaceWithFuel=3
- SpaceWithChest=4
- FirstEmptySlot=5
- LastEmptySlot=16
- CoalThreshold=0
- BlockThreshold=5
- ChestThreshold=2
- StuckCounter=1
- MaxStuckCount=50
- SliceNumber=0
- TorchNumber=0
- ChestNumber=0
- MoveCounter=0
- DigCounter=0
- PlaceCounter=0
- --simple functions######################################################
- --######################################################################
- function moveForward()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --Attempts to dig down, if it fails go into the while loop
- while not turtle.forward() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich stecke fest")
- print(">>Befreie mich und drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- MoveCounter=MoveCounter+1
- end
- function moveBack()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --Attempts to dig down, if it fails go into the while loop
- while not turtle.back() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich stecke fest")
- print(">>Befreie mich und drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- MoveCounter=MoveCounter+1
- end
- function moveUp()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --Attempts to dig down, if it fails go into the while loop
- while not turtle.up() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich stecke fest")
- print(">>Befreie mich und drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- MoveCounter=MoveCounter+1
- end
- function moveDown()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --Attempts to dig down, if it fails go into the while loop
- while not turtle.down() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich stecke fest")
- print(">>Befreie mich und drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- MoveCounter=MoveCounter+1
- end
- function placeBlock()
- --select the fill block
- turtle.select(SpaceWithBlock)
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts block place, if fail then go into the loop
- while not turtle.place() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann keinen Block vor mir platzieren ")
- print(">>Zerstöre den Block vor mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- PlaceCounter=PlaceCounter+1
- end
- function placeBlockDown()
- --select the fill block
- turtle.select(SpaceWithBlock)
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts block place, if fail then go into the loop
- while not turtle.placeDown() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann keinen Block unter mir platzieren ")
- print(">>Zerstöre den Block unter mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- PlaceCounter=PlaceCounter+1
- end
- function placeBlockUp()
- --select the fill block
- turtle.select(SpaceWithBlock)
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts block place, if fail then go into the loop
- while not turtle.placeUp() do
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann keinen Block über mir platzieren ")
- print(">>Zerstöre den Block über mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- --reset the stuck counter
- StuckCounter=1
- PlaceCounter=PlaceCounter+1
- end
- function moveLeftOne()
- --simple bit of code to strafe left one space
- --checkFuelLevel()
- turtle.turnLeft()
- moveForward()
- turtle.turnRight()
- end
- function moveRightOne()
- --simple bit of code to strafe right one space
- --checkFuelLevel()
- turtle.turnRight()
- moveForward()
- turtle.turnLeft()
- end
- function digBlock()
- MinicheckFuelLevel()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts dig, if fail then go into the loop
- while not turtle.dig() do
- if turtle.detect()==false then break end
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann den Block vor mir nicht abbauen ")
- print(">>Zerstöre den Block vor mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- DigCounter=DigCounter+1
- end
- function digBlockDown()
- MinicheckFuelLevel()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts dig, if fail then go into the loop
- while not turtle.digDown() do
- if turtle.detectDown()==false then break end
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann den Block unter mir nicht abbauen ")
- print(">>Zerstöre den Block unter mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- DigCounter=DigCounter+1
- end
- function digBlockUp()
- MinicheckFuelLevel()
- --reset stuckcounter just incase shoddy coding left a value in it
- StuckCounter=1
- --attempts dig, if fail then go into the loop
- while not turtle.digUp() do
- if turtle.detectUp()==false then break end
- --wait 1 to let whatever is in the way bugger off
- sleep(1)
- --increment the stuck counter as another attempt was failed
- StuckCounter=StuckCounter+1
- --if the stuck counter exceeds the number of attempts allowed
- if StuckCounter>=MaxStuckCount then
- --ask for help
- print(">>Hilfe! Ich kann den Block über mir nicht abbauen ")
- print(">>Zerstöre den Block über mir und Drücke Enter")
- print(" ")
- --pause for user input to proceed
- read()
- end
- end
- DigCounter=DigCounter+1
- end
- function digDownLoop()
- -- Dig infront until successful
- digUntilClear()
- -- Dig a column out infront of the turtle at the height set
- -- DiggingDown can be set to false if digging up is required
- for Counter=1,HeightOfTunnel do
- --dig the block infront
- digBlock()
- --moves down unless it has reached the last space
- --if counter is not equal to the height of the tunnel
- if Counter~=HeightOfTunnel then
- --move
- moveDown()
- end
- end
- --puts the turtle back to where he left off
- --loop round a number of times = to the height of the tunnel
- for Counter=1,HeightOfTunnel-1 do
- --do a fuel check
- --checkFuelLevel()
- --move
- moveUp()
- end
- end
- function digUntilClear()
- --while there is something infront of the turtle do this loop
- while turtle.detect()==true do
- --dig infront
- digBlock()
- --wait 1
- sleep(1)
- end
- end
- function lineWallDown()
- --repeat from 1 to the height of the tunnel
- for OtherWallCounter=1,HeightOfTunnel do
- -- fill a hole if there is one infront
- placeIfBlockMissing()
- --if it isn't the last cycle fo the for loop
- if OtherWallCounter~=HeightOfTunnel then
- --move
- moveDown()
- end
- end
- end
- function lineWallUp()
- --repeat from 1 to the height of the tunnel
- for WallCounter=1,HeightOfTunnel do
- -- fill a hole if there is one infront
- placeIfBlockMissing()
- --if it isn't the last cycle fo the for loop
- if WallCounter~=HeightOfTunnel then
- --move
- moveUp()
- end
- end
- end
- function lineFloor()
- --repeat from 1 to the width of the tunnel
- for FloorCounter=1,WidthOfTunnel do
- -- fill a hole if there is one below
- placeIfBlockMissingDown()
- --if it isn't the last cycle fo the for loop
- if FloorCounter~=WidthOfTunnel then
- --move
- moveBack()
- end
- end
- end
- function lineRoof()
- --repeat from 1 to the width of the tunnel
- for RoofCounter=1,WidthOfTunnel do
- -- fill a hole if there is one above
- placeIfBlockMissingUp()
- --if it isn't the last cycle for the for loop
- if RoofCounter~=WidthOfTunnel then
- --move
- moveBack()
- end
- end
- end
- function placeIfBlockMissing()
- --if there is no block infront then
- if turtle.detect()==false then
- --select the fill block
- turtle.select(SpaceWithBlock)
- --place the fill block infront
- placeBlock()
- end
- end
- function placeIfBlockMissingDown()
- --if there is no block below then
- if turtle.detectDown()==false then
- --select the fill block
- turtle.select(SpaceWithBlock)
- --place the fill block below
- turtle.placeDown()
- end
- end
- function placeIfBlockMissingUp()
- --if there is no block above then
- if turtle.detectUp()==false then
- --select the fill block
- turtle.select(SpaceWithBlock)
- --place the fill block above
- turtle.placeUp()
- end
- end
- function placeChest()
- --simple bit of code to select and then place a chest
- turtle.select(SpaceWithChest)
- turtle.place()
- end
- function placeInChest()
- --cycle from first to last slot
- for ChestDumpCounter=FirstEmptySlot,LastEmptySlot do
- --select the slot for this cycle
- turtle.select(ChestDumpCounter)
- --dump into chest
- turtle.drop()
- end
- end
- function digChestHole()
- --Clear infront
- digUntilClear()
- --now place and fill chest
- placeChest()
- placeInChest()
- end
- function placeTorch()
- -- loop round for the height of the tunnel -1
- for PlaceCounter=1,HeightOfTunnel-2 do
- --move down
- moveDown()
- end
- --move back two and turn 180
- moveBack()
- moveBack()
- turtle.turnRight()
- turtle.turnRight()
- --select the torches and place infront
- turtle.select(SpaceWithTorch)
- turtle.place()
- --turn back to the tunnel face and move towards it
- turtle.turnLeft()
- turtle.turnLeft()
- moveForward()
- moveForward()
- --loop round for the height of the tunnel
- for PlaceCounter=1,HeightOfTunnel-2 do
- --move up
- moveUp()
- end
- end
- function torchCheck()
- --checks to see if there are any torches left in the torch slot
- if turtle.getItemCount(SpaceWithTorch)==0 then
- --returns false if there are no torches
- return false
- else
- --returns true if there are torches
- return true
- end
- end
- function lengthCheck()
- if LengthCount>=MaxLength then
- return false
- else
- return true
- end
- end
- function amIEmpty()
- --set the spaceleft variable to 0
- SpaceLeft=0
- --cycle round for each slot
- for emptyCounter=FirstEmptySlot,LastEmptySlot do
- --if the slot is empty then
- if turtle.getItemCount(emptyCounter)==0 then
- --increment the spaceleft variable to count empty spaces
- SpaceLeft=SpaceLeft+1
- end
- end
- --if there are 1 or less spaces left in the inventory return true
- if SpaceLeft<=1 then
- return true
- else
- return false
- end
- end
- function MinicheckFuelLevel()
- -- check the fuel level, if it's less than 50 then refuel or pause
- CurrentFuel = turtle.getFuelLevel()
- --print ("Current fuel = " .. CurrentFuel)
- while checkCoalRemaining()==false do
- pauseForMoreCoal()
- end
- --if the turtle fuel level is less than 50
- if turtle.getFuelLevel()<=50 then
- --select the fuel slot
- turtle.select(SpaceWithFuel)
- --refuel with 1 peice
- turtle.refuel(1)
- end
- end
- function checkFuelLevel()
- -- check the fuel level, if it's less than 50 then refuel or pause
- CurrentFuel = turtle.getFuelLevel()
- print ("Current fuel = " .. CurrentFuel)
- while checkCoalRemaining()==false do
- pauseForMoreCoal()
- end
- --check the block level, if it's less than 5 refill or pause
- while checkBlocksRemaining()==false do
- pauseForMoreBlocks()
- end
- --check the chest level, if it's less than 2 refill or pause
- while checkChestRemaining()==false do
- pauseForMoreChest()
- end
- --if the turtle fuel level is less than 50
- if turtle.getFuelLevel()<=50 then
- --select the fuel slot
- turtle.select(SpaceWithFuel)
- --refuel with 1 peice
- turtle.refuel(1)
- end
- end
- function checkCoalRemaining()
- --if fuel remaining is less than threshold then return false
- if turtle.getItemCount(SpaceWithFuel) < CoalThreshold then
- return false
- else
- return true
- end
- end
- function checkBlocksRemaining()
- --cycle round each inventory slot
- for BlockCheckCounter=FirstEmptySlot,LastEmptySlot do
- --select the current slot for this cycle
- turtle.select(BlockCheckCounter)
- --compare the selected block to the fill block
- if turtle.compareTo(SpaceWithBlock)==true then
- --if there is a match then use it to refill fill block
- turtle.transferTo(SpaceWithBlock)
- end
- end
- -- checks to see how many blocks remain
- -- returns false if below BlockThreshold
- if turtle.getItemCount(SpaceWithBlock) < BlockThreshold then
- return false
- else
- return true
- end
- end
- function checkChestRemaining()
- --if fuel remaining is less than threshold then return false
- if turtle.getItemCount(SpaceWithChest) < ChestThreshold then
- return false
- else
- return true
- end
- end
- function pauseForMoreCoal()
- --print to user
- print(">>Bitte mehr Kohle!")
- print(">>und drücke Enter")
- --pause for user input
- PauseHere=read()
- end
- function pauseForMoreBlocks()
- --print to user
- print(">>Bitte mehr Blocks!")
- print(">>und drücke Enter")
- --pause for user input
- PauseHere=read()
- end
- function pauseForMoreChest()
- --print to user
- print(">>Bitte mehr Truhen!")
- print(">>und drücke Enter")
- --pause for user input
- PauseHere=read()
- end
- --MAIN CODE START#######################################################
- --######################################################################
- --initial printed info for user
- print(">>Wilkommen Tunnel Maker V1 By Azalen")
- print(">>Anleitung gibt es aufhttp://azalen.de/turtel/")
- --request tunnel height info, pause for input, converts to number
- print(">>Bitte Tunnel Höhe eingeben:")
- HeightOfTunnel = read()
- HeightOfTunnel=tonumber(HeightOfTunnel)
- --if tunnel height is invalid
- while HeightOfTunnel<2 do
- print ">>Üngültig"
- print ">>Tunnel Höhe muss mindesten 2 betragen"
- HeightOfTunnel = read()
- HeightOfTunnel=tonumber(HeightOfTunnel)
- end
- --request tunnel width info, pause for input, converts to number
- print(">>Bitte Tunnel Breite eingeben:")
- WidthOfTunnel = read()
- WidthOfTunnel=tonumber(WidthOfTunnel)
- --if tunnel width is invalid
- while WidthOfTunnel<2 do
- print ">>Ungültig"
- print ">>Tunnel Breite muss mindestes 2 betragen"
- WidthOfTunnel = read()
- WidthOfTunnel=tonumber(HeightOfTunnel)
- end
- print(">>Bitte Tunnel Länge eingeben:")
- MaxLength = read()
- MaxLength=tonumber(MaxLength)
- --if tunnel width is invalid
- while MaxLength<2 do
- print ">>Ungültig"
- print ">>Tunne Länge muss mindestens 2 betragen"
- MaxLength = read()
- MaxLength=tonumber(MaxLength)
- end
- --request torch spacing info, pause for input, converts to number
- print(">>Fackel abstand eingeben:")
- TorchEvery = read()
- TorchEvery=tonumber(TorchEvery)
- --if spacing is invalid
- while TorchEvery<=2 do
- print ">>Ungültig"
- print ">>Abstand muss mindestens 2 betragen"
- TorchEvery = read()
- TorchEvery=tonumber(TorchEvery)
- end
- --print user info regarding slot layout
- print(">>Slot 1: Fackeln")
- print(">>Slot 2: Blocks zum füllen")
- print(">>Slot 3: Kohle (bei Bedarf)")
- print(">>Slot 4: Truhen (Min 2)")
- print(" ")
- --print user info regarding stop and start
- print(">>Zum Stoppen Fackeln entfernen")
- print(">>Zum Starten Enter drücken")
- --pause for user input to begin executing tunnel dig
- StartString = read()
- --set the torch counter to 1
- TorchCounter=1
- --Does initial check to see the slots are filled
- --Adds initial fuel if required
- checkFuelLevel()
- --This while loop holds the continuous process of tunnel creation
- --while torches are still available run the loop
- while torchCheck()==true do
- --dig the tunnel face
- --loop round for thw width of the tunnel
- print (">>Graben Abschnitt " .. SliceNumber)
- SliceNumber=SliceNumber+1
- LengthCount=LengthCount+1
- for LeftCounter=1,WidthOfTunnel do
- --dig a column out
- digDownLoop()
- --if it's not the last column, move left one space
- if LeftCounter~=WidthOfTunnel then
- moveLeftOne()
- end
- end
- --do a fuel check
- checkFuelLevel()
- if lengthCheck()==false then break end
- --print ">>Slice cut, moving back"
- --move in and turn right
- moveForward()
- turtle.turnRight()
- --for the width of the tunnel move forwards
- for ReturnCounter=1,WidthOfTunnel-1 do
- moveForward()
- end
- --turn to face the tunnel wall at the top right position
- turtle.turnLeft()
- --print ">>Checking for torches"
- --TORCHCHECK, if no torches left then break the while loop
- --this will end the code running
- if torchCheck()==false then break end
- --TORCHCHECK
- --print ">>Lining the walls of the new slice"
- --move in and line the tunnel walls if gaps are found
- turtle.turnRight()
- --right wall
- lineWallDown()
- --floor
- lineFloor()
- turtle.turnLeft()
- turtle.turnLeft()
- --left wall
- lineWallUp()
- --roof
- lineRoof()
- --turn to face the tunnel wall at the top right position
- turtle.turnRight()
- --print ">>Checking for torches"
- --TORCHCHECK, if no torches left then break the while loop
- --this will end the code running
- if torchCheck()==false then break end
- --TORCHCHECK
- --print "Checking if a torch is needed"
- --if the current torch counter reaches the set limit
- if TorchCounter==TorchEvery then
- print (">>Setze Fackel " .. TorchNumber)
- TorchNumber=TorchNumber+1
- --place a torch then reset the counter
- placeTorch()
- TorchCounter=0
- end
- --increment the torch counter
- TorchCounter=TorchCounter+1
- --print ">>Checking for torches"
- --TORCHCHECK, if no torches left then break the while loop
- --this will end the code running
- if torchCheck()==false then break end
- --TORCHCHECK
- --print ">>Checking if a chest is needed"
- --checks if getting near full, if so places chest and empties itself
- --if full then
- if amIEmpty()==true then
- --print ">>Chest needed"
- -- move back and face the right hand wall
- moveBack()
- turtle.turnRight()
- --for each height of the tunnel
- for EmptyHeightCounter=1,HeightOfTunnel-1 do
- --move down
- moveDown()
- end
- --this chest check should be in a seperate function
- --i know, but i'm being lazy and putting it here :P
- --check the chest level, if it's less than 2 refill or pause
- while checkChestRemaining()==false do
- pauseForMoreChest()
- end
- print (">>Placing chest" .. ChestNumber)
- ChestNumber=ChestNumber+1
- --dig the chest hole, place chest, fill chest
- digChestHole()
- --move back up to the top right of the tunnel face
- --fill any gravel fall gaps on the way
- for EmptyHeightCounter=1,HeightOfTunnel-1 do
- moveUp()
- end
- turtle.turnLeft()
- moveForward()
- end
- end
- print ("Ende:")
- print ("Abgebaute Blöcke " .. DigCounter .. " ")
- print ("Aufgefüllte Blöcke " .. PlaceCounter .. " ")
- print ("Gegrabene Abschnitte " .. SliceNumber .. " ")
- print ("Länge des Tunnels " .. LengthCount .." ")
- print ("Fackeln gesetzt " .. TorchNumber .. " ")
- print ("Truhen verwendet " .. ChestNumber .. " ")
Add Comment
Please, Sign In to add comment