Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sleepTime = 0
- if #arg == 1 then
- sleepTime = tonumber(arg[1])
- if sleepTime == 0 then
- print("Please set the sleep time between each check.")
- return
- end
- else
- print("There needs to be one correct argument (e.g. logger 5)")
- return
- end
- local WOODS = {
- "minecraft:oak_log",
- "minecraft:birch_log",
- "minecraft:spruce_log"
- }
- function cleanInspectDown()
- local hasBlock, data = turtle.inspectDown()
- local name = textutils.serialize(data.name)
- local name2 = name:gsub("\"", "")
- local val = string.sub(name2, 0, string.len(name) - 2)
- return val
- end
- function cleanInspectUp()
- local hasBlock, data = turtle.inspectUp()
- local name = textutils.serialize(data.name)
- local name2 = name:gsub("\"", "")
- local val = string.sub(name2, 0, string.len(name) - 2)
- return val
- end
- function cleanInspect()
- local hasBlock, data = turtle.inspect()
- local name = textutils.serialize(data.name)
- local name2 = name:gsub("\"", "")
- local val = string.sub(name2, 0, string.len(name) - 2)
- return val
- end
- function down()
- local down = false
- for x = 1, #WOODS do
- if cleanInspectDown() == WOODS[x] then
- down = true
- return down
- end
- end
- end
- function up()
- local down = false
- for x = 1, #WOODS do
- if cleanInspectUp() == WOODS[x] then
- down = true
- return down
- end
- end
- end
- local SAPLINGS = {
- "minecraft:oak_sapling",
- "minecraft:birch_sapling",
- "minecraft:spruce_sapling"
- }
- local INVENTORY_SIZE = 16
- function plant()
- turtle.select(1)
- for i = 1, INVENTORY_SIZE do
- turtle.select(i)
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- local isAcceptedItem = false
- for x = 1, #SAPLINGS do
- if currentItem.name == SAPLINGS[x] then
- turtle.select(i)
- turtle.place()
- return
- end
- end
- end
- end
- end
- function log()
- turtle.dig()
- turtle.forward()
- if down() then
- local continue = true
- local num = 0
- repeat
- turtle.digDown()
- turtle.down()
- if not down() then
- continue = false
- end
- num = num + 1
- until(continue == false)
- local a = 0
- repeat
- turtle.up()
- a = a + 1
- until(a == num)
- end
- local continue = true
- local num = 0
- repeat
- turtle.digUp()
- turtle.up()
- if not up() then
- continue = false
- end
- num = num + 1
- until(continue == false)
- local a = 0
- repeat
- turtle.down()
- a = a + 1
- until(a == num)
- turtle.back()
- plant()
- end
- function logFront()
- local down = false
- for x = 1, #WOODS do
- if cleanInspect() == WOODS[x] then
- down = true
- return down
- end
- end
- end
- function saplingFront()
- local down = false
- for x = 1, #SAPLINGS do
- if cleanInspect() == SAPLINGS[x] then
- down = true
- return down
- end
- end
- end
- local FUELS = {
- "minecraft:coal_block",
- "minecraft:coal",
- "minecraft:lava_bucket",
- "minecraft:spruce_log",
- "minecraft:oak_log",
- "minecraft:birch_log"
- }
- function refuel(slot_number)
- print("[TURTLE] Refueling... ")
- turtle.select(slot_number)
- turtle.refuel()
- print("[TURTLE] Nom. Nom. Nom.")
- end
- -- Check the current fuel level
- function checkFuelLevel()
- local requiredFuelLevel = math.ceil(500)
- local currentFuelLevel = turtle.getFuelLevel()
- --print("[TURTLE] Current fuel level is: "..currentFuelLevel.." - Required: "..requiredFuelLevel)
- if currentFuelLevel < requiredFuelLevel then
- print("[TURTLE] Attempting to locate fuel.")
- for i = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- for x = 1, #FUELS do
- if currentItem.name == FUELS[x] then
- print("[TURTLE] Acceptable fuel found: " ..FUELS[x])
- if currentFuelLevel < requiredFuelLevel then
- refuel(i)
- else
- return true
- end
- end
- end
- end
- end
- print("[TURTLE] No acceptable fuel or not enough found, terminating program...")
- return false
- else
- return true
- end
- end
- function check()
- if logFront() then
- print("[TURTLE] Chopping!")
- log()
- checkFuelLevel()
- elseif not saplingFront() then
- print("[TURTLE] Planting!")
- plant()
- checkFuelLevel()
- else
- print("[TURTLE] Lurking!")
- checkFuelLevel()
- end
- end
- while true do
- print("Checking...")
- check()
- sleep(sleepTime)
- end
Add Comment
Please, Sign In to add comment