Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KnownFallingBlocks =
- {
- "minecraft:sand",
- "minecraft:gravel",
- "minecraft:anvil",
- "minecraft:dragon_egg",
- "Natura:heatsand"
- }
- KnownFuelAmounts =
- {
- {"Sticks", 5},
- {"Wood Blocks", 15},
- {"Coal", 80},
- {"Blaze Rods", 120},
- {"Lava Buckets", 1000}
- }
- __HaltOnInterruption = true
- __DigWhenUnableToMove = true
- function GetRecommendedFuel(cost)
- local Fuels = {}
- local MostEff = 1
- for i=1,#KnownFuelAmounts do
- local num = math.ceil(cost/(KnownFuelAmounts[i][2]))
- local waste = KnownFuelAmounts[i][2] - (cost%(KnownFuelAmounts[i][2]))
- Fuels[i] = {num, waste}
- end
- for i=1,#Fuels do
- if(i ~= MostEff) then
- if(Fuels[i][1] < Fuels[MostEff][1] and Fuels[i][2] <= (KnownFuelAmounts[i][2]*0.4)) then
- MostEff = i
- end
- end
- end
- return {KnownFuelAmounts[MostEff][1], Fuels[MostEff][1]}
- end
- function ConsumeFuel()
- DidFuel = false
- for i=1,16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel(turtle.getItemCount(i))
- DidFuel = true
- end
- end
- return DidFuel
- end
- function cls()
- term.setBackgroundColor(colours.black) -- Set the background colour to black.
- term.clear() -- Paint the entire display with the current background colour.
- term.setCursorPos(1,1) -- Move the cursor to the top left position.
- end
- function BooleanQuery(str)
- print(str .. "\n (Y for Yes, any other for No)\n")
- sinput = io.read()
- sinput = sinput:lower()
- output = false
- if(sinput:find("y")) then
- output = true
- end
- print("\n")
- return output
- end
- function ReadNum(str) -- str - String to show user on request.
- local fin = false
- print(str.."\n\n")
- local tmp = io.read()
- fin = tonumber(tmp)
- while not fin do
- print("Error: Input must be a number!")
- sleep(3)
- cls()
- print(str .. "\n\n")
- tmp = io.read()
- fin = tonumber(tmp)
- end
- print("\n")
- return tmp
- end
- function BlockCanFall() -- Check if the block in front of the Turtle can fall
- local IsBlock, BlockData = turtle.inspect()
- local IsFallingBlock = false
- if IsBlock then
- for i=1, #KnownFallingBlocks do
- if(KnownFallingBlocks[i] == BlockData.name) then
- IsFallingBlock = true
- break
- end
- end
- end
- return IsFallingBlock
- end
- function BlockAhead()
- return turtle.detect()
- end
- function BlockAbove()
- return turtle.detectUp()
- end
- function BlockBelow()
- return turtle.detectDown()
- end
- function Dig()
- while (BlockAhead()) do
- turtle.dig()
- sleep(1)
- end
- end
- function DigUp()
- while (BlockAbove()) do
- turtle.digUp()
- sleep(1)
- end
- end
- function DigDown()
- while (BlockBelow()) do
- turtle.digDown()
- sleep(1)
- end
- end
- function MoveForward()
- local DidMove = turtle.forward()
- local attempts = 0
- while (not DidMove) do
- if (attempts == 5) then
- if(__HaltOnInterruption) then
- break
- end
- if (__DigWhenUnableToMove) then
- Dig()
- end
- end
- attempts = attempts + 1
- DidMove = turtle.forward()
- end
- return DidMove
- end
- function MoveUp()
- local DidMove = turtle.up()
- local attempts = 0
- while (not DidMove) do
- if (attempts == 5) then
- if(__HaltOnInterruption) then
- break
- end
- if (__DigWhenUnableToMove) then
- DigUp()
- end
- end
- attempts = attempts + 1
- DidMove = turtle.up()
- end
- return DidMove
- end
- function MoveDown()
- local DidMove = turtle.down()
- local attempts = 0
- while (not DidMove) do
- if (attempts == 5) then
- if(__HaltOnInterruption) then
- break
- end
- if (__DigWhenUnableToMove) then
- DigDown()
- end
- end
- attempts = attempts + 1
- DidMove = turtle.down()
- end
- return DidMove
- end
- function DigMove()
- Dig()
- local CouldMove = MoveForward()
- if(not CouldMove) then
- if(BlockAhead()) then
- Dig()
- CouldMove = MoveForward()
- end
- end
- return CouldMove
- end
- function DigMoveUp()
- DigUp()
- local CouldMove = MoveUp()
- if(not CouldMove) then
- if(BlockAbove()) then
- DigUp()
- CouldMove = MoveUp()
- end
- end
- return CouldMove
- end
- function DigMoveDown()
- DigDown()
- local CouldMove = MoveDown()
- if(not CouldMove) then
- if(BlockBelow()) then
- DigDown()
- CouldMove = MoveDown()
- end
- end
- return CouldMove
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement