Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Haktest")
- -- leaves: 13
- -- brick: 14
- -- hout: 15
- -- sapling: 16
- padLengte = 6
- function terugNaarStart()
- print("Reset turtle")
- -- en ontvang geen f 200,-
- omgeving = bekijkOmgeving()
- -- voor sapling:
- if((omgeving[0] == 16) and (omgeving[5] == 14)) then
- print("Turtle start wachtend op sapling.")
- for i = 0, padLengte, 1 do
- turtle.back()
- end
- return
- end
- -- TODO als tutle uitvalt tijdens planten.
- -- Op pad:
- if(omgeving[5] == 14) then
- print("Turtle start op pad")
- for i = 0,3,1 do
- turtle.turnRight()
- if(omgeving[i] == 14) then
- break
- end
- end
- for i = 0, padLengte, 1 do
- turtle.back(padLengte)
- end
- return true
- end
- -- in boom:
- --hout Boven
- if(omgeving[4] == 15) then
- hakOmhoog()
- turtle.digUp()
- turtle.up()
- --linksonder:
- if(omgeving[0] ~= 15) then
- print("turtle start links onder")
- turtle.turnRight()
- else
- print("turtle start rechts achter")
- end
- turtle.dig()
- turtle.forward()
- terugNaarStart()
- return
- end
- --hout onder:
- if(omgeving[5] == 15) then
- turtle.back()
- turtle.turnRight()
- turtle.down()
- turtle.down()
- turtle.select(15)
- isLinksBoven = turtle.compare()
- turtle.up()
- turtle.up()
- turtle.turnLeft()
- turtle.forward()
- hakOmlaag()
- if(isLinksBoven) then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- terugNaarStart()
- return
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turtle.back()
- turtle.back()
- turtle.back()
- terugNaarStart()
- end
- end
- end
- function bekijkOmgeving()
- omgeving = {}
- for i = 0, 3, 1 do
- if(turtle.detect()) then
- for j = 13, 16, 1 do
- turtle.select(j)
- if(turtle.compare()) then
- omgeving[i] = j
- break
- end
- end
- if(omgeving[i] == nil) then
- print("Onbekend blok gevonden!")
- omgeving[i] = -1
- end
- else
- omgeving[i] = 0
- end
- turtle.turnRight()
- end
- if(turtle.detectUp()) then
- for i = 13, 16, 1 do
- turtle.select(i)
- if(turtle.compareUp()) then
- omgeving[4] = i
- break
- end
- end
- if(omgeving[4] == nil) then
- print("Onbekend blok gevonden!")
- omgeving[4] = -1
- end
- else
- omgeving[4] = 0
- end
- if(turtle.detectDown()) then
- for i = 13, 16, 1 do
- turtle.select(i)
- if(turtle.compareDown()) then
- omgeving[5] = i
- break
- end
- end
- if(omgeving[5] == nil) then
- print("Onbekend blok gevonden!")
- omgeving[5] = -1
- end
- else
- omgeving[5] = 0
- end
- return omgeving
- end
- function plantSapling()
- print("Plant sapling")
- turtle.forward()
- turtle.select(16)
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.place()
- turtle.back()
- turtle.place()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.place()
- end
- function hakOmhoog()
- hoogte = 0
- turtle.select(15)
- while(true) do
- if(turtle.compareUp() == true) then
- hoogte = hoogte + 1
- turtle.digUp()
- turtle.up()
- else
- break
- end
- if(turtle.getItemCount(15) == 0) then
- if(hoogte > 200) then
- break
- end
- end
- end
- end
- function hakOmlaag()
- turtle.select(15)
- while(true) do
- if(turtle.compareDown() == true) then
- turtle.digDown()
- turtle.down()
- else
- break
- end
- end
- end
- function hakBoom()
- print("Boom wordt gekapt.")
- turtle.select(15)
- turtle.dig()
- turtle.forward()
- hakOmhoog()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.up()
- turtle.digUp()
- turtle.down()
- hakOmlaag()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- hakOmhoog()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.digUp()
- turtle.up()
- turtle.digUp()
- turtle.down()
- hakOmlaag()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- function tankBij()
- selectedSlot = turtle.getSelectedSlot()
- turtle.select(15)
- while(turtle.getFuelLevel() < 0.9*turtle.getFuelLimit()) do
- turtle.refuel(1)
- if(turtle.getItemCount(15) < 10) then
- break
- end
- end
- turtle.select(selectedSlot)
- if(turtle.getFuelLevel() < 1000) then
- return false
- end
- return true
- end
- function detecteerBoom()
- -- return 1 als boom
- -- return 0 als sapling
- -- return -999 als anders
- turtle.select(15)
- if(turtle.compare() == true) then
- return 1
- end
- turtle.select(16)
- if(turtle.compare()) then
- return 0
- end
- return -999
- end
- function startTurtle()
- if(turtle.getItemCount(13)<1) then
- print("Geen leaves: probleem")
- return false
- end
- if(turtle.getItemCount(14) < 1) then
- print("Geen bricks: probleem")
- return false
- end
- if(turtle.getItemCount(15)<8) then
- print("Geen hout: probleem")
- return false
- end
- if(turtle.getItemCount(16) < 12) then
- print("Geen sapling: probleem")
- return false
- end
- omgeving = bekijkOmgeving()
- for i=0, 5, 1 do
- if(omgeving[i] > 12 and omgeving[i] < 17) then
- omgevingBekend = true
- break
- end
- end
- if(omgevingBekend == false) then
- return false
- end
- terugNaarStart()
- tankBij()
- for i = 0, padLengte-2, 1 do
- turtle.select(13)
- if(turtle.compare() == true) then
- turtle.dig()
- end
- turtle.forward()
- end
- if(turtle.detect() == false) then
- plantSapling()
- end
- timer = 0
- while(true) do
- boomCode = detecteerBoom()
- -- 0 als sapling, 1 als boom -999 anders
- if(boomCode == 1) then
- print("Boom volgroeid")
- break
- end
- if(boomCode < 0) then
- print("Saplings gestolen!")
- os.sleep(20)
- end
- os.sleep(10)
- timer = timer + 1
- if(timer % 6 == 0) then
- print(timer/60)
- end
- end
- -- Eindelijk, hak de boom om.
- hakBoom()
- for i = 0, padLengte-2, 1 do
- turtle.select(13)
- if(turtle.compare() == true) then
- turtle.dig()
- end
- turtle.forward()
- end
- for i = 1, 12, 1 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(16)
- turtle.suckUp(turtle.getItemSpace())
- turtle.turnRight()
- turtle.turnRight()
- tankBij()
- return true
- end
- aantalBomen = 0
- while(startTurtle()) do
- aantalBomen = aantalBomen + 1
- if(aantalBomen % 10 == 0 ) then
- print("Al " .. tostring(aantalBomen) .. " omgehakt zonder reset!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement