Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --{program="aStairway",version="1.07",date="2024-05-07"}
- -- Pastebin "VXFbDSpi"
- ---------------------------------------
- -- Turtle-automated stairway digger.
- -- based on aTreeFarm by Kaikaku
- -- v1.04b", date="2018-01-07
- -- Pastebin Qn008fPa
- ---------------------------------------
- ---------------------------------------
- ---- PARAMETERS -----------------------
- ---------------------------------------
- local cVer ="1.00"
- local cMaxFuel = 20000
- local cMinFuel = cMaxFuel * 0.2
- local cSleep = 1 -- os.sleep value used to pace operation
- local cSlotStart = 1
- local cSlotLast = 15
- local cSlotChest = 16 -- ender chest
- ---------------------------------------
- -- BASIC FUNCTIONS FOR TURTLE CONTROL -
- ---------------------------------------
- -- calling with no parameter moves one block forward
- local function safeForward(n)
- if n == nil
- then
- turtle.suck()
- while not turtle.forward() do os.sleep(cSleep) end
- else
- for i = 1, n do
- turtle.suck()
- while not turtle.forward() do os.sleep(cSleep) end
- end
- end
- end
- local function safeDig() -- digs forward
- turtle.suck()
- os.sleep(cSleep)
- while turtle.detect() -- might be digging into multilayered sand or gravel
- do
- turtle.dig()
- os.sleep(cSleep) -- allow blocks to fall
- end
- end
- local function safeDigDown()
- turtle.suckDown() -- might be a sapling or stick
- os.sleep(cSleep)
- turtle.digDown() -- might not be anything to dig
- end
- local function safeDigUp()
- turtle.suckUp() -- remove drek on top
- os.sleep(cSleep)
- turtle.digUp() -- might not be anything to dig
- end
- ---------------------------------------
- ---- functions ------------------------
- ---------------------------------------
- -- wait for enter to be pressed
- local function waitEnter()
- write("Press enter to start:")
- read()
- end
- -- check fuel in turtle, attempt to replenish if low
- local function checkRefuel()
- if turtle.getFuelLevel() < cMaxFuel * 0.8
- then
- print("Fuel level is low, "..turtle.getFuelLevel()..".")
- print("Use refuel all command.")
- craftFuel()
- else
- print("Fuel level ok, "..turtle.getFuelLevel()..".")
- end
- end
- local function emptyInventory()
- -- assume 2 spaces above turtle to transfer
- print("transferring inventory...")
- turtle.select(cSlotChest) -- put chest ontop if turtle
- turtle.placeUp()
- for i = 1, 15 do -- scan slots
- turtle.select(i)
- turtle.dropUp() -- put entire stack in chest
- os.sleep(5) -- let ender magic work
- end
- turtle.select(cSlotChest) -- retrieve chest
- safeDigUp()
- turtle.select(cSlotStart) -- continue filling from start
- print("transfer done.")
- end
- ---------------------------------------
- -- dig a row, minimum width is 2
- ---------------------------------------
- local function digRow(rowWidth)
- -- assume facing stairway direction at start
- turtle.turnRight()
- if rowWidth > 2
- then
- for i = 3, rowWidth
- do
- turtle.dig()
- turtle.forward()
- end
- end
- turtle.dig() -- free dig with no motion
- turtle.turnRight()
- turtle.turnRight()
- if rowWidth > 2
- then
- for i = 3, rowWidth
- do
- turtle.forward()
- end
- end
- turtle.turnRight() -- face next slice
- end
- ---------------------------------------
- -- dig a 3 wide 4 high slice
- ---------------------------------------
- local function digSlice()
- -- assume facing bottom left of slice
- turtle.dig()
- turtle.forward() -- go into next slice
- turtle.digDown()
- if turtle.detectDown() -- might be bedrock, so stop
- then
- return false; -- can't dig, bedrock, all done
- end
- turtle.down()
- for i = 1, 4 do
- if i > 1
- then
- turtle.digUp()
- turtle.up()
- end
- digRow(3)
- end
- for i = 1, 3 do
- turtle.down() -- back down to floor
- end
- if turtle.getItemCount(cSlotLast) > 0 -- almost full, transfer all to ender chest.
- then
- emptyInventory()
- end
- return true -- slice dug
- end
- ---------------------------------------
- ---- main -----------------------------
- ---------------------------------------
- turtle.select(cSlotStart)
- term.clear()
- term.setCursorPos(1,1)
- if turtle.getFuelLevel() < cMinFuel
- then
- print("Fuel level "..turtle.getFuelLevel().." is too low.")
- print("Use command \"refuel all\" with 3 stacks of planks.") -- need to add fuel
- return
- end
- print("+-------------------------------------+")
- print("| aStairway "..cVer..", by NortWind |")
- print("+-------------------------------------+")
- print("| Digging a stairway: |")
- print("| Mining turtle sits facing the |")
- print("| first step into the ground |")
- print("| Put ender chest in slot 16 |")
- print("+-------------------------------------+")
- waitEnter()
- while digSlice()
- do
- os.sleep(cSleep)
- end
- turtle.turnRight() -- climb back to top of stairs
- turtle.turnRight()
- turtle.forward()
- while turtle.detect()
- do
- turtle.up()
- turtle.forward()
- end
- emptyInventory() -- clean leftover inventory
Add Comment
Please, Sign In to add comment