Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --MENU
- --VARIABLES
- local version, savefile ,message = "ULTIMATE WOOD CHOPPER BETA 0.9.5 prerelease", "uwcvariables0.9.2", ""
- local w,h = term.getSize()
- local id, distance, turtleslot = 15, 7, 1
- local running, chopping, usebonemeal = true, true, true
- local savestate, runningProgram = 0, ""
- turtle.select(turtleslot)
- rednet.open("right")
- --VARIABLES
- cancelTimer = 2
- bonemealTimer = 120
- bonemealFirstDelay = 0
- amountMaxWoodSlotBonemeal = 14
- amountMaxWoodSlotNoBonemeal = 7
- amountMinBonemeal = 8
- amountMinSaplings = 17
- amountMinFuelLevel = 1200
- amountFurnaceWoodBonemeal = 16
- amountFurnaceWoodNoBonemeal = 8
- debugMaxHeight = 55
- usebonemeal = true
- persistence = true
- amountbonemealtimes = 1
- function loadVariables()
- local file = fs.open(savefile,"r")
- cancelTimer = tonumber(file.readLine())
- bonemealTimer = tonumber(file.readLine())
- bonemealFirstDelay = tonumber(file.readLine())
- amountMaxWoodSlotBonemeal = tonumber(file.readLine())
- amountMaxWoodSlotNoBonemeal = tonumber(file.readLine())
- amountMinBonemeal = tonumber(file.readLine())
- amountMinSaplings = tonumber(file.readLine())
- amountMinFuelLevel = tonumber(file.readLine())
- amountFurnaceWoodBonemeal = tonumber(file.readLine())
- amountFurnaceWoodNoBonemeal = tonumber(file.readLine())
- debugMaxHeight = tonumber(file.readLine())
- local catchusebonemeal = file.readLine()
- if catchusebonemeal == "true" then usebonemeal = true else usebonemeal = false end
- distance = tonumber(file.readLine())
- local catchpersistence = file.readLine()
- if catchpersistence == "true" then persistence = true else persistence = false end
- amountbonemealtimes = tonumber(file.readLine())
- file.close()
- end
- function saveVariables()
- local file = fs.open(savefile,"w")
- file.writeLine(cancelTimer)
- file.writeLine(bonemealTimer)
- file.writeLine(bonemealFirstDelay)
- file.writeLine(amountMaxWoodSlotBonemeal)
- file.writeLine(amountMaxWoodSlotNoBonemeal)
- file.writeLine(amountMinBonemeal)
- file.writeLine(amountMinSaplings)
- file.writeLine(amountMinFuelLevel)
- file.writeLine(amountFurnaceWoodBonemeal)
- file.writeLine(amountFurnaceWoodNoBonemeal)
- file.writeLine(debugMaxHeight)
- file.writeLine(usebonemeal)
- file.writeLine(distance)
- file.writeLine(persistence)
- file.writeLine(amountbonemealtimes)
- for i=1,10 do
- file.writeLine("-1")
- end
- file.close()
- end
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- term.clear()
- end
- --RUN MENU
- function runMenu()
- while true do
- clearScreen()
- print("Rednet active! Waiting for message...")
- id, message = rednet.receive()
- sleep(0.1)
- rednet.broadcast("started")
- startProgram(message)
- end
- end
- function startProgram(input)
- if input == "quit" then
- running = false
- runningProgram = ""
- saveVariables()
- return
- elseif input == "standard" then
- distance = 7
- runningProgram = "standard"
- saveSavePoint(0)
- saveVariables()
- chop()
- runningProgram = ""
- saveVariables()
- elseif input == "expanded" then
- distance = 9
- runningProgram = "expanded"
- saveSavePoint(0)
- saveVariables()
- chop()
- runningProgram = ""
- saveVariables()
- elseif input == "debugstandard" then
- distance = 7
- UWCdebug()
- elseif input == "debugexpanded" then
- distance = 9
- UWCdebug()
- elseif input == "onebyone" then
- FWConebyone()
- elseif input == "twobytwo" then
- FWCtwobytwo()
- elseif input == "forward" then
- turtle.forward()
- elseif input == "back" then
- turtle.back()
- elseif input == "up" then
- turtle.up()
- elseif input == "down" then
- turtle.down()
- elseif input == "left" then
- turtle.turnLeft()
- elseif input == "right" then
- turtle.turnRight()
- elseif input == "refuel" then
- turtle.refuel(1)
- elseif input == "select" then
- turtleslot = turtleslot + 1
- if turtleslot > 16 then turtleslot = 1 end
- turtle.select(turtleslot)
- elseif input == "digup" then
- turtle.digUp()
- elseif input == "digfront" then
- turtle.dig()
- elseif input == "digdown" then
- turtle.digDown()
- elseif input == "godown" then
- UWCgodown()
- elseif input == "" then
- return
- elseif true then
- end
- end
- --LAST SESSION
- function saveSavePoint(i)
- savestate = i
- local file = fs.open("uwcsavepoint","w")
- file.writeLine(savestate)
- file.writeLine(runningProgram)
- file.close()
- end
- function loadSavePoint()
- local file = fs.open("uwcsavepoint","r")
- savestate = tonumber(file.readLine())
- runningProgram = file.readLine()
- file.close()
- end
- function checkForLastSession()
- if not fs.exists("uwcsavepoint") then return end
- if not persistence then return end
- loadSavePoint()
- if savestate == 0 then
- startProgram(runningProgram)
- return
- end
- print("Turtle shutdown while it was working.")
- while savestate > 0 do
- if savestate >= 8 then
- cutWood()
- end
- if savestate == 7 then
- turtle.back()
- saveSavePoint(2)
- turtle.down()
- end
- if savestate == 2 then
- saveSavePoint(4)
- turtle.turnLeft()
- end
- if savestate == 4 then
- saveSavePoint(1)
- turtle.turnLeft()
- end
- if savestate == 3 then
- saveSavePoint(1)
- turtle.turnRight()
- end
- if savestate == 6 then
- saveSavePoint(1)
- turtle.turnRight()
- end
- if savestate == 1 then
- while not turtle.detect() and max < 15 do turtle.forward() max = max + 1 end
- if max == 15 then saveSavePoint(0) os.shutdown() end
- saveSavePoint(5)
- end
- if savestate == 5 then
- storeWood()
- saveSavePoint(0)
- turtle.turnRight()
- end
- end
- startProgram(runningProgram)
- end
- --ULTIMATE WOOD CHOPPER PROGRAMS
- --VARIABLES
- local dirtexpand, pipeexpand, obsidianpipeexpand, blockslot, coal, chest, furnace, dirt, pipe, ironpipe, goldpipe, obsidianpipe, woodenpipe, engine, lever, bonemeal, stone1, stone2, stone3, sapling, fuel = 2,3,4,5,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,3
- --MOVE FUNCTIONS
- function forward()
- while not turtle.forward() do end
- end
- function back()
- while not turtle.back() do end
- end
- function up()
- while not turtle.up() do end
- end
- function down()
- while not turtle.down() do end
- end
- --MAIN CHOP PROGRAM FUNCTIONS
- function moveForward(j)
- for i = 1,j do
- forward()
- end
- end
- function moveForwardRemove(j)
- for i = 1,j do
- turtle.dig()
- forward()
- end
- end
- function getCoal()
- local delay = os.startTimer(cancelTimer)
- print("Taking coal out of the chest!")
- print("If nothing happens the chest has too less materials!")
- print("Press Enter to terminate process!")
- while turtle.getFuelLevel() < amountMinFuelLevel do
- event = { os.pullEvent() }
- if event[1] == "timer" and event[2] == delay then
- turtle.select(16)
- turtle.suck()
- if turtle.getItemCount(16) > 0 then
- turtle.refuel(math.ceil((amountMinFuelLevel - turtle.getFuelLevel())/80))
- turtle.drop()
- if turtle.getItemCount(16) > 0 then
- turtle.select(16)
- turtle.refuel()
- end
- if turtle.getFuelLevel() < amountMinFuelLevel then
- delay = os.startTimer(2)
- end
- else
- delay = os.startTimer(cancelTimer)
- end
- elseif event[1] == "key" and event[2] == 28 then
- print("Terminated by User!")
- clearScreen()
- runningProgram = ""
- saveSavePoint(0)
- os.reboot()
- end
- end
- print("Succesful!")
- end
- function getSaplings()
- local taking = true
- local delay = os.startTimer(cancelTimer)
- print("Taking saplings out of the chest!")
- print("If nothing happens the chest has too less materials!")
- print("Press Enter to terminate process!")
- while taking == true do
- event = { os.pullEvent() }
- if event[1] == "timer" and event[2] == delay then
- if turtle.getItemCount(1) > 0 then
- if turtle.getItemCount(2) > 0 then
- turtle.select(1)
- turtle.suck()
- if turtle.getItemCount(3) > 0 then
- turtle.select(3)
- turtle.drop()
- end
- else
- turtle.select(1)
- turtle.suck()
- if turtle.getItemCount(2) > 0 then
- turtle.select(2)
- turtle.drop()
- end
- end
- else
- turtle.select(1)
- turtle.suck()
- end
- if turtle.getItemCount(3) > 0 then
- print("!!!!!!!!!")
- print("The sapling chest is full! Please take out some stacks, otherwise you lose items! The turtle will drop them!")
- print("!!!!!!!!!")
- turtle.select(3)
- turtle.dropDown()
- end
- if turtle.getItemCount(1) < amountMinSaplings then
- delay = os.startTimer(cancelTimer)
- else
- taking = false
- end
- elseif event[1] == "key" and event[2] == 28 then
- print("Terminated by User!")
- turtle.turnRight()
- forward()
- turtle.turnRight()
- clearScreen()
- runningProgram = ""
- saveSavePoint(0)
- os.reboot()
- end
- end
- print("Succesful!")
- end
- function getBonemeal()
- local taking = true
- local delay = os.startTimer(cancelTimer)
- print("Taking bonemeal out of the chest!")
- print("If nothing happens the chest has too less materials!")
- print("Press Enter to terminate process!")
- while taking == true do
- event = { os.pullEvent() }
- if usebonemeal == true then
- if event[1] == "timer" and event[2] == delay then
- if turtle.getItemCount(2) > 0 then
- turtle.select(2)
- turtle.suckUp()
- if turtle.getItemCount(3) > 0 then
- turtle.select(3)
- turtle.dropUp()
- end
- else
- turtle.select(2)
- turtle.suckUp()
- end
- if turtle.getItemCount(3) > 0 then
- print("!!!!!!!!!")
- print("The bonemeal chest is full! Please take out some stacks, otherwise you lose items! The turtle will drop them!")
- print("!!!!!!!!!")
- turtle.select(3)
- turtle.dropDown()
- end
- if turtle.getItemCount(2) < amountMinBonemeal then
- delay = os.startTimer(cancelTimer)
- else
- taking = false
- end
- elseif event[1] == "key" and event[2] == 28 then
- print("Terminated by User!")
- turtle.turnRight()
- forward()
- turtle.turnRight()
- clearScreen()
- runningProgram = ""
- saveSavePoint(0)
- os.reboot()
- end
- else
- turtle.select(2)
- turtle.dropUp()
- taking = false
- end
- end
- print("Successful!")
- end
- function storeWood()
- print("Storing wood in the chests!")
- chestfull = true
- while chestfull == true do
- if usebonemeal == true then
- for i=3,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- chestfull = turtle.drop()
- end
- end
- else
- for i=2,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- chestfull = turtle.drop()
- end
- end
- end
- chestfull = not chestfull
- if chestfull == true and turtle.detectUp() == true then
- print("Wood! Wood everywhere!!!")
- print("Your wood chests are full!")
- print("Try to add more vertical chests or take wood out of them.")
- print("")
- chopping = false
- while turtle.detectDown() == false do
- down()
- end
- turtle.turnRight()
- end
- if chestfull == true and turtle.detectUp() == false then
- up()
- print("This Chest is full!")
- end
- end
- while turtle.detectDown() == false do
- down()
- end
- print("Successful stored the wood!")
- print("")
- end
- function treeGrew()
- turtle.select(1)
- if not turtle.compare() then
- return true
- else
- return false
- end
- end
- function plantTree()
- print("Planting saplings!")
- turtle.select(1)
- moveForwardRemove(2)
- saveSavePoint(6)
- turtle.turnRight()
- turtle.place()
- saveSavePoint(2)
- turtle.turnLeft()
- back()
- turtle.place()
- saveSavePoint(6)
- turtle.turnRight()
- turtle.place()
- saveSavePoint(2)
- turtle.turnLeft()
- back()
- turtle.place()
- if usebonemeal then
- sleep(bonemealFirstDelay)
- end
- local treeNotGrown = true
- while treeNotGrown and turtle.getItemCount(2) > amountbonemealtimes + 1 do
- if usebonemeal then
- print("Fertilizing the tree with bonemeal!")
- turtle.select(2)
- for i=1,amountbonemealtimes do
- turtle.place()
- sleep(1)
- end
- end
- if not treeGrew() then
- print("Tree didnt grew yet!")
- print("Will try again in " .. bonemealTimer .." seconds...")
- back()
- sleep(bonemealTimer)
- forward()
- else
- treeNotGrown = false
- end
- end
- print("Successful planted new tree!")
- print("")
- end
- function getMaterials()
- saveSavePoint(4)
- turtle.turnLeft()
- saveSavePoint(1)
- turtle.turnLeft()
- moveForward(distance)
- turtle.select(3)
- if usebonemeal then
- turtle.dropDown(amountFurnaceWoodBonemeal)
- else
- turtle.dropDown(amountFurnaceWoodNoBonemeal)
- end
- saveSavePoint(5)
- storeWood()
- saveSavePoint(0)
- turtle.turnRight()
- if redstone.getInput("back") == false then
- print("Shutdown by redstone signal!")
- chopping = false
- runningProgram = ""
- saveSavePoint(0)
- else
- getCoal()
- saveSavePoint(2)
- turtle.turnRight()
- turtle.forward()
- saveSavePoint(3)
- turtle.turnRight()
- getSaplings()
- getBonemeal()
- saveSavePoint(2)
- turtle.turnLeft()
- moveForward(distance-1)
- end
- end
- function chopUp()
- turtle.dig()
- while turtle.detectUp() do
- turtle.digUp()
- up()
- turtle.dig()
- end
- end
- function chopDown()
- turtle.dig()
- while turtle.detectDown() do
- turtle.digDown()
- down()
- turtle.dig()
- end
- saveSavePoint(104)
- down()
- turtle.dig()
- end
- function cutWood()
- print("Chopping down the tree!")
- turtle.select(1)
- if savestate == 2 then
- turtle.dig()
- saveSavePoint(100)
- forward()
- end
- if savestate == 100 then
- saveSavePoint(101)
- turtle.turnRight()
- end
- if savestate == 101 then
- turtle.dig()
- saveSavePoint(102)
- turtle.turnLeft()
- end
- if savestate == 102 then
- chopUp()
- saveSavePoint(8)
- turtle.turnRight()
- end
- print("Reached the top of the tree!")
- if savestate == 8 then
- turtle.dig()
- saveSavePoint(9)
- forward()
- end
- if savestate == 9 then
- saveSavePoint(103)
- turtle.turnLeft()
- end
- if savestate == 103 then
- chopDown()
- saveSavePoint(10)
- back()
- end
- if savestate == 104 then
- turtle.dig()
- saveSavePoint(10)
- back()
- end
- print("Successful chopped the tree!")
- print("")
- if savestate == 10 then
- saveSavePoint(11)
- turtle.turnLeft()
- end
- if savestate == 11 then
- saveSavePoint(12)
- forward()
- end
- if savestate == 12 then
- saveSavePoint(2)
- turtle.turnRight()
- end
- end
- function chop()
- if redstone.getInput("back") == true then
- saveSavePoint(0)
- print("Starting the Fir Wood Chooper program!")
- getCoal()
- if turtle.getItemCount(3) > 0 or turtle.getItemCount(16) > 0 then
- saveSavePoint(1)
- turtle.turnLeft()
- storeWood()
- saveSavePoint(0)
- turtle.turnRight()
- end
- saveSavePoint(2)
- turtle.turnRight()
- forward()
- saveSavePoint(3)
- turtle.turnRight()
- if turtle.getItemCount(1) < amountMinSaplings then
- getSaplings()
- end
- if turtle.getItemCount(2) < amountMinBonemeal and usebonemeal == true then
- getBonemeal()
- end
- if turtle.getItemCount(2) > 0 and usebonemeal == false then
- turtle.select(2)
- turtle.dropUp()
- end
- saveSavePoint(1)
- turtle.turnRight()
- forward()
- saveSavePoint(0)
- turtle.turnRight()
- saveSavePoint(2)
- turtle.turnRight()
- moveForward(distance)
- while chopping == true do
- local needMaterials = false
- if turtle.getFuelLevel() < 200 then
- needMaterials = true
- print("Have to refuel!")
- end
- if turtle.getItemCount(1) < amountMinSaplings then
- needMaterials = true
- print("Need more Saplings!")
- end
- if turtle.getItemCount(2) < amountMinBonemeal and usebonemeal then
- needMaterials = true
- print("Need more bonemeal!")
- end
- if usebonemeal and turtle.getItemCount(amountMaxWoodSlotBonemeal) > 0 then
- needMaterials = true
- print("Enough wood harvested!")
- end
- if usebonemeal == false and turtle.getItemCount(amountMaxWoodSlotNoBonemeal) > 0 then
- needMaterials = true
- print("Enough wood harvested!")
- end
- if needMaterials == true then
- getMaterials()
- end
- if chopping == true then
- plantTree()
- cutWood()
- end
- end
- else
- runningProgram = ""
- saveSavePoint(0)
- end
- chopping = true
- end
- --MAIN DEBUG FUNCTIONS
- function UWCdebug()
- getCoal()
- turtle.turnRight()
- moveForward(distance)
- local height = 0
- turtle.select(1)
- turtle.dig()
- forward()
- turtle.dig()
- while not turtle.detectUp() and height < debugMaxHeight do
- turtle.up()
- height = height + 1
- end
- turtle.dig()
- while turtle.detectUp() do
- turtle.digUp()
- turtle.up()
- turtle.dig()
- height = height + 1
- end
- turtle.turnRight()
- turtle.dig()
- forward()
- turtle.turnLeft()
- turtle.dig()
- while height > 0 do
- turtle.digDown()
- down()
- turtle.dig()
- height = height - 1
- end
- back()
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- moveForward(distance)
- turtle.turnRight()
- print("Debug finished! Please take the wood out of the inventory!")
- print("Press Enter to get back into the menu!")
- read()
- end
- function FWCtwobytwo()
- print("Chopping down 2x2 tree.")
- while turtle.getFuelLevel() < 200 do
- sleep(2)
- turtle.select(1)
- turtle.refuel(1)
- print("Refueled!")
- end
- savestate = 2
- cutWood()
- end
- --FWConebyone
- function FWConebyone()
- print("Chopping down 1x1 tree.")
- while turtle.getFuelLevel() < 200 do
- sleep(2)
- turtle.select(1)
- turtle.refuel(1)
- print("Refueled!")
- end
- turtle.select(2)
- turtle.dig()
- forward()
- while turtle.compareUp() do
- turtle.digUp()
- up()
- end
- while not turtle.detectDown() do
- turtle.down()
- end
- end
- function UWCgodown()
- while not turtle.detectDown() do
- turtle.down()
- end
- end
- --MAIN PROGRAM
- if fs.exists(savefile) then
- loadVariables()
- end
- checkForLastSession()
- while running == true do
- runMenu()
- end
Advertisement
Add Comment
Please, Sign In to add comment