Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[To Do:
- If interest is high enough:
- 1. Add rednet capability
- 2. Save time by going through rows to detect trees
- ]]
- --Version 1.2.5
- --Config rows are to the right
- --Columns are forward
- -- rows > x x x x x
- -- x x x x x
- -- ^ ^ ^ ^
- -- Columns
- rows = 2
- columns = 2
- --Space between saplings
- space = 2
- --Turn on Fuel Check
- doCheckFuel = true
- --If how much to raise by when fuel low
- raise = 1000
- tArgs = {...}
- tArgsCheck = {}
- if tArgs[1] == "initial" then
- failings = 0
- initial = true
- if tArgs[2] and tArgs[3] and tArgs[4] then
- if not (tonumber(tArgs[2]) and tonumber(tArgs[3]) and tonumber(tArgs[4])) then
- error([[Please restart with acutal numbers in the argument,
- it will most definantly not work without numbers there]],0)
- end
- rows = tonumber(tArgs[2])
- columns = tonumber(tArgs[3])
- space = tonumber(tArgs[4])
- end
- else
- initial = false
- tArgsCheck = {}
- for i=1, #tArgs do
- if tonumber(tArgs[i]) then
- tArgsCheck[i] = tonumber(tArgs[i])
- end
- end
- if tArgsCheck[1] ~= nil and tArgsCheck[2] ~= nil then
- rows = tArgsCheck[1]
- columns = tArgsCheck[2]
- end
- if tArgsCheck[3] ~= nil then
- space = tArgsCheck[3]
- end
- end
- if rows < 1 then rows = 1 end
- if columns <1 then columns = 1 end
- if space <1 then space = 1 end
- rows = math.floor(rows)
- columns = math.floor(columns)
- space = math.floor(space)
- --Calculating Fuel Usage
- --This will just keep it over the fuel value you set
- fuelUsage = rows*columns*8 + --Assume an average of height 8 per tree
- rows*columns*(space+1) +
- columns*(space+1)
- if columns/2 ~= math.floor(columns/2)
- then
- fuelUsage = fuelUsage + rows*(space+1)
- end
- if doCheckFuel == true then
- function checkFuel()
- local fuelLevel = turtle.getFuelLevel()
- return fuelLevel
- end
- if checkFuel() < fuelUsage then
- term.clear()
- term.setCursorPos(1,1)
- print("More Fuel Needed")
- print("Place in Bottom Right, press any key")
- os.pullEvent("char")
- turtle.select(16)
- while checkFuel() < fuelUsage + raise do
- if turtle.refuel(1) == false then
- term.clearLine()
- print("Still too little fuel")
- term.clearLine()
- print("Press a key to resume fueling")
- os.pullEvent("char")
- end
- local x,y = term.getCursorPos()
- print(checkFuel().." Fuel")
- term.setCursorPos(x,y)
- end
- print(checkFuel().." Units of Fuel")
- sleep(3)
- turtle.select(1)
- end
- end
- --Defining Functions
- function move()
- while not turtle.forward() do
- turtle.dig()
- end
- turtle.suckDown()
- end
- function logger()
- print("Fuel: "..checkFuel())
- local dist = 0
- while turtle.detect() do
- turtle.dig()
- up()
- dist = dist+1
- end
- for i=0, dist-1 do
- down()
- end
- end
- function moveSaplings()
- local movedSaps = false
- if turtle.getItemCount(1) < 10 then
- local itemsInInventory = false
- for i=2, 15 do
- if turtle.getItemCount(i) > 0 then
- itemsInInventory = true
- end
- end
- if itemsInInventory then
- for i=2, 15 do
- turtle.select(i)
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- movedSaps = true
- end
- end
- end
- turtle.select(1)
- end
- return movedSaps
- end
- function countSaplings()
- local var = turtle.getItemCount(1)
- return var
- end
- function inCheck()
- if turtle.detect() then
- down()
- logger()
- if countSaplings() > 1 then
- turtle.place()
- elseif moveSaplings() == true then
- turtle.place()
- end
- up()
- end
- if initial == true then -- If you specify it is initial running
- if countSaplings() > 1 then
- down()
- turtle.dig()
- if not turtle.place() then
- failings = failings + 1
- print("On Row "..cRow..", Column "..cColumn.." a place failed due to")
- if countSaplings() < 1 then
- print("lack of saplings")
- else
- print("inhospitable terrain")
- end
- end
- up()
- else
- failings = failings + 1
- print("I'M FAILNG YOU, MASTER, NO SAPLINGS")
- end
- end
- end
- function treeCheck()
- if rowCheck == "right" then
- turtle.turnLeft()
- inCheck()
- turtle.turnRight()
- else
- turtle.turnRight()
- inCheck()
- turtle.turnLeft()
- end
- move()
- end
- --Misc. Move Functions:
- function up()
- while not turtle.up() do turtle.digUp() end
- end
- function down()
- while not turtle.down() do turtle.digDown() end
- end
- --Initial Check for Saplings
- if turtle.getItemCount(1) == 0 then
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- if countSaplings() == 0 then
- print("No Saplings, Continue (\"c\") or Quit (\"q\")?")
- local _, key = os.pullEvent("char")
- if key == "q" then
- return
- end
- end
- end
- rowCheck = "right"
- --UserInterface
- term.clear()
- term.setCursorPos(1,1)
- print("This is the Auto Log Harvester")
- print("Made by Civilwargeeky","")
- print("Your Current Dimensions:")
- print("X: "..rows.." Y: "..columns.." Space: "..space,"")
- print("This Job Will Take Up To "..fuelUsage.." fuel")
- while fuelUsage > turtle.getFuelLevel() do
- print("More Fuel Needed. Place in Bottom Right")
- print("Then Press any Key to fuel")
- os.pullEvent("char")
- turtle.select(16)
- for i=1, turtle.getItemCount(16) do
- if fuelUsage > turtle.getFuelLevel() then
- turtle.refuel(1)
- end
- end
- turtle.select(1)
- end
- print("Starting in 3")
- sleep(3)
- --Starting it along
- if initial and countSaplings() == 0 then
- print("No saplings, please restart with proper amounts")
- return false
- end
- up()
- turtle.turnRight()
- cRow = 0
- cColumn = 0
- --In the program, the singular "column" and "row" are the current count
- -- while the plural "columns" and "rows" are the numbers from the config
- --Actual Loops
- for column=1, columns do
- cColumn = cColumn + 1 -- See cRow below...
- --Cutting Down Every Tree in Column
- move()
- for row=1, rows do
- cRow = cRow + 1 -- cRow because the rows variable refuses to be nice in called functions
- treeCheck()
- if row ~= rows then
- for b=1, space do
- move()
- end
- end
- end
- --Go to Next Column
- if column ~= columns then
- if rowCheck == "right" then
- turtle.turnLeft()
- for b=1, space+1 do
- move()
- end
- turtle.turnLeft()
- else
- turtle.turnRight()
- for b=1, space+1 do
- move()
- end
- turtle.turnRight()
- end
- --Switching Row
- if rowCheck == "right" then
- rowCheck = "left"
- else
- rowCheck = "right"
- end
- end
- end
- --Getting back to home chest
- if rowCheck == "right" then
- turtle.turnLeft()
- turtle.turnLeft()
- for a=1, rows-1 do
- for i=1, 3 do
- move()
- end
- end
- for i=1, 2 do
- move()
- end
- end
- turtle.turnLeft()
- for i=1, (columns-1) * (space+1) do
- move()
- end
- down()
- --Resupply Saplings
- if turtle.getItemCount(1) < 10 then
- if not moveSaplings() then
- turtle.turnRight()
- if turtle.detect() then
- turtle.suck()
- else
- print("No Supply Chest")
- sleep(1)
- end
- turtle.turnLeft()
- end
- end
- --Dropping Inventory
- logs = 0
- sleep(1)
- if turtle.detect() then
- for i=2, 15 do
- turtle.select(i)
- if not turtle.compareTo(1) then
- logs = logs + turtle.getItemCount(i)
- turtle.drop()
- end
- end
- else
- for i=2, 15 do
- turtle.select(i)
- if not turtle.compareTo(1) then
- logs = logs + turtle.getItemCount(i)
- end
- end
- end
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- term.clear()
- term.setCursorPos(1,1)
- print("Job Done!")
- print("Wood Obtained: "..logs)
- print("Current Fuel: "..turtle.getFuelLevel())
- if initial == true and failings ~= 0 then
- print("Placed: "..(columns*rows-failings).."/"..(columns*rows))
- end
- moveSaplings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement