Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = require( "blib" )
- local torch = "minecraft:torch"
- local chest = "minecraft:chest"
- local enderChest = "minecraft:ender_chest"
- local chestDumpLoc = {x = 1, y = 0, z = 1, xf = 0, yf = -1}
- local Length
- local Width
- local reqTorches
- local reqChests
- function Shutdown(message)
- print(message)
- print("Powering down...")
- return 1
- end
- function NavigateToLocation(location, order)
- for i = 1, 2 do
- print(order[i] == "x")
- print(order[i])
- print("x")
- if(order[i] == "x") then
- -- 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
- elseif (order[i] == "y") then
- -- 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
- end
- 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
- --- Actual Mining ---
- function Start()
- if(m.SelectItem("minecraft:chest")) then
- turtle.digDown()
- turtle.placeDown()
- end
- m.Forward3() -- The turtle starts outside the square, as such, it enters at the start, and the Y index
- -- is actually decremented by one, since mining on the x axis will manage one block off each
- -- level change
- local torchL = 0
- local torchW = 8
- -- fix not finish on width
- -- fix chest storage thing (puts in coal)
- for x = 1, Width do -- starting length cuts one turn off, but not one column off. see below
- torchW = torchW + 1 -- increment torchPlacingWidth
- for y = 1, Length - 1 do -- width cuts one length down off the next
- -- check for fuel
- local fuelAmount = DistanceFromLocation(chestDumpLoc) + 5
- if(not m.CheckFuel(fuelAmount)) then
- local savedLoc = m.table_deepcopy(m.coords)
- NavigateToLocation(chestDumpLoc, {"x", "y"})
- 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(fuelAmount)
- NavigateToLocation(savedLoc, {"y", "x"})
- end
- -- check for torch placement
- torchL = torchL + 1 -- increment torchPlacementLength
- if(reqTorches == true) then
- if(torchL >= 8 and torchW >= 6) then -- if its been 6 blocks wide and traveled 8 blocks down, place a torch
- if(not m.PlaceTorch()) then
- local savedLoc = m.table_deepcopy(m.coords)
- NavigateToLocation(chestDumpLoc, {"x", "y"})
- while not m.SelectItem("minecraft:torch") do
- print("Out of torches ...")
- print("Place coal in the inventory to continue.")
- os.sleep(3)
- end
- NavigateToLocation(savedLoc, {"y", "x"})
- end
- torchL = 1
- end
- end
- -- check if inventory is full
- if(m.InventoryFull() == true) then
- local savedLoc = m.table_deepcopy(m.coords)
- NavigateToLocation(chestDumpLoc, {"x", "y"})
- if(not m.DumpItemsExistingChest("down")) then
- local s, data = turtle.inspectDown()
- while data.name ~= "minecraft:chest" do
- s, data = turtle.inspectDown()
- print("Waiting for chest ... ")
- os.sleep(3)
- end
- m.DumpItemsExistingChest("down")
- end
- NavigateToLocation(savedLoc, {"y", "x"})
- end
- m.Forward3()
- end
- if( Width - x ~= 0) then -- Technically on the last column, we continue forward, but don't turn into the next column
- if(math.fmod(x, 2) == 0) then -- if we're on an even column, turn left
- m.TurnLeftDig()
- else -- odd columns (start is 1 btw) turn right!
- m.TurnRightDig()
- end
- end
- if(torchW >= 6)then -- if its been 6 blocks wide, then reset!
- torchW = 0
- end
- end
- return 1
- end
- --- main ---
- function Main()
- local response
- print("Welcome to the BetterMining Program")
- print("BetterMining will mine a 2D plane defined by your X and Y inputs")
- print("")
- print("Do you want to require torches?")
- print("(y for yes, n for no)")
- response = read()
- if(response == "y") then
- reqTorches = true
- else
- reqTorches = false
- end
- -- check if has items
- if(m.GetItemIndex(torch) == nil and reqTorches == true)then
- print("You don't have any torches!")
- return
- end
- --check if has fuel
- if(not m.CheckFuel(10))then
- print("You don't have fuel!")
- return
- end
- m.Clear()
- -- 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
- print("Mining Started ... ")
- Start()
- NavigateToLocation(chestDumpLoc, {"x", "y"})
- print("Finished!")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement