Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- It mines trees! --
- -- doesn't go out of the outOfBoundsMarker
- -- reverses at the stop marker
- -- errors at a halt maker
- -- ground markers
- local outOfBoundsMarker = "minecraft:grass_block"
- local outOfBoundsMarker2 = "minecraft:dirt"
- local pauseMarker = "atmospheric:arid_sandstone"
- local stopMakrer = "minecraft:cobblestone"
- local haltMarker = "minecraft:glass"
- local inventoryMarker = "environmental:willow_planks"
- local inventory = "environmental:willow_chest"
- --side markers
- local woodLog = "minecraft:birch_log"
- local sapling ="minecraft:birch_sapling"
- local ignore = "minecraft:snow"
- local realSnow ="snowrealmagic:snow"
- --local
- local fuelSlot = 2
- local emptyTurtleSlots = { 3,4,5,6,7,8,9,10,11,12,13,14 }
- local keepFullSlots = {1,2}
- function combine(slot)
- ---Make sure slot is not already full
- turtle.select(slot)
- if turtle.getItemCount() == 64 then return end
- if turtle.getItemCount() > 0 then
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemCount() >0 then
- if turtle.compareTo(i) then
- turtle.transferTo(slot)
- end
- end
- end
- else
- return "slot empty"
- end
- end
- function pickupItems()
- turtle.suck()
- turtle.suckDown()
- turtle.suckUp()
- end
- function t_detect(f)
- detectDown = detectBlockNameDown()
- end
- function t_detectFwd(f)
- if turtle.detect() == true then
- local a,b = turtle.inspect()
- if b ~= false then
- detectFwd = b.name
- else
- detectFwd = "none"
- end
- else
- detectFwd = false
- end
- -- f()
- end
- function testBounds()
- local isBlock = turtle.detect == true
- haltIfNeccesary(detectDown)
- keepInBounds(detectDown,f)
- testInfFront(isBlock)
- end
- function testInfFront(isBlock)
- local blockInfort = turtle.inspect()
- if isBlock == true then
- if blockInfort == "minecraft:snow" then
- turtle.turnRight2()
- elseif blockInfort == woodLog then
- elseif blockInfort == sapling then
- elseif blockInfort == ignore then
- elseif blockInfort == realSnow then turtle.dig()
- else
- error("obstructed - there is something strange in the way!")
- end
- end
- end
- function isBlockDown(block,blockDetected)
- if type(blockDetected) ~= "string" then
- print(string.sub(debug.traceback(),1,200))
- error("invalid detection")
- end
- if block == blockDetected then
- return true
- else
- return false
- end
- end
- function detectBlockNameDown()
- local a,b = turtle.inspectDown()
- return b.name or "none"
- end
- function haltIfNeccesary(detectDown)
- local halt = isBlockDown(haltMarker,detectDown)
- if halt == true then
- error("Halted")
- end
- end
- function returnFromOutOfBounds(f)
- turtle.back2()
- turtle.turnRight2()
- end
- function keepInBounds(detectDown,f)
- if isBlockDown(outOfBoundsMarker,detectDown) == true then
- returnFromOutOfBounds(f)
- end
- -- out of bounds marker 2
- if isBlockDown(outOfBoundsMarker2,detectDown,f) == true then
- returnFromOutOfBounds(f)
- end
- end
- do
- local f = turtle.forward
- function turtle.forward2()--detectDown)
- f()
- t_detect(f)
- testBounds()
- pickupItems()
- return true
- end
- end
- do
- local b = turtle.back
- function turtle.back2()
- b()
- t_detect(b)
- testBounds()
- pickupItems()
- end
- end
- do
- local l = turtle.turnLeft
- function turtle.turnLeft2()
- --print("l1")
- l()
- t_detectFwd(l)
- pickupItems()
- --print("l2")
- end
- end
- do
- local r= turtle.turnRight
- function turtle.turnRight2()
- --print("r1")
- r()
- t_detectFwd(r)
- pickupItems()
- --print("r2")
- end
- end
- do
- local u = turtle.up
- function turtle.up2()
- local try = u()
- print("going up")
- while try == false do
- print("failed going up retying")
- turtle.digUp()
- try = u()
- end
- pickupItems()
- end
- end
- do
- local d = turtle.down
- function turtle.down2()
- local try = d()
- print("going down")
- while try == false do
- print("failed going down retying")
- turtle.digDown()
- try = d()
- end
- pickupItems()
- end
- end
- function sort()
- for i,v in pairs(keepFullSlots) do
- combine(v)
- end
- end
- function insertToInventory()
- sort()
- --local emptyTurtleSlots
- for i,v in pairs(emptyTurtleSlots) do
- turtle.select(v)
- turtle.drop()
- end
- end
- function FindInventory()
- local i=1
- while detectFwd ~= inventory do
- turtle.turnLeft2()
- i = i + 1
- if i == 10 then
- error("unable to find inventory")
- end
- end
- insertToInventory()
- for i2=1, i-1 do
- turtle.turnRight2()
- end
- end
- function checkForChestBlock()
- if detectDown == inventoryMarker then
- FindInventory()
- end
- end
- function digTree()
- local maxZ = 10
- function isBlock(block)
- if isBlock ~= false then
- --local a,b = turtle.inspect()
- local blockName = detectFwd
- if blockName == block then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function searchSlotsFor(blockId)
- for slot = 1,16 do
- turtle.select(slot)
- --local i = turtle.
- local i = turtle.getItemDetail() or "nothing"
- if i ~= "nothing" then
- if i.name == blockId then
- return slot
- else
- end
- end
- end
- return "nothing found"
- end
- function findBlock(blockId)
- local i = turtle.getItemDetail() or "nothing"
- if i ~= "nothing" and i.name == blockId then
- return true
- else
- slot = searchSlotsFor(blockId)
- if slot ~= "nothing found" then
- return true
- else
- print(tostring(blockId) .. " not found")
- local i = 0
- local ingnoreTime = 5
- while searchSlotsFor(blockId) == "nothing found" do
- i = i + 1
- sleep(1)
- write(".")
- if type(ingnoreTime) == "number" then
- if i == ingnoreTime then
- print("ignoring")
- return "none"
- end
- end
- end
- end
- end
- end
- function ifLogDigTree()
- local isLog = isBlock(woodLog) == true
- if isLog then
- for i=1,maxZ do
- turtle.dig()
- turtle.digUp()
- turtle.up2()
- end
- for i=1,maxZ do
- turtle.down2()
- end
- if findBlock(sapling) == true then
- turtle.place()
- end
- end
- if not isLog then
- local isRealSnow = isBlock(realSnow) == true
- if isRealSnow then
- turtle.dig()
- end
- local isSnow = isBlock(ignore) == true
- if isSnow then
- turtle.dig()
- --local isSapling = isBlock(sapling)
- else
- turtle.place()
- end
- end
- end
- ifLogDigTree()
- end
- detectDown = detectBlockNameDown() --- updates in turtle.forward2()
- function paceBlock(pauseAt,stopAt,direction)
- print(detectDown)
- turtle.forward2()--detectDown)
- if direction == "right" then
- checkForChestBlock()
- end
- local pause = isBlockDown(pauseAt,detectDown)
- local stop = isBlockDown(stopAt,detectDown)
- if pause == true then
- --pauseTurn()
- turtle.turnRight2()
- digTree()
- turtle.turnLeft2()
- turtle.turnLeft2()
- digTree()
- turtle.turnRight2()
- --resumeTurn()
- elseif stop == true then
- return "stop"
- end
- --
- end
- function paceBlockRepeatedly(pauseAt,stopAt,direction)
- while true do
- topUpFuel()
- if paceBlock(pauseAt,stopAt,direction) == "stop" then return "stop" end
- end
- end
- function paceRight(pauseAt,stopAt)
- --turtle.turnRight()
- paceBlockRepeatedly(pauseAt,stopAt,"right")
- turtle.turnRight2()
- turtle.turnRight2()
- --turtle.turnRight()
- end
- function paceLeft(pauseAt,stopAt)
- -- turtle.turnLeft()
- paceBlockRepeatedly(pauseAt,stopAt,"left")
- turtle.turnLeft2()
- turtle.turnLeft2()
- -- turtle.turnLeft()
- --paceRight()
- end
- function pace(pauseAt,stopAt,direction)
- if direction == "right" then
- paceRight(pauseAt,stopAt)
- elseif direction == "left" then
- paceLeft(pauseAt,stopAt)
- end
- end
- function topUpFuel()
- local fuelBuffer = 1000
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel < fuelBuffer then
- local prevSlot = turtle.getSelectedSlot()
- print("attempting to refuel")
- local i = 1
- while turtle.getFuelLevel() < fuelBuffer do
- turtle.select(fuelSlot)
- turtle.refuel(1)
- i = i+1
- end
- turtle.select(prevSlot)
- else
- end
- end
- function turnToCorretSide()
- turtle.turnRight2()
- while detectFwd ~= false do
- turtle.turnLeft2()
- print(detectFwd)
- end
- --turtle.turnLeft2()
- end
- ------ main
- turtle.select(1)
- topUpFuel()
- turnToCorretSide()
- while true do
- topUpFuel()
- paceLeft(pauseMarker,stopMakrer)
- topUpFuel()
- paceRight(pauseMarker,stopMakrer)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement