Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local deforestation = {trees = {
- "minecraft:oak_log",
- "minecraft:birch_log",
- "minecraft:acacia_log",
- "minecraft:dark_oak_log",
- "minecraft:jungle_log",
- "minecraft:spruce_log"}
- }
- ----------movement library
- movement = {}
- movement.curXPos = 0
- movement.curYPos = 0
- movement.curZPos = 0
- movement.orientation = "north"
- movement.forward = function()
- local k = turtle.forward()
- if k == true then
- if movement.orientation == "north" then
- movement.curXPos = movement.curXPos + 1
- elseif movement.orientation == "east" then
- movement.curYPos = movement.curYPos + 1
- elseif movement.orientation == "south" then
- movement.curXPos = movement.curXPos - 1
- elseif movement.orientation == "west" then
- movement.curYPos = movement.curYPos - 1
- end
- end
- return k
- end
- movement.up = function()
- local k = turtle.up()
- if k == true then
- movement.curZPos = movement.curZPos + 1
- end
- return k
- end
- movement.down = function()
- local k = turtle.down()
- if k == true then
- movement.curZPos = movement.curZPos - 1
- end
- return k
- end
- movement.turnLeft = function()
- local k = turtle.turnLeft()
- if movement.orientation == "north" then
- movement.orientation = "west"
- elseif movement.orientation == "west" then
- movement.orientation = "south"
- elseif movement.orientation == "south" then
- movement.orientation = "east"
- elseif movement.orientation == "east" then
- movement.orientation = "north"
- end
- return k
- end
- movement.turnRight = function()
- local k = turtle.turnRight()
- if movement.orientation == "north" then
- movement.orientation = "east"
- elseif movement.orientation == "east" then
- movement.orientation = "south"
- elseif movement.orientation == "south" then
- movement.orientation = "west"
- elseif movement.orientation == "west" then
- movement.orientation = "north"
- end
- return k
- end
- ---------------these functions are useful for specific situations (NOTE: you should probably use movement.faceDirection() instead of turtle.turn as it updates orientation which is relevant for the other functions)
- movement.goHome = function()
- local savedPos = {}
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- print("Facing direction: "..movement.orientation)
- if movement.curYPos > 0 then
- movement.faceDirection("west")
- for i=1,savedPos.y do
- movement.forward()
- end
- elseif movement.curYPos < 0 then
- movement.faceDirection("east")
- for i=1,math.abs(savedPos.y) do
- movement.forward()
- end
- end
- if movement.curXPos > 0 then
- movement.faceDirection("south")
- for i=1,savedPos.x do
- movement.forward()
- end
- elseif movement.curXPos < 0 then
- movement.faceDirection("north")
- for i=1,math.abs(savedPos.x) do
- movement.forward()
- end
- end
- end
- movement.faceDirection = function(orientation)
- if orientation == "north" then
- if movement.orientation == "south" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif movement.orientation == "east" then
- turtle.turnLeft()
- elseif movement.orientation == "west" then
- turtle.turnRight()
- end
- movement.orientation = "north"
- elseif orientation == "west" then
- if movement.orientation == "south" then
- turtle.turnRight()
- elseif movement.orientation =="east" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif movement.orientation == "north" then
- turtle.turnLeft()
- end
- movement.orientation = "west"
- elseif orientation == "south" then
- if movement.orientation == "east" then
- turtle.turnRight()
- elseif movement.orientation == "north" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif movement.orientation == "west" then
- turtle.turnLeft()
- end
- movement.orientation = "south"
- elseif orientation == "east" then
- if movement.orientation == "north" then
- turtle.turnRight()
- elseif movement.orientation == "west" then
- for i=1,2 do
- turtle.turnLeft()
- end
- elseif movement.orientation == "south" then
- turtle.turnLeft()
- end
- movement.orientation = "east"
- end
- end
- movement.goToCoords = function(toX, toY, toZ, orientation)
- local savedPos = {}
- local changeInPos = {}
- savedPos.toX = toX
- savedPos.toY = toY
- savedPos.toZ = toZ
- savedPos.orient = orientation
- local placeholder = {}
- placeholder.x = math.abs(savedPos.toX - movement.curXPos)
- placeholder.y = math.abs(savedPos.toY - movement.curYPos)
- placeholder.z = math.abs(savedPos.toZ - movement.curZPos)
- if savedPos.x > movement.curXPos then
- movement.faceDirection("north")
- for i=1,placeholder.x do
- movement.forward()
- end
- elseif savedPos.x < movement.curXPos then
- movement.faceDirection("south")
- for i=1,placeholder.x do
- movement.forward()
- end
- end
- if savedPos.y > movement.curYPos then
- movement.faceDirection("east")
- for i=1, placeholder.y do
- movement.forward()
- end
- elseif savedPos.y < movement.curYPos then
- movement.faceDirection("west")
- for i=1,placeholder.y do
- movement.forward()
- end
- end
- if savedPos.z > curZPos then
- for i=1,placeholder.z do
- turtle.digUp()
- movement.up()
- end
- elseif savedPos.z < curZPos then
- for i=1,placeholder.z do
- movement.down()
- end
- end
- movement.faceDirection(savedPos.orient)
- end
- -----------------
- -----------------
- ----------------deforestation movement functions dedicated to climbing over obstacles
- deforestation.parseArgs = function()
- print("Do you want the turtle to refuel using wood farmed? (y/n)")
- deforestation.selfSufficient = read()
- end
- deforestation.mineTree = function()
- local tablee = {}
- local goDown = false
- repeat
- local mineTree = false
- for i,v in pairs(deforestation.trees) do
- x, tablee = turtle.inspect()
- if tablee.name == v then
- mineTree = true
- end
- end
- if mineTree == true then
- turtle.dig()
- turtle.digUp()
- movement.up()
- goDown = true
- end
- until mineTree == false
- if goDown == true then
- if turtle.detectDown() == false then
- repeat
- movement.down()
- until turtle.detectDown() == true
- end
- end
- end
- deforestation.forward = function()
- if turtle.detectDown() == false then
- repeat
- local k = movement.down()
- if k == false then
- turtle.digDown()
- end
- until turtle.detectDown() == true
- end
- deforestation.mineTree()
- if movement.forward() == false then
- deforestation.mineTree()
- while movement.forward() == false do
- deforestation.mineTree()
- if movement.up() == false then
- repeat
- turtle.digUp()
- until movement.up() == true
- end
- end
- end
- check = true
- end
- deforestation.goHome = function()
- local savedPos = {}
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- print("Facing direction: "..movement.orientation)
- if movement.curYPos > 0 then
- movement.faceDirection("west")
- for i=1,savedPos.y do
- deforestation.forward()
- end
- elseif movement.curYPos < 0 then
- movement.faceDirection("east")
- for i=1,math.abs(savedPos.y) do
- deforestation.forward()
- end
- end
- if movement.curXPos > 0 then
- movement.faceDirection("south")
- for i=1,savedPos.x do
- deforestation.forward()
- end
- elseif movement.curXPos < 0 then
- movement.faceDirection("north")
- for i=1,math.abs(savedPos.x) do
- deforestation.forward()
- end
- end
- end
- deforestation.goToCoords = function(x, y, z, orientation)
- local savedPos = {}
- savedPos.x = x
- savedPos.y = y
- savedPos.z = z
- savedPos.orient = orientation
- if savedPos.x > 0 then
- for i=1,savedPos.x do
- deforestation.forward()
- end
- elseif savedPos.x < 0 then
- for i=1,2 do
- turtle.turnLeft()
- end
- for i=1,math.abs(savedPosX) do
- deforestation.forward()
- end
- end
- if savedPos.y > 0 then
- movement.faceDirection("east")
- for i=1, savedPos.y do
- deforestation.forward()
- end
- elseif savedPos.y < 0 then
- movement.faceDirection("west")
- for i=1,savedPos.y do
- deforestation.forward()
- end
- end
- if savedPos.z > 0 then
- for i=1,savedPos.z do
- turtle.digUp()
- movement.up()
- end
- elseif savedPos.z < 0 then
- for i=1,savedPos.z do
- movement.negZ()
- end
- end
- movement.faceDirection(savedPos.orient)
- end
- deforestation.refuel = function()
- local tablee = {}
- local savedPos = {}
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- savedPos.orient = movement.orientation
- local curSlot = 1
- if deforestation.selfSufficient == "y" then
- if turtle.getFuelLevel() <= savedPos.x + savedPos.y + 20 then
- if turtle.getItemCount(16) ~= 0 then
- turtle.select(16)
- turtle.refuel(16)
- elseif turtle.getItemCount(16) == 0 then
- for i=1,15 do
- turtle.select(curSlot)
- for i,v in pairs(deforestation.trees) do
- local tablee = turtle.getItemDetail()
- if tablee ~= nil and tablee.name == v then
- turtle.transferTo(16)
- turtle.select(16)
- turtle.refuel(16)
- turtle.select(1)
- end
- end
- curSlot = curSlot + 1
- if curSlot == 15 then
- turtle.select(1)
- end
- end
- end
- end
- elseif turtle.getFuelLevel() <= savedPos.x + savedPos.y + 20 and turtle.getItemCount(16) ~= 0 then
- turtle.select(16)
- turtle.refuel()
- elseif turtle.getFuelLevel() <= savedPos.x + savedPos.y + 20 and turtle.getItemCount(16) == 0 then
- savedPos.x = movement.curXPos
- savedPos.y = movement.curYPos
- savedPos.z = movement.curZPos
- deforestation.goHome()
- movement.faceDirection("north")
- turtle.select(16)
- if turtle.suckDown(32) == false then
- print("Out of fuel, please add fuel to chest or 16th slot")
- repeat
- sleep(1)
- until turtle.refuel() == true or turtle.suck(32) == true
- end
- turtle.refuel()
- deforestation.goToCoords(savedPos.x, savedPos.y, savedPos.z, savedPos.orient)
- end
- end
- deforestation.deforest = function()
- local amount = 1
- while true do
- deforestation.refuel()
- deforestation.mineTree()
- for i=1, amount do
- term.clear()
- term.setCursorPos(1, 1)
- print([[X Position: ]]..movement.curXPos)
- term.setCursorPos(1, 2)
- print([[Y Position: ]]..movement.curYPos)
- term.setCursorPos(1, 3)
- print("Orientation: "..movement.orientation)
- term.setCursorPos(1,4)
- print("Amount moving: "..amount)
- deforestation.forward()
- term.setCursorPos(1,5)
- print("Movement check: "..tostring(check))
- end
- movement.faceDirection("east")
- deforestation.refuel()
- deforestation.mineTree()
- for i=1, amount do
- term.clear()
- term.setCursorPos(1, 1)
- print([[X Position: ]]..movement.curXPos)
- term.setCursorPos(1, 2)
- print([[Y Position: ]]..movement.curYPos)
- term.setCursorPos(1, 3)
- print("Orientation: "..movement.orientation)
- term.setCursorPos(1,4)
- print("Amount moving: "..amount)
- deforestation.forward()
- term.setCursorPos(1,5)
- print("Movement check: "..tostring(check))
- end
- movement.faceDirection("south")
- amount = amount + 1
- deforestation.refuel()
- deforestation.mineTree()
- for i=1, amount do
- term.clear()
- term.setCursorPos(1, 1)
- print([[X Position: ]]..movement.curXPos)
- term.setCursorPos(1, 2)
- print([[Y Position: ]]..movement.curYPos)
- term.setCursorPos(1, 3)
- print("Orientation: "..movement.orientation)
- term.setCursorPos(1,4)
- print("Amount moving: "..amount)
- deforestation.forward()
- term.setCursorPos(1,5)
- print("Movement check: "..tostring(check))
- end
- movement.faceDirection("west")
- deforestation.refuel()
- deforestation.mineTree()
- for i=1, amount do
- term.clear()
- term.setCursorPos(1, 1)
- print([[X Position: ]]..movement.curXPos)
- term.setCursorPos(1, 2)
- print([[Y Position: ]]..movement.curYPos)
- term.setCursorPos(1, 3)
- print("Orientation: "..movement.orientation)
- term.setCursorPos(1,4)
- print("Amount moving: "..amount)
- deforestation.forward()
- term.setCursorPos(1,5)
- print("Movement check: "..tostring(check))
- end
- movement.faceDirection("north")
- amount = amount + 1
- end
- end
- deforestation.parseArgs()
- deforestation.deforest()
Add Comment
Please, Sign In to add comment