Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Jackman 1.0
- -- by MCKerrnel
- --
- -- A ComputerCraft program to
- -- operate a smalltree farm.
- -- Turtle will chop down trees
- -- and replant in the same cycle.
- -- Size of farm grid that turtle
- -- will traverse.
- local width = 5
- local length = 13
- -- Fuel needed to start a cycle.
- local fuelCycle = 250
- -- Replants a sapling.
- function plantTree()
- -- We are already one block
- -- above ground, so let's
- -- just place a sapling
- -- underneath us.
- turtle.select(1)
- turtle.placeDown()
- end
- -- Chops a tree down starting at
- -- the base and going to top.
- -- Does not work for anything
- -- bigger than 1x1.
- function chopTree()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- local vertical = 0
- while turtle.detectUp() do
- turtle.digUp()
- turtle.up()
- vertical = vertical + 1
- end
- while vertical > 0 do
- turtle.down()
- vertical = vertical - 1
- end
- -- Replant a new sapling.
- plantTree()
- end
- function chopCycle()
- local pass = 1
- local colPos = 1
- local rowPos = 1
- while pass <= 2 do
- for rowPos = 1, length, 1 do
- if turtle.detect() then
- chopTree()
- else
- turtle.forward()
- end
- end
- turtle.turnLeft()
- if pass == 1 then
- for colPos = 1, width, 1 do
- if turtle.detect() then
- chopTree()
- else
- turtle.forward()
- end
- end
- turtle.turnLeft()
- end
- pass = pass + 1
- end
- end
- -- Unloads the wood from the turtle
- -- into the chest for wood.
- function emptyWood()
- turtle.turnRight()
- for slot = 2, 16, 1 do
- turtle.select(slot)
- turtle.drop()
- end
- turtle.turnLeft()
- end
- -- A quick function to convert a decimal
- -- value into an integer. Dunno why
- -- LUA has to be so difficult with this.
- -- Should be a built-in function!
- function toInt(decimalNum)
- local D2I = string.format("%i", decimalNum)
- return D2I
- end
- function refuel(fuelCycles)
- -- Refuel. This is a regular turtle
- -- so can only hold 20,000 units.
- if fuelCycles < 1 then
- turtle.turnRight()
- turtle.select(2)
- -- Try to fill up, but if not enough to
- -- fill up, that's ok.
- while fuelCycles < 1 or turtle.getFuelLevel() < 20000 do
- -- If there's nothing to grab, error out.
- if turtle.suck() == false then
- break
- end
- turtle.refuel()
- fuelCycles = turtle.getFuelLevel() / fuelCycle
- end
- -- If we still need fuel
- -- then alert console.
- if fuelCycles < 1 then
- print "NO FUEL: Reload the FUEL chest."
- end
- turtle.turnLeft()
- end
- return fuelCycles
- end
- -- MAINLINE
- local fuelCycles = turtle.getFuelLevel() / fuelCycle
- print("Enough fuel to chop ", toInt(fuelCycles), " cycles.")
- -- This is where it all happens.
- while true do
- -- Fuel Up
- fuelCycles = turtle.getFuelLevel() / fuelCycle
- if fuelCycles < 1 then
- fuelCycles = refuel(fuelCycles)
- end
- --Restock Saplings
- if turtle.getItemCount(1) < 7 then
- turtle.select(1)
- turtle.suckDown()
- if turtle.getItemCount(1) < 7 then
- print("NO SAPLINGS: Restock sapling chest!")
- end
- end
- if fuelCycles >= 1 and turtle.getItemCount(1) > 6 then
- -- Send turtle out to chop!
- turtle.up()
- chopCycle()
- -- Return to start
- for count = 1, 5, 1 do
- turtle.forward()
- end
- turtle.down()
- -- Empty inventory
- emptyWood()
- turtle.turnLeft()
- end
- sleep(300)
- end
Advertisement
Add Comment
Please, Sign In to add comment