Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = require("blib")
- local chestDumpLoc = {x = 1, y = 1, z = 1, xf = 0, yf = -1}
- function NavigateToLocation(location)
- -- Navigate Z axis
- while m.coords.z ~= location.z do
- if(m.coords.z < location.z) then
- m.MapUp()
- else
- m.MapDown()
- end
- end
- -- Orient Turtle Y Direction
- if(m.coords.y < location.y) then
- while m.coords.yf ~= 1 do
- m.MapTurnRight()
- end
- else
- while m.coords.yf ~= -1 do
- m.MapTurnRight()
- end
- end
- -- Navigate Y axis
- while m.coords.y ~= location.y do
- m.MapForward()
- end
- -- Orient Turtle X Direction
- if(m.coords.x < location.x) then
- while m.coords.xf ~= 1 do
- m.MapTurnRight()
- end
- else
- while m.coords.xf ~= -1 do
- m.MapTurnRight()
- end
- end
- -- Navigate X axis
- while m.coords.x ~= location.x do
- m.MapForward()
- end
- -- Orient according to location specs
- while m.coords.xf ~= location.xf do
- m.MapTurnRight()
- end
- while m.coords.yf ~= location.yf do
- m.MapTurnRight()
- end
- end
- function DistanceFromLocation(location)
- xd = math.abs(location.x - m.coords.x)
- yd = math.abs(location.y - m.coords.y)
- zd = math.abs(location.z - m.coords.z)
- return xd + yd + zd
- end
- --- Digging Process ---
- function Start()
- m.MapForward()
- if(m.SelectItem("minecraft:chest")) then
- m.MapTurnRight()
- m.MapTurnRight()
- turtle.place()
- m.MapTurnRight()
- m.MapTurnRight()
- end
- for z = 1, Height do
- for x = 1, Width do -- starting length cuts one turn off, but not one column off. see below
- for y = 1, Length - 1 do -- width cuts one length down off the next
- -- check for fuel
- local d = DistanceFromLocation(chestDumpLoc) + 5
- if(not m.CheckFuel(d)) then
- local savedLoc = m.table_deepcopy(m.coords)
- NavigateToLocation(chestDumpLoc)
- while not m.SelectItem("minecraft:coal") do
- print("Out of fuel ...")
- print("Place coal in the inventory to continue.")
- os.sleep(3)
- end
- m.CheckFuel(d)
- NavigateToLocation(savedLoc)
- end
- if(m.InventoryFull()) then
- -- navigate to chestLoc
- local savedLoc = m.table_deepcopy(m.coords)
- NavigateToLocation(chestDumpLoc)
- m.DumpItemsExistingChest()
- NavigateToLocation(savedLoc)
- end
- m.DetectAndDig()
- m.MapForward()
- end
- if(Width - x ~= 0) then -- Technically on the last column, we want to continue forward so we can't do 'Width - 1', but don't turn into the next column
- if(lastTurn == "Right") then -- if we're on an even column, turn left
- m.MapTurnRightDig()
- lastTurn = "Left"
- else -- odd columns (start is 1 btw) turn right!
- m.MapTurnLeftDig()
- lastTurn = "Right"
- end
- end
- end
- if(Height - z ~= 0) then
- turtle.digDown()
- m.MapDown()
- m.MapTurnLeft()
- m.MapTurnLeft()
- end
- end
- return 1
- end
- function Main()
- local response
- print("Welcome to the Minecraft file building program")
- print("What length do you want to excavate?")
- -- Gets Y Input from user
- print("Length?")
- Length = tonumber(io.read())
- while Length == nil do
- print("oops! enter a number!")
- Length = tonumber(io.read())
- end
- -- Gets X Input from user
- print("")
- print("Width?")
- Width = tonumber(io.read())
- while Width == nil do
- print("oops! enter a number!")
- Width = tonumber(io.read())
- end
- -- Gets Z Input from user
- print("")
- print("Depth?")
- Height = tonumber(io.read())
- while Height == nil do
- print("oops! enter a number!")
- Height = tonumber(io.read())
- end
- print("Mining Started ... ")
- Start()
- chestDumpLoc.y = 0
- chestDumpLoc.z = 1
- NavigateToLocation(chestDumpLoc)
- print("Finished!")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement