Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Ores = {Diamond, Coal, Iron, Gold, Emerald}
- local AmountToMine = 0
- local MineableBlocks = 0
- local PMovements = 0
- local RMovements = 0
- local Fueled = false
- local BlocksMined = 0
- local function mined(BlocksMined)
- BlocksMined = BlocksMined + 1
- return BlocksMined
- end
- local function GetMineableBlocks(PMovements)
- PMovements = turtle.getFuelLevel()
- for i = 3,PMovements do
- MineableBlocks = MineableBlocks + 1
- end
- return MineableBlocks
- end
- local function GetRequiredMovements(AmountToMine)
- for i = 1,AmountToMine do
- RMovements = RMovements + 3
- end
- return RMovements
- end
- local function checkfuel(AmountToMine,MineableBlocks,RMovements,PMovements)
- turtle.refuel()
- MineableBlocks = GetMineableBlocks(PMovements)
- if turtle.getFuelLevel() <= RMovements then
- print("Insert fuel in slot 1. ")
- return false
- elseif tonumber(AmountToMine) >= MineableBlocks then
- print("You may not dig that many blocks!")
- return false
- else
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
- turtle.refuel(halfStack) -- consume half the stack as fuel
- end
- end
- return true
- end
- end
- local function MINEALG(BlocksMined, AmountToMine)
- local BlockFS = turtle.detect()-- Block Forward Status.
- local BlockDS = turtle.detectDown()-- Block Down Status.
- for i = 1,AmountToMine do
- BlockFS = turtle.detect()
- BlockDS = turtle.detectDown()
- if BlockFS == true then
- BlockDS = turtle.detectDown()
- if BlockDS == true then
- turtle.digDown()
- turtle.forward()
- BlocksMined = mined(BlocksMined)
- end
- turtle.dig() -- Mine forwards.
- BlocksMined = mined(BlocksMined)
- turtle.forward() -- Move forwards.
- if BlockDS == false then
- turtle.forward()-- Move forwards.
- else end
- elseif BlockFS == false then
- while BlockFS == false do
- if BlockDS == true then
- turtle.digDown()
- turtle.forward()
- BlocksMined = mined(BlocksMined)
- else
- turtle.forward() -- Move forwards.
- BlockFS = turtle.detect()
- end
- end
- end
- end
- return BlocksMined
- end
- local function initialize(MineableBlocks,AmountToMine,RMovements,Fueled)
- MineableBlocks = GetMineableBlocks(PMovements) -- Get the largest possible amount of blocks that could be digd at the current fuel level.
- print("Mine Length?") -- Self explanatory.
- AmountToMine = io.read() -- Read the user inputurtle.
- RMovements = GetRequiredMovements(AmountToMine) -- Get the required movments for a tunnel of that length.
- Fueled = checkfuel(AmountToMine,MineableBlocks,RMovements,PMovements) -- Check to see if the current fuel level will satiate your instructions.
- if Fueled == true then
- MINEALG(BlocksMined,AmountToMine) -- Execute the Mining Algorithm.
- else
- while Fueled == false do
- os.sleep(1)
- checkfuel(AmountToMine,MineableBlocks,RMovements) -- Check the fuel level until it is high enough to that the turtle may dig.
- end
- end
- end
- initialize(MineableBlocks,AmountToMine,RMovements,Fueled)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement