Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- paces = 0
- fuelStausLineNumber = 11
- paceStatusLineNumber = 12
- infoLineNumber = 13
- fuelLinePrefix = "Fuel: "
- waterBucketSlot = 2
- -- Predefined Functions
- function printToLine(str, line)
- a,b = term.getCursorPos()
- term.setCursorPos(1,line)
- term.clearLine(1,line)
- write(str)
- term.setCursorPos(a,b)
- end
- function replaceLava()
- local a,b = turtle.inspectDown() or 0,0
- if b~= "No block to inspect" and type(b) == "table" then
- if b.name then
- if b.name == "minecraft:lava" then
- --place water
- turtle.select(waterBucketSlot)
- turtle.place()
- sleep(1)
- turtle.place()
- end
- end
- end
- end
- function digSection()
- if turtle.detectDown() then
- turtle.digDown()
- end
- if turtle.detectUp() then
- turtle.digUp()
- end
- if turtle.detect() then
- turtle.dig()
- end
- replaceLava()
- end
- function turnBackwards()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function attemptForward()
- success = turtle.forward()
- if not success then
- while turtle.forward() == false do
- digSection()
- end
- end
- end
- function isFuelAvailable()
- turtle.select(fuelSlot)
- while turtle.refuel(0) == false do
- printToLine("Please insert a valid fuel",fuelStausLineNumber)
- end
- end
- function refuelIfNeccesary()
- turtle.select(fuelSlot)
- isFuelAvailable()
- while turtle.getFuelLevel() < fuelBuffer do
- turtle.select(fuelSlot)
- turtle.refuel(1)
- printToLine("Refueling",fuelStausLineNumber)
- end
- printToLine(fuelLinePrefix.. tostring(turtle.getFuelLevel()) , fuelStausLineNumber)
- -- print("Fuel level: "..tostring(turtle.getFuelLevel()) )
- end
- function estimateFuel()
- turtle.select(fuelSlot)
- --fuelPerItem = 80
- fuelItems = turtle.getItemCount(fuelSlot)-1
- --print(fuelPerItem)
- totalFuel = fuelPerItem*fuelItems + turtle.getFuelLevel()
- print(totalFuel)
- return totalFuel
- end
- function estimateFuelNeeded()
- fuelNeeded = length*2+fuelBuffer
- return fuelNeeded
- end
- function isEnoughFuel()
- fuelLevel = estimateFuel()
- neededFuel = estimateFuelNeeded()
- print(fuelLevel.."fuel detected")
- print("fuel required: ".. neededFuel)
- if fuelLevel < neededFuel then
- print("Not enough fuel for full journey")
- print(neededFuel-fuelBuffer.." more fuel units required")
- print("That is approx this qty of your fuel")
- print((neededFuel-fuelBuffer)/fuelPerItem)
- error("Insufficent fuel provided")
- end
- end
- function goBack()
- turnBackwards()
- for i=1, paces do
- attemptForward()
- refuelIfNeccesary()
- end
- turnBackwards()
- end
- function returnIfFull()
- slotsFull = 0
- for i=1, 16, 1 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then
- slotsFull = slotsFull + 1
- else
- end
- end
- if slotsFull >= maxSlot then
- print("max slots full. returning")
- goBack()
- error("No space left")
- end
- turtle.select(fuelSlot)
- end
- function msgAndWait(msg)
- write(tostring(msg)..": ")
- read("")
- write("")
- end
- function yesOrNoToBool(response)
- local responseStr = tostring(response)
- local responseLower = string.lower(responseStr)
- if responseLower == "yes" or responseLower == "y" then
- return true
- elseif responseLower == "no" or responseLower == "n" then
- return false
- else
- local errorDescription = "invalid response: '"..responseLower.."'"
- return nil
- end
- end
- function setToDefaultIfNil(var,defaultValue)
- if var == nil then
- return defaultValue
- else
- return var
- end
- end
- function getFuelValue()
- --fuelSlot = ,,,
- local getFuelVal = require("getFuelVal")
- local fuelVal = getFuelVal(fuelSlot)
- return fuelVal
- end
- --- set variables and request from user if needed. If all esle fails, set to defaults
- function setup()
- --values
- maxSlot = 12
- slotCheckTMax= 10
- fuelSlot = 1
- fuelBuffer = 100
- dist = args[1]
- confirm = yesOrNoToBool(args[2]) --or yesOrNoToBool("yes")
- goBackVal= yesOrNoToBool(args[3]) --or yesOrNoToBool("yes")
- fuelValue = args[4] --or getFuelValue()
- dist = setToDefaultIfNil(dist,10)
- confirm = setToDefaultIfNil(confirm,yesOrNoToBool("yes"))
- goBackVal = setToDefaultIfNil(goBackVal,yesOrNoToBool("yes"))
- fuelValue = setToDefaultIfNil(fuelValue,getFuelValue())
- --estimate fuel value
- --
- if dist == nil then
- print("Did you know,")
- print("You may also specify any values as paramaters? ")
- print("you can type - to not specify an expected paramater :")
- print(" 1: length forward")
- print(" 2: wait for confirmation screen before going? (yes/no)")
- print(" 3: go back after? (yes/no)")
- print(" 4: fuel value as a number")
- -- print("2: fuel slot no")
- -- print("3: fuel buffer" )
- -- print("4: fuel value (coal = 80)")
- -- print("5: max slots full")
- -- print("6: slot full check interval")
- -- print("7: show confirm menu? yes/no")
- end
- if dist == nil then
- write("Please enter length forward: ")
- end
- length = tonumber(dist) or tonumber(read()) or 10
- -- if args[2] == nil then
- -- write("please enter fuel slot: ")
- -- end
- -- fuelSlot = tonumber(args[2]) or tonumber(read()) or 1
- if fuelValue == nil then
- print()
- print(
- [[Please enter fuel value
- coal = 80
- biofuel can = 520
- scrap = 15
- coalfuel can = 1520
- wooden scaffolding = 15
- peat = 80
- sugarcane = 0 (Do not use it!)
- ...
- ]])
- write("press enter to see more")
- read("")
- print([[
- wooden tools = 10
- lava = 1000
- blaze rod = 120
- wood blocks = 15
- sticks = 5
- coal or charcoal = 80
- mushroom block = 15
- Coal coke = 320
- ]])
- write("select value: ")
- end
- fuelPerItem = tonumber(fuelValue) or tonumber(read()) --or 80
- print(confirm)
- if confirm == true then
- print("----------------")
- write("length: "..tostring(length) .."\n")
- write("FuelSlot: " .. tostring(fuelSlot) .."\n")
- write("Fuel buffer: "..tostring(fuelBuffer) .."\n")
- write("Item fuel value: "..tostring(fuelPerItem) .. "\n")
- print("")
- write("press enter to begin: ")
- read("X")
- elseif confirm == false then
- else
- print("Error: invalid confirm value.")
- read("X")
- --read("")
- end
- end
- function isTurtle()
- if not turtle then
- error("this program requires a turtle")
- end
- end
- function main()
- for i=1, length do
- if paces%slotCheckTMax == 0 then
- returnIfFull()
- end
- -- dig the blocks
- digSection()
- -- go forward and repeat until done
- canGoForward = turtle.forward()
- while not canGoForward do
- digSection()
- canGoForward = turtle.forward()
- end
- -- we have gone one pace
- paces = paces + 1
- refuelIfNeccesary()
- -- If we've gone all the way then 'return to sender'
- if paces == length then
- if goBackVal then
- printToLine("going back",infoLineNumber)
- goBack()
- sleep(1)
- else
- printToLine("not going back - ",infoLineNumber)
- sleep(1)
- end
- end
- --update display to show status
- printToLine("Paces: "..tostring(paces+1).."/"..tostring(length),paceStatusLineNumber)
- printToLine(fuelLinePrefix..tostring(turtle.getFuelLevel()),fuelStausLineNumber)
- end
- end
- ------------------------------------------------------------------
- -- \/ The magic begins here \/
- ------------------------------------------------------------------
- isTurtle()
- term.clear()
- setup()
- isEnoughFuel()
- term.clear()
- isFuelAvailable()
- refuelIfNeccesary()
- turtle.up()
- main()
- print()
- term.clear()
- term.setCursorPos(1,1)
- turtle.down()
Add Comment
Please, Sign In to add comment