Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FTB LumberJack - V 3.0
- -- Made by Xmarks
- -- https://www.youtube.com/channel/UCA6oAnFqdDcc0sa6H8G5DSA
- -- Program cuts down a 1x1 Tree and replants
- -- Best Performed with a Fir Tree
- -- Drops items in slots 2-to-14 after process is finished
- -- Waits for Tree to regrow or uses BoneMeal of available - BoneMeal TODO
- -- Ensures Program won't start unless enough Fuel for 1 cycle
- -- Ensures Operation can't be blocked
- -- ***************************************
- -- * Wood-Drop Chest behind Turtle *
- -- * Fuel-Stock Chest left of Turtle *
- -- * Sapling-Stock Chest right of Turtle *
- -- * BoneMeal-Stock Chest below Turtle *
- -- ***************************************
- -- * Slot 1: Fuel *
- -- * Stot 15: Wood Block - Comparison *
- -- * Stot 16: Tree-Sapling - Replant *
- -- ***************************************
- -- Global Assumed Tree height - Change for taller Trees
- -- * Adapts to Taller Trees after first Run
- assumed_height = 50;
- -- Do not Change - Stores height of tree after each itteration
- next_assumed_height = 0
- -- Check Fuel Level - Refuel if necessary
- -- Assumes Tree Height - Does not start if not enough Fuel
- local function checkFuel()
- while turtle.getFuelLevel() < (40 + 2 * assumed_height) do
- -- If not enough fuel available, wait for more fuel
- if turtle.getItemCount(1) == 0 then
- print('More Fuel requird on Slot 1 - sleeping for 10s')
- os.sleep(10)
- else
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- end
- -- Ensures Turtle Moves Forward 1 Block
- local function goForward()
- local counter = 0
- while counter < 1 do
- if turtle.forward() then
- counter = counter + 1
- -- if can not move, try digging and attacking
- else
- turtle.dig()
- turtle.attack()
- end
- end
- return true
- end
- -- Ensures Turtle Moves 1 Block Upwards
- local function goUp()
- local counter = 0
- while counter < 1 do
- if turtle.up() then
- counter = counter + 1
- -- if can not move, try digging and attacking
- else
- turtle.digUp()
- turtle.attackUp()
- end
- end
- return true
- end
- -- Ensures Turtle Moves 1 Block Downwards
- local function goDown()
- local counter = 0
- while counter < 1 do
- if turtle.down() then
- counter = counter + 1
- -- if can not move, try digging and attacking
- else
- turtle.digDown()
- turtle.attackDown()
- end
- end
- return true
- end
- -- Will place down Block from given Slot without fail
- -- * Expects Block Slot as argument
- local function placeBlock(block_slot)
- local starting_stack = turtle.getItemCount(block_slot)
- local counter = 0
- while counter < 1 do
- turtle.place()
- -- if it could not place the Block - Clear Obstructions
- if starting_stack == turtle.getItemCount(block_slot) then
- turtle.dig()
- turtle.attack()
- else
- counter = counter + 1
- end
- end
- return true
- end
- -- Tree Fell Function
- local function fellTree()
- turtle.dig()
- goForward()
- print('digging upwards until no more blocks are detected')
- -- will store height of tree as turtle digs up
- local tree_height = 0;
- -- turtle will dig the first half of the 2x2 tree
- while turtle.detectUp() do
- turtle.dig()
- turtle.digUp()
- if goUp() then
- tree_height = tree_height + 1
- end
- end
- -- Next time - fuel assumptions will be more correct
- next_assumed_height = tree_height
- print('Dug up to a Height of ' .. tree_height)
- print('Going down for ' .. tree_height .. 'blocks')
- -- turtle will now go down for the same height
- for i = 0,(tree_height - 1) do
- goDown()
- end
- print('Finished felling the Tree')
- end
- -- Function clears inventory
- local function dropLoot()
- print('Dropping all blocks in slots 2-to-14 into the chest')
- for slot = 2,14 do
- turtle.select(slot)
- turtle.drop()
- end
- return
- end
- -- Function Replants a 2x2 area with provided seeds
- local function replant()
- turtle.select(16)
- if placeBlock(16) then
- print('Seed planted - Waiting for tree to grow')
- end
- return
- end
- -- Main Code that runs the program
- while true do
- -- wood slot for compare
- turtle.select(15)
- -- If true - the tree has grown
- if turtle.compare() then
- checkFuel()
- fellTree()
- turtle.turnLeft()
- turtle.turnLeft()
- goForward()
- dropLoot()
- turtle.turnLeft()
- turtle.turnLeft()
- replant()
- else
- turtle.suck()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement