Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Advanced Logger by Henness
- -- Version 1.0 3/1/2015
- -- Config
- local program = "Advanced Logger"
- local version = "v1.0"
- local author = "Henness"
- local area = 100
- local trees = {"minecraft:log","Natura:tree"}
- local blacklist = {"minecraft:stone","minecraft:grass","minecraft:dirt","minecraft:sand","minecraft:gravel"}
- local whitelist = {"minecraft:tallgrass","BiomesOPlenty:foliage","minecraft:leaves","minecraft:deadbush","minecraft:yellow_flower","minecraft:red_flower","minecraft:brown_mushroom","minecraft:red_mushroom","minecraft:vine","minecraft:waterlily"}
- local loc = {}
- loc = {
- paused = false,
- x = 0,
- y = 0,
- z = 0,
- facing = 0,
- facingToAxis = {
- [0] = { axis = 'z', unit = 1 },
- [1] = { axis = 'x', unit = -1 },
- [2] = { axis = 'z', unit = -1 },
- [3] = { axis = 'x', unit = 1 }
- },
- pause = function()
- while loc.paused do
- sleep(1)
- end
- end,
- getAxisForFacing = function()
- return loc.facingToAxis[loc.facing]['axis'], loc.facingToAxis[loc.facing]['unit']
- end,
- turnLeft = function()
- loc.pause()
- loc.facing = (loc.facing - 1) % 4
- turtle.turnLeft()
- end,
- turnRight = function()
- loc.pause()
- loc.facing = (loc.facing + 1) % 4
- turtle.turnRight()
- end,
- moveForward = function()
- loc.pause()
- if turtle.forward() then
- local axis, unit = loc.getAxisForFacing()
- loc[axis] = loc[axis] + unit
- return true
- end
- return false
- end,
- moveBack = function()
- loc.pause()
- if turtle.back() then
- local axis, unit = loc.getAxisForFacing()
- loc[axis] = loc[axis] - unit
- return true
- end
- return false
- end,
- face = function(faceto)
- local dirdif = (faceto - loc.facing) % 4
- if dirdif == 1 then
- loc.turnRight()
- elseif dirdif == 2 then
- loc.turnRight()
- loc.turnRight()
- elseif dirdif == 3 then
- loc.turnLeft()
- end
- end,
- movez = function(d)
- if d < loc.z then loc.face(2) elseif d > loc.z then loc.face(0) end
- return loc.moveForward()
- end,
- movex = function(d)
- if d < loc.x then loc.face(1) elseif d > loc.x then loc.face(3) end
- return loc.moveForward()
- end,
- movey = function(d)
- if d < loc.y then
- return loc.moveDown()
- end
- return loc.moveUp()
- end,
- moveUp = function()
- loc.pause()
- if turtle.up() then
- loc.y = loc.y + 1
- return true
- end
- return false
- end,
- moveDown = function()
- loc.pause()
- if turtle.down() then
- loc.y = loc.y - 1
- return true
- end
- return false
- end,
- moveTo = function(x, y, z, facing)
- if y > loc.y then
- while loc.y < y do
- while not loc.moveUp() do
- if turtle.detectUp() then
- turtle.select(1)
- turtle.digUp()
- else
- turtle.attackUp()
- end
- end
- end
- end
- while x ~= loc.x do
- while not loc.movex(x) do
- if turtle.detect() then
- turtle.select(1)
- turtle.dig()
- else
- turtle.attack()
- end
- end
- end
- while z ~= loc.z do
- while not loc.movez(z) do
- if turtle.detect() then
- turtle.select(1)
- turtle.dig()
- else
- turtle.attack()
- end
- end
- end
- if y < loc.y then
- while loc.y > y do
- while not loc.moveDown() do
- if turtle.detectDown() then
- turtle.select(1)
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- end
- loc.face(facing)
- return true
- end,
- moveToPos = function(pos)
- return loc.moveTo(pos.x, pos.y, pos.z, pos.facing)
- end,
- distanceTo = function(x, y, z)
- return math.abs(x) - loc.x + math.abs(y) - loc.y + math.abs(z) - loc.z
- end,
- distanceToPos = function(pos)
- return loc.distanceTo(pos.x, pos.y, pos.z)
- end
- }
- function saveTable(table,name) -- Save table to file for access later
- local file = fs.open(name,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function loadTable(name) -- Load table from file, returns a table
- local file = fs.open(name,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function isTree(direction)
- if direction == "up" then
- isBlock, blockData = turtle.inspectUp()
- elseif direction == "down" then
- isBlock, blockData = turtle.inspectDown()
- else
- isBlock, blockData = turtle.inspect()
- end
- if isBlock then
- for key,value in pairs(trees) do
- if value == blockData.name then
- return true
- end
- end
- end
- return false
- end
- function isBlacklist(direction)
- if direction == "up" then
- isBlock, blockData = turtle.inspectUp()
- elseif direction == "down" then
- isBlock, blockData = turtle.inspectDown()
- else
- isBlock, blockData = turtle.inspect()
- end
- if isBlock then
- for key,value in pairs(blacklist) do
- if value == blockData.name then
- return true
- end
- end
- end
- return false
- end
- function isWhitelist(direction)
- if direction == "up" then
- isBlock, blockData = turtle.inspectUp()
- elseif direction == "down" then
- isBlock, blockData = turtle.inspectDown()
- else
- isBlock, blockData = turtle.inspect()
- end
- if isBlock then
- for key,value in pairs(whitelist) do
- if value == blockData.name then
- return true
- end
- end
- end
- return false
- end
- function refuel()
- if turtle.getFuelLevel() < turtle.getFuelLimit() then
- for i=1,16 do
- turtle.select(i)
- turtle.refuel()
- if turtle.getFuelLevel() == turtle.getFuelLimit() then
- break
- end
- end
- turtle.select(1)
- end
- end
- function chopTree()
- if isTree("up") then
- while isTree("up") do
- turtle.digUp()
- if not loc.moveUp() then
- turtle.attackUp()
- end
- end
- refuel()
- while not turtle.inspectDown() do
- while not loc.moveDown() do
- turtle.attackDown()
- end
- end
- return true
- end
- return false
- end
- function advance()
- while not loc.moveForward() do
- if turtle.inspect() then
- if isBlacklist() then
- while not loc.moveUp() do
- if turtle.inspectUp() then
- turtle.digUp()
- else
- turtle.attack()
- end
- end
- else
- turtle.dig()
- end
- else
- turtle.attack()
- end
- end
- while not turtle.inspectDown() or isWhitelist("down") do
- while not loc.moveDown() do
- if turtle.inspectDown() then
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- if loc.y <= 60 then
- break
- end
- end
- end
- function runLogger()
- local cArea = 1
- while cArea <= area do
- for i=1, cArea do
- advance()
- chopTree()
- end
- loc.turnRight()
- for i=1, cArea do
- advance()
- chopTree()
- end
- loc.turnRight()
- cArea = cArea + 1
- end
- end
- local tArgs = { ... }
- if turtle.getFuelLevel() > 0 or turtle.getFuelLevel() == "unlimited" then
- if #tArgs == 4 then
- loc.x = tonumber(tArgs[1])
- loc.y = tonumber(tArgs[2])
- loc.z = tonumber(tArgs[3])
- loc.face = tonumber(tArgs[4])
- runLogger()
- term.setCursorPos(1,1)
- term.clear()
- else
- error("Usage: advancedlogger x y z face")
- end
- else
- error("Error, there must be fuel in the turtle!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement