Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Move up for given amount and check for every move if there is enough fuel for this opreation
- function moveUp(amount)
- for n = 1, amount, 1 do
- checkFuel(0)
- turtle.up()
- end
- end
- -- Move down for given amount and check for every move if there is enough fuel for this opreation
- function moveDown(amount)
- for n = 1, amount, 1 do
- checkFuel(0)
- turtle.down()
- end
- end
- -- if there is more fuel then requested, otherweise refuel from slot 5
- -- if this fails then wait for userinput
- function checkFuel(value)
- fuel = turtle.getFuelLevel()
- if fuel <= value then
- print("Need FUEL!, press any key when ready")
- -- move wood to refuel slot and refuel (we could refuel from 5 but this is logically cleaner ;) )
- turtle.select(5)
- turtle.transferTo(16 ,32)
- turtle.select(16)
- turtle.refuel()
- fuel = turtle.getFuelLevel()
- print("Refueled - Fuel Level"..fuel)
- -- refuel failed for some reason? wait for player to refuel
- if fuel == 0 then
- print("Refuel failed, please refuel manually!!")
- local event, param1 = os.pullEvent("char")
- turtle.select(16)
- turtle.refuel()
- end
- end
- end
- -- checks if there is something in front of turtel
- -- if yes : it must be a tree and turtel will chop it down
- -- maybe there are just leaves but we think of them as a tree and clear the way ;)
- function detectAndCutTree()
- -- is something in front of turtel?
- if turtle.detect() then
- -- dig block in front place it in slot 5 and move to digged pos, chop 1 below and chop everything above
- turtle.select(5)
- turtle.dig()
- moveForward(1)
- turtle.digDown()
- while turtle.detectUp() do
- turtle.digUp()
- moveUp(1)
- end
- -- move down to ground
- while not turtle.detectDown() do
- moveDown(1)
- end
- -- move to original postion, pre chopping
- moveUp(1)
- turtle.back()
- end
- end
- -- moves turtel forwar for given amount, check for fuel and possible tree on every move
- function moveForward(amount)
- for n = 1, amount, 1 do
- checkFuel(0)
- detectAndCutTree()
- turtle.forward()
- end
- end
- -- plant a sappling, checks for saps in slot 1 and 2. if empty waits for player input
- function plantSap()
- gotSap = 1
- turtle.select(1)
- sapLevel = turtle.getItemCount(1)
- -- if slot 1 is empty try slot 2
- if sapLevel == 0 then
- turtle.select(2)
- sapLevel2 = turtle.getItemCount(2)
- -- if slot 2 is empty try slot 3
- if sapLevel2 == 0 then
- turtle.select(3)
- sapLevel3 = turtle.getItemCount(3)
- -- if slot 3 is empty try slot 4
- if sapLevel3 == 0 then
- turtle.select(4)
- sapLevel4 = turtle.getItemCount(4)
- -- if slot 4 is empty just continue in felling mode
- if sapLevel4 == 0 then
- gotSap = 0
- print("No Saplings! just felling now")
- end
- end
- end
- end
- -- if gotSap == 1 we cant plant something and have the right slot selected
- if gotSap == 1 then
- turtle.placeDown()
- end
- end
- -- move in straight line and planting a sappling on every second field
- function plantOrCut(dist)
- plant = 0
- while dist > 0 do
- dist = dist - 1
- if plant == 0 then
- -- just move and cut no plating
- moveForward(1)
- plant = 1
- else
- -- try planting then move and cut
- plantSap()
- moveForward(1)
- plant = 0
- end
- end
- end
- -- method for moving the turtel through the grid
- function moveTurtel()
- dist = 10
- turn = 0
- moveUp(1)
- turtle.select(1)
- for n = 1, dist, 1 do
- -- move turtel
- plantOrCut(dist)
- -- turn right
- if turn == 0 then
- turtle.turnRight()
- moveForward(2)
- turtle.turnRight()
- turn = 1
- -- turn left
- else
- turtle.turnLeft()
- moveForward(2)
- turtle.turnLeft()
- turn = 0
- end
- end
- end
- -- returns back to chest, refuels and drops loot
- function goHome()
- turtle.turnLeft()
- moveForward(20)
- turtle.turnRight()
- --sit on chest
- moveDown(1)
- -- move one wood to another place to make sure the slot will be filled with wood again
- turtle.select(5)
- turtle.transferTo(15 ,4)
- checkFuel(800)
- -- drop loot to chest
- turtle.select(5)
- turtle.dropDown()
- turtle.select(6)
- turtle.dropDown()
- turtle.select(7)
- turtle.dropDown()
- turtle.select(8)
- turtle.dropDown()
- -- move one wood back to 5 to ensure we have wood there to refuel from
- -- reserves slot
- turtle.select(15)
- turtle.transferTo(5 ,1)
- turtle.transferTo(6 ,1)
- turtle.transferTo(7 ,1)
- turtle.transferTo(8 ,1)
- end
- -- Main Routine, endless repeating
- -- fuels itself than starts
- function gogoTurtel()
- turtle.select(16)
- turtle.refuel()
- while 1 > 0 do
- fuel = turtle.getFuelLevel()
- print("Going with Fuel Level"..fuel)
- moveTurtel()
- goHome()
- end
- end
- gogoTurtel()
Add Comment
Please, Sign In to add comment