Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- host = 3
- status = "Inactive"
- pos = vector.new(gps.locate())
- local modem = peripheral.find("modem")
- rednet.open("left")
- L = 0
- R = 1
- pathX = {5,3,2,3,2,3,5,9}
- turns = {R,R,L,L,R,R,R}
- step = 1
- currX = 1
- function save_config()
- sw = fs.open("config.txt", "w")
- sw.writeLine(step)
- sw.writeLine(currX)
- sw.close()
- end
- function load_config()
- sr = fs.open("config.txt", "r")
- step = tonumber(sr.readLine())
- currX = tonumber(sr.readLine())
- sr.close()
- end
- function left(times)
- for i=1,times do
- turtle.turnLeft()
- end
- end
- function right(times)
- for i=1,times do
- turtle.turnRight()
- end
- end
- function chopTree()
- refuel(1)
- status = "Chopping"
- while turtle.detect() do
- turtle.dig()
- turtle.digUp()
- turtle.up()
- pos = vector.new(gps.locate())
- refuel(1)
- end
- status = "Returning"
- local has_block, data = turtle.inspectDown()
- while not has_block or (data.name ~= "minecraft:andesite" and data.name ~= "computercraft:wired_modem_full") do
- if(not turtle.down()) then
- turtle.digDown()
- turtle.down()
- end
- has_block, data = turtle.inspectDown()
- pos = vector.new(gps.locate())
- end
- turtle.select(1)
- turtle.place()
- turtle.select(2)
- status = "Roaming"
- end
- function cleanInv()
- local data = turtle.getItemDetail(1)
- if(data ~= nil and data.name ~= "minecraft:oak_sapling") then
- turtle.select(1)
- turtle.drop()
- end
- for i=1, 16 do
- local data = turtle.getItemDetail(i)
- if(data ~= nil and data.name == "minecraft:oak_sapling") then
- turtle.select(i)
- turtle.transferTo(1)
- end
- end
- turtle.suck()
- turtle.select(1)
- end
- function emptyInv()
- local modem = peripheral.wrap("bottom")
- local turtleName = modem.getNameLocal()
- local chest = peripheral.find("minecraft:chest")
- if(chest ~= nil) then
- for slot, item in pairs(chest.list()) do
- if(item.name == "minecraft:oak_sapling") then
- chest.pushItems(turtleName, slot, 64, 1)
- end
- end
- end
- for idx=2,16 do
- chest.pullItems(turtleName, idx)
- end
- end
- function refuel(lvl)
- while(turtle.getFuelLevel() <= lvl) do
- status = "Waiting for Fuel"
- for i=2, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- turtle.select(1)
- sleep(2)
- end
- end
- function checkForTree()
- local has_block, data = turtle.inspect()
- if(has_block) then
- if (data.name == "minecraft:oak_log") then
- chopTree()
- cleanInv()
- refuel(1)
- end
- else
- turtle.select(1)
- turtle.place()
- end
- end
- function farmTree()
- while true do
- while(currX <= pathX[step]) do
- refuel(1)
- left(1)
- checkForTree()
- right(2)
- checkForTree()
- left(1)
- while(not turtle.forward()) do
- turtle.dig()
- turtle.attack()
- end
- currX = currX + 1
- end
- checkForTree()
- currX = 1
- if(turns[step] == R) then
- left(1)
- checkForTree()
- right(2)
- else
- right(1)
- checkForTree()
- left(2)
- end
- step = step + 1
- if(step > table.getn(pathX)) then
- step = 1
- emptyInv()
- end
- end
- end
- function rangeCheck()
- while true do
- if rednet.receive("failsafe") == null then
- os.shutdown()
- end
- sleep(1)
- end
- end
- function transmit()
- while(true) do
- local sender, message, protocol = rednet.receive("ping")
- if(message ~= nil and message == "send") then
- rednet.send(host, os.getComputerLabel() .. " " .. turtle.getFuelLevel() .. " " .. pos.x .. " " .. pos.y .." " .. pos.z .. " " .. status, "miners")
- sleep(0.5)
- end
- end
- end
- parallel.waitForAny(farmTree, rangeCheck, transmit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement