Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile("Fuel")
- dofile("Inventory")
- DigOut = {}
- local hasSub = false
- local fuel = Fuel:new(fuel)
- local inventory = Inventory:new(inventory)
- local default = "none"
- local blacklist
- local whiteList
- local blackListActive = false
- local whiteListActive = false
- function DigOut:new(o)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- return o
- end
- function DigOut.ExcavateDownBlackList(x, y, z, blockList)
- blacklist = blockList
- blacklist = loadTableFromFile(blacklist)
- blackListActive = true
- if x % 2 == 0 then -- Even
- EvenYCycle(x, y, z)
- else -- Odd
- OddYCycle(x, y, z)
- end
- end
- function DigOut.ExcavateDownWhiteList(x, y, z, blockList)
- whiteList = blockList
- whiteList = loadTableFromFile(whiteList)
- whiteListActive = true
- if x % 2 == 0 then -- Even
- EvenYCycle(x, y, z)
- else -- Odd
- OddYCycle(x, y, z)
- end
- end
- function DigOut.ExcavateDownDefault(x, y, z)
- if x % 2 == 0 then -- Even
- EvenYCycle(x, y, z)
- else -- Odd
- OddYCycle(x, y, z)
- end
- end
- function layerOdd(x, y)
- for i = 1, x, 1 do
- if blackListActive then
- mineXDistanceBlackList(y)
- elseif whiteListActive then
- mineXDistanceWhiteList(y)
- else
- mineXDistance(y)
- end
- if i ~= x then
- if i % 2 ~= 0 then
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- end
- if not hasSub then
- y = y - 1
- hasSub = true
- end
- end
- end
- return y
- end
- function layerEven(x, y)
- for i = 1, x, 1 do
- if blackListActive then
- mineXDistanceBlackList(y)
- elseif whileListActive then
- mineXDistanceWhiteList(y)
- else
- mineXDistance(y)
- end
- if i ~= x then
- if i % 2 ~= 0 then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- end
- if not hasSub then
- y = y - 1
- hasSub = true
- end
- end
- end
- end
- -- Goes down a block and turns around
- function layerDown()
- turtle.digDown()
- turtle.down()
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Mine with a blacklist item filter
- function mineXDistanceBlackList(x)
- for i = 1, x, 1 do
- -- Check Fuel
- if fuel.isFuelLevelSubOptimal(40) then
- --Refuel
- local fueled = false
- local count = 1
- while not fueled do -- Look through turtle's inventory to refuel
- turtle.select(count)
- fueled = turtle.refuel()
- count = count + 1
- if count >= 16 and not fueled then -- If the inventory has been check through and nothing has been found break
- print("Turtle is almost out of fuel and does not have fuel and cannot find any.")
- break
- end
- end
- end
- -- Check Inventory
- filterInventoryBlackList()
- -- Dig and move forward
- turtle.dig()
- turtle.forward()
- end
- end
- -- Mine with a whiteList item filter
- function mineXDistanceWhiteList(x)
- for i = 1, x, 1 do
- -- Check Fuel
- if fuel.isFuelLevelSubOptimal(40) then
- --Refuel
- local fueled = false
- local count = 1
- while not fueled do -- Look through turtle's inventory to refuel
- turtle.select(count)
- fueled = turtle.refuel()
- count = count + 1
- if count >= 16 and not fueled then -- If the inventory has been check through and nothing has been found break
- print("Turtle is almost out of fuel and does not have fuel and cannot find any.")
- break
- end
- end
- end
- -- Check Inventory
- filterInventoryWhiteList()
- -- Dig and move forward
- turtle.dig()
- turtle.forward()
- end
- end
- -- Mine WithOut an item filter
- function mineXDistance(x)
- for i = 1, x, 1 do
- -- Check Fuel
- if fuel.isFuelLevelSubOptimal(40) then
- --Refuel
- local fueled = false
- local count = 1
- while not fueled do -- Look through turtle's inventory to refuel
- turtle.select(count)
- fueled = turtle.refuel()
- count = count + 1
- if count >= 16 and not fueled then -- If the inventory has been check through and nothing has been found break
- print("Turtle is almost out of fuel and does not have fuel and cannot find any.")
- break
- end
- end
- end
- -- Dig and move forward
- turtle.dig()
- turtle.forward()
- end
- end
- -- The Odd Y mining cycle
- function OddYCycle(x, y, z)
- for s = 1, z, 1 do
- y = layerOdd(x, y)
- if s ~= z then
- layerDown()
- end
- end
- end
- -- The Even Y mining cycle
- function EvenYCycle(x, y, z)
- for s = 1, z, 1 do
- if s % 2 ~= 0 then
- y = layerOdd(x, y)
- else
- layerEven(x, y)
- end
- if s ~= z then
- layerDown()
- end
- end
- end
- function loadTableFromFile(fileName)
- local file = fs.open(fileName, "r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- function filterInventoryBlackList()
- if(#blacklist > 0) then
- local itemWasFound, itemsFound = inventory.checkInventoryForItems(blacklist)
- if itemWasFound then
- for i = 1, #blacklist, 1 do
- local item = itemsFound[blacklist[i]]
- for s = 1, #item, 1 do
- if item[s] then
- turtle.select(s)
- turtle.drop()
- end
- end
- end
- end
- end
- end
- function filterInventoryWhiteList()
- if(#whiteList > 0) then
- local slotsToKeep = {}
- local itemWasFound, itemsFound = inventory.checkInventoryForItems(whiteList)
- -- If one of the items on the whitelist was found then cache all the slots with items from the whitelist in them
- if itemWasFound then
- for i = 1, #whiteList, 1 do
- local item = itemsFound[whiteList[i]]
- for s = 1, #item, 1 do
- if item[s] then
- slotsToKeep[s] = true
- else
- if i ~= 1 then
- if not slotsToKeep[s] then
- slotsToKeep[s] = false
- end
- else
- slotsToKeep[s] = false
- end
- end
- end
- end
- end
- -- Get rid of every item from every slot that doesnt have a whiteList item in its slot
- for i = 1, 16, 1 do
- if itemWasFound then
- if not slotsToKeep[i] then
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- else
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment