Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SEPERATOR = "======================================="
- local BUCKET_ID = "minecraft:bucket"
- local FUELBUCKET_ID = "minecraft:lava_bucket"
- function MAIN()
- clear()
- welcomeMessage()
- untilSuccess(waitForBucket)
- clear()
- say(SEPERATOR)
- say("\nFueling up...\n")
- say(SEPERATOR)
- Refuel();
- clear()
- say(SEPERATOR)
- say("\nFinished.\n")
- say(SEPERATOR)
- end
- function clear() shell.run("clear"); end
- function say(...) print(...); end
- function untilSuccess(func,...)
- local s = false
- repeat s = func(...); until s;
- end
- function waitForBucket()
- turtle.select(1)
- local dat = turtle.getItemDetail()
- if not dat or dat.name ~= BUCKET_ID then say("Insert bucket in slot 1 to continue."); pause(); return false; end
- return true;
- end
- function waitForMinimumFuel()
- local f = turtle.getFuelLevel()
- if f < 1 then
- return false
- end
- end
- function pause()
- print("\nPress ENTER to continue...");
- local pX,pY = term.getCursorPos()
- --term.setCursorPos(0,0);
- io.read();
- clear()
- --term.setCursorPos(1,1)
- welcomeMessage();
- end
- function Refuel(dir)
- local blocksMoved = 0
- local stopEarly = false --
- repeat
- turtle.placeDown()
- turtle.select(1)
- local dat = turtle.getItemDetail()
- if dat and dat.name == FUELBUCKET_ID then
- turtle.refuel(1)
- end
- local moveTries = 0
- repeat
- local success = turtle.forward()
- if success == false then moveTries = moveTries + 1 end
- until success or moveTries > 3
- if moveTries <= 3 then
- blocksMoved = blocksMoved + 1
- print("Fuel: "..tostring(turtle.getFuelLevel()).."...")
- else
- print("Ran into a wall, returning early...")
- stopEarly = true
- end
- until turtle.getFuelLevel() == turtle.getFuelLimit() or stopEarly;
- repeat
- turtle.back()
- blocksMoved = blocksMoved - 1
- until blocksMoved == 0
- end
- function welcomeMessage()
- say(SEPERATOR)
- say("Welcome to Turtle Refill!")
- say(SEPERATOR)
- end
- function isValidDir(txt)
- local t = string.upper(txt)
- return not ( (t=="TOP") or (t=="BOTTOM") or (t=="LEFT") or (t=="RIGHT") or (t=="FRONT") or (t=="BACK") );
- end
- MAIN()
Advertisement
Add Comment
Please, Sign In to add comment