local ENDERCHEST = "enderstorage:ender_chest" local refuelLevel = 2000 local ores = { ["minecraft:coal_ore"] = true, ["minecraft:redstone_ore"] = true, ["minecraft:gold_ore"] = true, ["minecraft:iron_ore"] = true, ["minecraft:diamond_ore"] = true, ["minecraft:lapis_ore"] = true, ["minecraft:emerald_ore"] = true, ["mekanism:tin_ore"] = true, ["mekanism:lead_ore"] = true, ["mekanism:copper_ore"] = true, ["create:zinc_ore"] = true, ["immersiveengineering:ore_nickel"] = true, ["powah:uraninite_raw"] = true, ["darkerdepths:silver_ore"] = true, ["forbidden_arcanus:arcane_crystal_ore"] = true, ["mysticalworld:quicksilver_ore"] = true, ["mysticalworld:saphire_ore"] = true, ["druidcraft:fiery_glass_ore"] = true, ["immersiveengineering:ore_silver"] = true, ["mekanism:fluorite_ore"] = true, ["mekanism:uranium_ore"] = true, ["forbidden_arcanus:ruinstone"] = true, ["forbidden_arcanus:xpetrified_ore"] = true, ["mekanism:osmium_ore"] = true } local garbage = { ["minecraft:cobblestone"] = true, ["minecraft:gravel"] = true, ["minecraft:dirt"] = true, ["minecraft:granite"] = true, ["minecraft:diorite"] = true, ["quark:cobbled_deepslate"] = true, } local distanceSinceLastInvCheck = 0 function placeUp() repeat turtle.digUp() until turtle.placeUp() return true end function forward() repeat turtle.dig() until turtle.forward() distanceSinceLastInvCheck = distanceSinceLastInvCheck + 1 return true end function back() if not turtle.back() then turtle.turnRight() turtle.turnRight() forward() turtle.turnRight() turtle.turnRight() end return true end function right() turtle.turnRight() return true end function left() turtle.turnLeft() return true end function up() repeat turtle.digUp() until turtle.up() distanceSinceLastInvCheck = distanceSinceLastInvCheck + 1 return true end function down() repeat turtle.digDown() until turtle.down() distanceSinceLastInvCheck = distanceSinceLastInvCheck + 1 return true end function putDownChest() print("Placing Chest") for i = 1, 16 do local data = turtle.getItemDetail(i) if data then if data.name == ENDERCHEST then turtle.select(i) placeUp() end end end end function findChest() print("Finding Chest") local worked, d = turtle.inspectUp() if worked then if d.name == ENDERCHEST then turtle.digUp() return true end end for i = 1, 16 do local data = turtle.getItemDetail(i) if data then if data.name == ENDERCHEST then return i end end end return false end function checkBlock(side) side = side or 0 local fun = turtle.inspect if side == 1 then fun = turtle.inspectUp elseif side == 2 then fun = turtle.inspectDown end local worked, data = fun() if worked then if ores[data.name] then return data.name end end return false end function scan(n) n = n or 1 if n > 100 then return end --forward if checkBlock() then forward() scan(n+1) back() end --up if checkBlock(1) then up() scan(n+1) down() end --down if checkBlock(2) then down() scan(n+1) up() end --left left() if checkBlock() then forward() scan(n+1) back() end right() --right right() if checkBlock() then forward() scan(n+1) back() end left() end function sortInv() local emptySlots = 0 for i = 1, 16 do print("Testing Slot " .. i) local firstItem = turtle.getItemDetail(i) if firstItem then for b = i + 1, 16 do local secondItem = turtle.getItemDetail(b) if secondItem then if secondItem.name == firstItem.name then print("Slot " .. i .. " and slot " .. b .. " match... transfering") turtle.select(b) turtle.transferTo(i) end end end if garbage[firstItem.name] then print(firstItem.name .. " is garbage. Dumping") turtle.select(i) turtle.dropUp() elseif firstItem.name == "minecraft:coal" then if turtle.getFuelLevel() < refuelLevel then print("Refueling") turtle.select(i) turtle.refuel() end end else emptySlots = emptySlots + 1 end end if emptySlots < 5 then putDownChest() for i = 1, 16 do turtle.select(i) turtle.dropUp() end findChest() end turtle.select(1) end function main() if not findChest() then error("NO CHEST FOUND AHHHHH") end while true do if distanceSinceLastInvCheck > 20 then sortInv() distanceSinceLastInvCheck = 0 end forward() scan() up() scan() forward() scan() down() scan() end end main()