Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local distanceMoved = 0
- local torchCount = 0
- local sideDistance = 0
- local lengthDistance = 0
- local facing = "forward"
- local returnCommandSent = false
- local stopCommandSent = false
- local lastBlockAlreadyTorch = false
- local maxSideDistance = 30
- local lastFullLength = 5
- local blocksSinceLastDump = 0
- local dumps = 0
- function MainLoop()
- while not stopCommandSent do
- term.clear()
- sideDistance = 0
- lengthDistance = 0
- facing = "forward"
- print("Starting")
- Restock()
- if (not GoodFuelLevel(maxSideDistance + lastFullLength)) then
- print("Not enough fuel!")
- else
- StripMine()
- print("Returning")
- ReturnHome()
- end
- end
- end
- function FindStripmine()
- end
- function StripMine()
- turtle.turnLeft()
- turtle.turnLeft()
- --Start by moving forward 5 blocks
- for i = 1, lastFullLength, 1 do
- --Dig
- if turtle.detect() and CanCollect() then
- --print("Dig")
- turtle.dig()
- end
- if turtle.detectUp() and CanCollect() then
- turtle.digUp()
- end
- if returnCommandSent then
- break
- end
- if turtle.forward() then
- lengthDistance = lengthDistance + 1
- blocksSinceLastDump = blocksSinceLastDump + 1
- end
- distanceMoved = distanceMoved + 1
- end
- while GoodFuelLevel() and CanCollect() do
- --term.clear()
- --print("Moved to block " .. tostring(distanceMoved))
- --print("Fuel at: " .. tostring(turtle.getFuelLevel()))
- if (facing == "forward" and lengthDistance % 3 == 0) then
- if (sideDistance > 0) then
- turtle.turnRight()
- facing = "right"
- else
- turtle.turnLeft()
- facing = "left"
- end
- end
- if (facing == "left" and sideDistance >= maxSideDistance) then
- turtle.turnRight()
- facing = "forward"
- else
- if (facing == "right" and sideDistance <= -maxSideDistance) then
- turtle.turnLeft()
- facing = "forward"
- end
- end
- --Sets the respawn point for the next time the turtle goes out
- if (sideDistance == 0) then
- lastFullLength = lengthDistance
- end
- --Check if there is a torch above
- if math.abs(sideDistance) % 10 == 5 - 1 or math.abs(sideDistance) % 10 == 5 + 1 then
- local success, data = turtle.inspectUp()
- if (success and data.name == "minecraft:wall_torch") then
- lastBlockAlreadyTorch = true
- end
- end
- --Dig
- while turtle.detect() do
- turtle.dig()
- end
- while turtle.detectUp() and not lastBlockAlreadyTorch do
- turtle.digUp()
- end
- print("return: ", returnCommandSent)
- if returnCommandSent then
- return
- end
- --print("Torch check: " .. torchCount .. ", " .. lastTorchDistance .. ", " .. setTorchDistance)
- if math.abs(sideDistance) % 10 == 5 then
- if torchCount > 0 and GoodFuelLevel(2) and not lastBlockAlreadyTorch then
- if turtle.back() then
- turtle.select(LeastAmountOfTorchSlot())
- turtle.placeUp()
- turtle.forward()
- distanceMoved = distanceMoved + 2
- torchCount = torchCount - 1
- end
- end
- lastBlockAlreadyTorch = false
- end
- distanceMoved = distanceMoved + 1
- if turtle.forward() then
- if (facing == "forward") then
- lengthDistance = lengthDistance + 1;
- blocksSinceLastDump = blocksSinceLastDump + 1;
- else
- if (facing == "left") then
- sideDistance = sideDistance + 1;
- else
- if (facing == "right") then
- sideDistance = sideDistance - 1;
- end
- end
- end
- end
- end
- returnCommandSent = true
- end
- function GoodFuelLevel(extra)
- if extra == nil then
- extra = 0
- end
- --If the bot has gone 100 blocks without dumping it will go dump anyway
- if (blocksSinceLastDump == dumps*100 + 100) then
- return false
- end
- if turtle.getFuelLevel() <= lengthDistance + math.abs(sideDistance) + 1 + extra then
- --Find the slot with the least amount of coal
- local slot = LeastAmountOfCoalSlot()
- print("Best slot: ", slot)
- if slot ~= -1 then
- turtle.select(slot)
- turtle.refuel(1)
- return true
- else
- return false
- end
- end
- return true
- end
- function ReturnHome()
- if (facing == "forward") then
- print("In a forward tunnel")
- turtle.turnLeft()
- turtle.turnLeft()
- while (lengthDistance % 3 ~= 0) do
- if turtle.forward() then
- lengthDistance = lengthDistance - 1
- end
- end
- if (sideDistance > 0) then
- turtle.turnLeft()
- facing = "right"
- end
- if (sideDistance < 0) then
- turtle.turnRight()
- facing = "left"
- end
- end
- if (facing == "left" and sideDistance > 0) then
- print("Backing from left side")
- turtle.turnLeft()
- turtle.turnLeft()
- facing = "right"
- end
- if (facing == "right" and sideDistance < 0) then
- print("Backing from right side")
- turtle.turnLeft()
- turtle.turnLeft()
- facing = "left"
- end
- print("Getting back")
- while sideDistance ~= 0 do
- print("Side distance: ", sideDistance)
- --Dig
- while turtle.detect() do
- turtle.dig()
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- if turtle.forward() then
- if (facing == "left") then
- sideDistance = sideDistance + 1
- else
- sideDistance = sideDistance - 1
- end
- end
- end
- if (facing == "left") then
- print("Final turn")
- turtle.turnLeft()
- end
- if (facing == "right") then
- print("Final turn")
- turtle.turnRight()
- end
- print("Final stretch")
- while lengthDistance > 0 do
- print("Final distance: ", lengthDistance)
- --Dig
- if turtle.detect() then
- turtle.dig()
- end
- if turtle.detectUp() then
- turtle.digUp()
- end
- if turtle.forward() then
- lengthDistance = lengthDistance - 1
- end
- end
- print("I'm Home!")
- returnCommandSent = false
- end
- --Finds the slot with the least amount of coal. IF none is found return -1
- function LeastAmountOfCoalSlot()
- local slot = -1
- local topCount = 100
- for i = 1, 16, 1 do
- print("checking item: ", i)
- local item = turtle.getItemDetail(i)
- print("Item: ", item)
- if item then
- print("Is this coal? ", item.name)
- print("Count: ", item.count)
- if ((item.name == "minecraft:coal" or item.name == "minecraft:charcoal" or item.name == "modern_industrialization:lignite_coal") and item.count < topCount) then
- print("yes")
- slot = i
- topCount = item.count
- end
- end
- end
- return slot
- end
- --Finds the slot with the least amount of torch. IF none is found return -1
- function LeastAmountOfTorchSlot()
- local slot = -1
- local topCount = 100
- for i = 1, 16, 1 do
- print("checking item: ", i)
- local item = turtle.getItemDetail(i)
- print("Item: ", item)
- if item then
- print("Is this coal? ", item.name)
- print("Count: ", item.count)
- if ((item.name == "minecraft:torch") and item.count < topCount) then
- print("yes")
- slot = i
- topCount = item.count
- end
- end
- end
- return slot
- end
- --Checks if there is space for the given item
- function CanCollect()
- local fullSlots = 0
- for i = 1, 16, 1 do
- local item = turtle.getItemDetail(i)
- if item then
- fullSlots = fullSlots + 1
- end
- end
- if fullSlots >= 15 then
- print("I'm full. Will try to dispose")
- Dispose()
- fullSlots = 0
- --Checks again if its full after dispose
- for i = 1, 16, 1 do
- local item = turtle.getItemDetail(i)
- if item then
- fullSlots = fullSlots + 1
- end
- end
- end
- if fullSlots >= 15 then
- print("I'm full of good stuff")
- Dispose()
- returnCommandSent = true
- return false
- end
- return true
- end
- function Restock()
- for i = 1, 16, 1 do
- local item = turtle.getItemDetail(i)
- if item ~= nil then
- --Makes sure its not touching the fuel or torch stack if they exist
- if ((item.name == "minecraft:coal") or (item.name == "minecraft:torch") or (item.name == "minecraft:charcoal") or (item.name == "minecraft:soul_torch")) then
- else
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- local torchStack = turtle.getItemDetail(2)
- if torchStack ~= nil and (torchStack.name == "minecraft:torch" or torchStack.name == "minecraft:soul_torch") then
- torchCount = turtle.getItemCount(2)
- end
- end
- function Dispose()
- for i = 1, 16, 1 do
- local item = turtle.getItemDetail(i)
- if item ~= nil then
- if ((item.name == "minecraft:cobblestone") or (item.name == "minecraft:cobbled_deepslate") or (item.name == "minecraft:diorite") or (item.name == "minecraft:granite") or (item.name == "byg:soapstone") or (item.name == "minecraft:gravel") or (item.name == "minecraft:dirt") or (item.name == "minecraft:tuff") or (item.name == "minecraft:smooth_basalt") or (item.name == "ad_astra:moon_cobblestone") or (item.name == "minecraft:soul_soil") or (item.name == "minecraft:netherrack") or (item.name == "byg:scoria_cobblestone")) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- local torchStack = turtle.getItemDetail(2)
- if torchStack ~= nil and (torchStack.name == "minecraft:torch" or torchStack.name == "minecraft:soul_torch") then
- torchCount = turtle.getItemCount(2)
- end
- end
- function TryPlaceTorch()
- end
- MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement