Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blackList = {
- ["minecraft:stone"] = true,
- ["minecraft:cobblestone"] = true,
- ["minecraft:gravel"] = true,
- ["minecraft:dirt"] = true,
- }
- local useFuel = true
- local backFill = true
- local fuelLevel = 0
- local function checkSlots()
- local emptySlots = 0
- local enderChestSlot = 0
- for slotNum = 1, 16 do
- local itemData = turtle.getItemDetail(slotNum)
- if itemData then
- if itemData.name == "EnderStorage:enderChest" then
- enderChestSlot = slotNum
- end
- else
- emptySlots = emptySlots + 1
- end
- end
- if emptySlots < 5 then
- if enderChestSlot > 0 then
- turtle.select(enderChestSlot)
- if turtle.placeUp() then
- for slotNum = 1, 16 do
- local itemData = turtle.getItemDetail(slotNum)
- if itemData and not blackList[itemData.name] then
- turtle.select(slotNum)
- turtle.dropUp()
- local attempts = 1
- while turtle.getItemCount(slotNum) > 0 do
- if attempts > 30 then
- turtle.digUp()
- return false
- end
- sleep(1)
- turtle.dropUp()
- attempts = attempts + 1
- end
- end
- end
- turtle.select(1)
- turtle.digUp()
- end
- else
- return false
- end
- end
- return true
- end
- local function checkFuelLevel()
- fuelLevel = turtle.getFuelLevel()
- if type(fuelLevel) == "string" then
- fuelLevel = math.huge
- end
- end
- --taken from refuel program
- local function refuel(nLimit)
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
- local nBurn = math.min( nLimit, nCount )
- turtle.select( n )
- if turtle.refuel( nBurn ) then
- local nNewCount = turtle.getItemCount(n)
- nLimit = nLimit - (nCount - nNewCount)
- end
- end
- end
- turtle.select(1)
- checkFuelLevel()
- return nLimit <= 0
- end
- local function tryBackFill(turtlePlace)
- for slotNum = 1, 16 do
- local itemData = turtle.getItemDetail(slotNum)
- if itemData and blackList[itemData.name] then
- turtle.select(slotNum)
- turtlePlace()
- break
- end
- end
- turtle.select(1)
- end
- local function main()
- local keepGoingDown = true
- local distanceMoved = 0
- while keepGoingDown do
- local blockBelow, blockData = turtle.inspectDown()
- if blockBelow and blockData.name == "minecraft:bedrock" then
- keepGoingDown = false
- else
- if fuelLevel > distanceMoved or (useFuel and refuel(1)) then
- if blockBelow then
- turtle.digDown()
- end
- local attempts = 0 --just in case of hitting natural cobble gen
- while not turtle.down() and keepGoingDown do
- attempts = attempts + 1
- if attempts >= 5 then
- keepGoingDown = false
- end
- turtle.digDown()
- end
- distanceMoved = distanceMoved + 1
- fuelLevel = fuelLevel - 1
- if keepGoingDown then
- for i = 1, 4 do
- local isBlock, data = turtle.inspect()
- if isBlock then
- if not blackList[data.name] and turtle.dig() then
- if backFill then
- tryBackFill(turtle.place)
- end
- end
- elseif backFill then
- tryBackFill(turtle.place)
- end
- if i < 4 then
- turtle.turnLeft()
- end
- end
- if not checkSlots() then
- keepGoingDown = false
- end
- end
- else
- keepGoingDown = false
- end
- end
- end
- for i = 1, distanceMoved do
- while not turtle.up() do
- sleep(1)
- end
- tryBackFill(turtle.placeDown)
- end
- end
- checkFuelLevel()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement