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 Length
- local Width
- local fuelMin = 25
- local reqTorches
- local function ends_with(str, ending)
- if(str == nil) then
- return false
- end
- return ending == "" or str:sub(-#ending) == ending -- colon operator and string doc - https://docs.coronalabs.com/api/library/string/sub.html
- end
- function Shutdown(message)
- print(message)
- print("Powering down...")
- return 1 -- By C convention 0 is success, 1 is failure
- end
- function IsOre(OreName)
- local returnVal = ends_with(OreName, "ore")
- if(OreName == "minecraft:diamond_ore") then
- returnVal = false
- end
- return(returnVal)
- end
- function MineIfOre(direction)
- local success, inspection
- if(direction == "up") then
- success, inspection = turtle.inspectUp()
- if(IsOre(inspection.name)) then
- turtle.digUp()
- end
- return
- elseif(direction == "down") then
- success, inspection = turtle.inspectDown()
- if(IsOre(inspection.name) or inspection.name == "minecraft:lava") then
- turtle.digDown()
- if(m.SelectItem("minecraft:cobblestone") == true) then
- turtle.placeDown()
- end
- end
- return
- elseif(direction == "forward") then
- success, inspection = turtle.inspect()
- else
- success, inspection = turtle.inspect()
- end
- if(IsOre(inspection.name)) then
- turtle.dig()
- end
- end
- function InspectLR()
- m.CheckFuel(fuelMin)
- turtle.turnLeft()
- MineIfOre()
- turtle.turnRight()
- turtle.turnRight()
- MineIfOre()
- turtle.turnLeft()
- end
- function DigSequence()
- m.CheckFuel(fuelMin)
- m.DetectAndDig()
- turtle.forward()
- MineIfOre("down")
- InspectLR()
- turtle.digUp()
- turtle.up()
- MineIfOre("up")
- InspectLR()
- turtle.down()
- end
- function FirstLap()
- local trueWidth = (Width - 1)*2 + Width
- for y = 1, Length do
- m.CheckFuel(fuelMin)
- m.DetectAndDig()
- turtle.forward()
- turtle.digUp()
- end
- turtle.turnRight()
- for x = 1, trueWidth - 1 do
- m.CheckFuel(fuelMin)
- m.DetectAndDig()
- turtle.forward()
- turtle.digUp()
- end
- turtle.turnRight()
- for y = 1, Length - 1 do
- m.CheckFuel(fuelMin)
- m.DetectAndDig()
- turtle.forward()
- turtle.digUp()
- end
- turtle.turnRight()
- for x = 1, trueWidth - 1 do
- m.CheckFuel(fuelMin)
- m.DetectAndDig()
- turtle.forward()
- turtle.digUp()
- end
- turtle.turnRight()
- end
- function Start()
- FirstLap()
- m.CheckFuel(fuelMin)
- InspectLR()
- turtle.digUp()
- turtle.up()
- InspectLR()
- turtle.down()
- local torchL = 6
- 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
- if(not m.CheckFuel(fuelMin)) then
- return Shutdown("Out of Fuel!")
- end
- -- check if inventory is full
- if(m.InventoryFull() == true) then
- if(m.DumpItemsChest() == false) then
- return Shutdown("Out of chests!")
- end
- end
- -- check for torch placement
- torchL = torchL + 1 -- increment torchPlacementLength
- if(reqTorches == true) then
- if(torchL >= 6) then -- if its been 6 blocks wide and traveled 8 blocks down, place a torch
- if(not m.PlaceTorch("left")) then
- return Shutdown("Out of torches!")
- end
- torchL = 0
- end
- end
- -- Actual Mining Sequence
- DigSequence()
- end
- if( Width - x ~= 0) then -- Technically on the last column, we continue forward, but don't turn into the next column
- m.CheckFuel(fuelMin)
- if(math.fmod(x, 2) == 0) then -- if we're on an even column, turn left (LUA STARTS WITH 1 weird i know)
- turtle.turnLeft()
- DigSequence()
- DigSequence()
- DigSequence()
- turtle.turnLeft()
- else -- odd columns (start is 1 btw) turn right!
- turtle.turnRight()
- DigSequence()
- DigSequence()
- DigSequence()
- turtle.turnRight()
- end
- end
- end
- end
- function Main()
- local response
- print("Welcome to the Strip Mining Program")
- print("Strip Mining will mine hallways 2 blocks apart, and try its best to mine out all surrounding ore")
- 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
- elseif( m.GetItemIndex(chest) == nil) then
- print("You don't have any chests!")
- return
- end
- ----------------- check if has fuel ---------------------------
- if(not m.CheckFuel(10))then
- print("You don't have fuel!")
- return
- end
- --------------- 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("Strip Mining Started ... ")
- Start()
- print("finished!")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement