Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Made by Rnen10
- -- If problems/questions feel free to contact me
- -- https://twitter.com/Rnen10
- -- rnen. (Evan#7181) on discord
- -- This automates a Forestry wood pile oven using a CC turtle. (Needs a pickaxe and access to flint to the right, wood piles below, output on top). Made for a 3x3 oven, start off the turtle on the middle. If the coordinate system gets broken, just run "rm coalData"
- ---@diagnostic disable-next-line: undefined-global
- term.clear()
- term.setCursorPos(1, 1)
- --[[The sleep time before closing it off after lighting]]
- local lightTime = 1
- --[[The minimum fuel required for one oven run]]
- local min_fuel = 40
- --[[The time to wait for the next batch. waitTime * 10 = seconds]]
- local waitTime = 150
- local debug = false
- local brickSlot = 14
- local flintSlot = 15
- local woodSlot = 16
- local function DEBUG()
- return (fs.exists("coaldebug.lua") or debug)
- end
- local done = false
- local turtleState = { ["x"] = 0, ["y"] = 0, ["rot"] = 1, ["action"] = 0 }
- local function split(inputstr)
- local t = {}
- for str in string.gmatch(inputstr, "[^\r\n]+") do
- table.insert(t, str)
- end
- return t
- end
- --[[Refreshes the GUI with new text]]
- local function NewLine(Str)
- local barLength = 40
- local tempPercentage = 0
- term.clear()
- term.setCursorPos(1, 2)
- print("-------------[CoalBot v1.0]------------")
- term.setCursorPos(11, 5)
- write("v {Current action} v")
- local splString = split(Str)
- local size1 = 0
- for _ in pairs(splString) do size1 = size1 + 1 end
- if size1 > 1 then
- for i, v in ipairs(splString) do
- term.setCursorPos(21 - (math.floor(string.len(v) / 2)), i + 7)
- term.write(v)
- end
- else
- term.setCursorPos(21 - (math.floor(string.len(Str) / 2)), 8)
- term.write(Str)
- end
- --if DEBUG() then
- -- term.setCursorPos(1, 11)
- -- print("X: " ..
- -- turtleState["x"] ..
- -- " Y: " .. turtleState["y"] .. " Rot: " .. turtleState["rot"] .. " Action: " .. turtleState["action"])
- --end
- local fuelStr = "[Current Fuel - %" .. tostring((math.floor(turtle.getFuelLevel()))) .. "]"
- term.setCursorPos(21 - (math.floor(string.len(fuelStr) / 2)), 12)
- write(fuelStr)
- term.setCursorPos(1, 13)
- barLength = turtle.getFuelLevel() / 100 * 40
- if barLength > 40 then barLength = 40 end
- if term.isColor() then
- term.setBackgroundColor(colors.green)
- else
- term.setBackgroundColor(colors.white)
- end
- for i = 1, (barLength) do
- write(" ")
- end
- if barLength < 40 then
- if term.isColor() then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.gray) end
- local remainingBarLength = (40 - barLength)
- for i = 1, (remainingBarLength) do
- write(" ")
- end
- end
- term.setBackgroundColor(colors.black)
- end
- --[[Reads the turtleState data from a file, or writes a new one if it doesn't exist]]
- local function CheckPosition()
- if fs.exists("coalData") then
- local file = fs.open("coalData", "r")
- local data = file.readAll()
- file.close()
- turtleState = textutils.unserialize(data)
- else
- local file = fs.open("coalData", "w")
- file.write(textutils.serialize(turtleState))
- file.close()
- end
- end
- --[[Saves the turtleState data to a file]]
- local function SavePosition()
- local file = fs.open("coalData", "w")
- file.write(textutils.serialize(turtleState))
- file.close()
- end
- --[[Goes Forward. Saves change in cordinate]]
- local function Forward()
- turtle.forward()
- if turtleState["rot"] == 1 then
- turtleState["x"] = turtleState["x"] + 1
- elseif turtleState["rot"] == 3 then
- turtleState["x"] = turtleState["x"] - 1
- elseif turtleState["rot"] == 0 then
- turtleState["y"] = turtleState["y"] - 1
- elseif turtleState["rot"] == 2 then
- turtleState["y"] = turtleState["y"] + 1
- end
- SavePosition()
- end
- --[[Turns right. Saves change in cordinate]]
- local function Right()
- turtle.turnRight()
- turtleState["rot"] = turtleState["rot"] + 1
- if turtleState["rot"] > 4 then turtleState["rot"] = 0 end
- SavePosition()
- end
- --[[Turns left. Saves change in cordinate]]
- local function Left()
- turtle.turnLeft()
- turtleState["rot"] = turtleState["rot"] - 1
- if turtleState["rot"] < 0 then turtleState["rot"] = 4 end
- SavePosition()
- end
- --[[Goes back. Saves change in cordinate]]
- local function Back()
- turtle.back()
- if turtleState["rot"] == 1 then
- turtleState["x"] = turtleState["x"] - 1
- elseif turtleState["rot"] == 3 then
- turtleState["x"] = turtleState["x"] + 1
- elseif turtleState["rot"] == 0 then
- turtleState["y"] = turtleState["y"] + 1
- elseif turtleState["rot"] == 2 then
- turtleState["y"] = turtleState["y"] - 1
- end
- SavePosition()
- end
- --[[Empties the inventory into a chest above the turtle]]
- local function Empty()
- if not done then NewLine("Emptying Inventory") end
- for i = 1, 16 do
- if i == flintSlot or i == woodSlot then
- else
- turtle.select(i)
- if not turtle.dropUp() and (turtle.getItemCount() > 0) then
- NewLine("Chest is full!")
- done = true
- break
- end
- end
- end
- turtle.select(1)
- end
- --[[Checks the fuel level, if below required level, returns false]]
- local function CheckFuel()
- return turtle.getFuelLevel() > min_fuel
- end
- local function CheckEmpty(bool)
- local invItemNumber = 0
- NewLine("Counting Items...")
- for i = 1, 16 do
- if bool and (i == flintSlot or i == woodSlot) then
- else
- turtle.select(i)
- invItemNumber = invItemNumber + turtle.getItemCount(i)
- end
- end
- turtle.select(1)
- return invItemNumber < 1
- end
- local function CheckFlint()
- return turtle.getItemCount(flintSlot) > 0
- end
- local function GetFlint()
- Right()
- turtle.select(flintSlot)
- turtle.suck(1)
- turtle.select(1)
- Left()
- return turtle.getItemCount(flintSlot) > 0
- end
- --[[Replaces blocks above and below]]
- local function ReplaceBlocks()
- turtle.select(1)
- turtle.digDown()
- turtle.digUp()
- turtle.select(woodSlot)
- turtle.placeDown()
- turtle.placeUp()
- turtle.select(1)
- end
- --[[Goes through the oven and replaces all the ash with new wood]]
- local function ResetOven()
- NewLine("Replacing Ash/Wood")
- if turtle.getItemCount(woodSlot) < 64 then
- turtle.select(woodSlot)
- turtle.suckDown(64 - turtle.getItemCount())
- if turtle.getItemCount() < 27 then
- NewLine("Not enough Wood Piles!!\nStopping...")
- done = true
- return false
- end
- end
- turtle.select(brickSlot)
- turtle.dig()
- Forward()
- turtle.dig()
- Forward()
- for i = 1, 3 do
- ReplaceBlocks()
- Left()
- turtle.dig()
- Forward()
- ReplaceBlocks()
- Back()
- turtle.select(woodSlot)
- turtle.place()
- turtle.select(1)
- Right()
- Right()
- turtle.dig()
- Forward()
- ReplaceBlocks()
- Back()
- turtle.select(woodSlot)
- turtle.place()
- turtle.select(1)
- Left()
- if i < 3 then
- turtle.dig()
- Forward()
- end
- end
- for i = 1, 3 do
- Back()
- turtle.select(woodSlot)
- turtle.place()
- end
- Back()
- turtle.select(flintSlot)
- turtle.place()
- sleep(lightTime)
- turtle.select(brickSlot)
- turtle.place()
- turtle.select(1)
- return true
- end
- -- ===========STARTUP SEQUENCE==========
- NewLine("Checking Fuel & Position...")
- --if turtle.getFuelLevel() > 20 then
- CheckPosition()
- --end
- if not CheckFuel() then
- NewLine("Turtle needs to be primed with fuel!")
- done = true
- return
- end
- Empty()
- --if CheckEmpty() then
- -- NewLine("Inventory Empty!")
- -- done = true
- -- return
- --end
- -- ===========STARTUP SEQUENCE END======
- -- ===========MAIN LOOP=================
- while not done do
- if not CheckFlint() then
- if not GetFlint() then
- NewLine("Out of Flint & Steel!")
- done = true
- break
- end
- end
- if not ResetOven() then
- break
- end
- if not CheckFuel() then
- NewLine("Refueling...")
- while not CheckFuel() do
- for i = 1, 2 do
- turtle.select(i)
- turtle.refuel(1)
- end
- end
- end
- Empty()
- for i = 1, waitTime do
- NewLine("Waiting For BurnCycle...\n" .. ((waitTime - i) * 10 + 10) .. "s")
- sleep(10)
- end
- end
- -- ===========MAIN LOOP END=============
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement