Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LENTH_MAX = 21
- local PASTE_ID = "e9EasxCL"
- local SCRIPT_NAME = "test"
- local UNKNOWN_LIST = "unsortable_items"
- local arg = {...}
- local LOG_REPORT_ID = 633
- function pastebin_download(code, name)
- fs.delete(name)
- if pcall(shell.run, "pastebin", "get", code, name) then
- print(name, "downloaded successfully !")
- else
- print("Failed to download ", name)
- end
- end
- function init_item_list(lenght)
- local tab
- local i
- tab = {}
- i = 1
- while i <= lenght do
- tab[i] = {}
- i = i + 1
- end
- return tab
- end
- function get_item_list_right()
- local right
- right = init_item_list(LENTH_MAX)
- right[1][#right[1] + 1] = "minecraft:cobblestone"
- right[2][#right[2] + 1] = "minecraft:dirt"
- right[3][#right[3] + 1] = "minecraft:log"
- right[3][#right[3] + 1] = "minecraft:log2"
- right[4][#right[4] + 1] = "minecraft:glass"
- right[5][#right[5] + 1] = "minecraft:sand"
- right[6][#right[6] + 1] = "minecraft:stone,0"
- right[7][#right[7] + 1] = "thaumcraft:crystal_essence"
- right[8][#right[8] + 1] = ""
- right[9][#right[9] + 1] = "minecraft:grass"
- right[10][#right[10] + 1] = "minecraft:gold_ore"
- right[10][#right[10] + 1] = "minecraft:iron_ore"
- right[10][#right[10] + 1] = "thaumcraft:ore_cinnabar"
- right[11][#right[11] + 1] = "minecraft:iron_ingot"
- right[12][#right[12] + 1] = "minecraft:gold_ingot"
- right[13][#right[13] + 1] = "minecraft:gold_block"
- right[13][#right[13] + 1] = "minecraft:diamond"
- right[14][#right[14] + 1] = "minecraft:emerald"
- right[15][#right[15] + 1] = "minecraft:gravel"
- right[16][#right[16] + 1] = "minecraft:stone,5"
- right[17][#right[17] + 1] = "minecraft:stone,3"
- right[18][#right[18] + 1] = "minecraft:stone,1"
- right[19][#right[19] + 1] = "chisel:marble2"
- right[20][#right[20] + 1] = "chisel:limestone2"
- right[21][#right[21] + 1] = "minecraft:rotten_flesh"
- return right
- end
- function get_item_list_left()
- local right
- right = init_item_list(LENTH_MAX)
- right[1][#right[1] + 1] = "minecraft:wooden_slab"
- right[1][#right[1] + 1] = "minecraft:stone_slab"
- right[1][#right[1] + 1] = "minecraft:birch_stairs"
- right[1][#right[1] + 1] = "minecraft:spruce_stairs"
- right[1][#right[1] + 1] = "minecraft:stone_stairs"
- right[1][#right[1] + 1] = "minecraft:brick_stairs"
- right[1][#right[1] + 1] = "minecraft:sandstone_stairs"
- right[1][#right[1] + 1] = "minecraft:carpet"
- right[1][#right[1] + 1] = "minecraft:oak_stairs"
- right[1][#right[1] + 1] = "minecraft:nether_brick_stairs"
- right[1][#right[1] + 1] = "minecraft:quartz_stairs"
- right[2][#right[2] + 1] = "minecraft:birch_fence"
- right[2][#right[2] + 1] = "minecraft:fence_gate"
- right[2][#right[2] + 1] = "minecraft:oak_fence"
- right[2][#right[2] + 1] = "minecraft:nether_brick_fence"
- right[2][#right[2] + 1] = "minecraft:spruce_fence"
- right[2][#right[2] + 1] = "minecraft:jungle_fence"
- right[2][#right[2] + 1] = "minecraft:dark_oak_fence"
- right[2][#right[2] + 1] = "minecraft:acacia_fence"
- right[2][#right[2] + 1] = "minecraft:birch_fence_gate"
- right[2][#right[2] + 1] = "minecraft:oak_fence_gate"
- right[2][#right[2] + 1] = "minecraft:spruce_fence_gate"
- right[2][#right[2] + 1] = "minecraft:jungle_fence_gate"
- right[2][#right[2] + 1] = "minecraft:dark_oak_fence_gate"
- right[2][#right[2] + 1] = "minecraft:acacia_fence_gate"
- right[2][#right[2] + 1] = "minecraft:cobblestone_wall"
- right[2][#right[2] + 1] = "minecraft:iron_bars"
- right[2][#right[2] + 1] = "minecraft:stained_glass_pane"
- right[2][#right[2] + 1] = "minecraft:glass_pane"
- right[2][#right[2] + 1] = "minecraft:fence"
- right[3][#right[3] + 1] = "minecraft:flint"
- right[4][#right[4] + 1] = "minecraft:sandstone"
- right[5][#right[5] + 1] = "OpenBlocks:technicolorGlasses"
- right[5][#right[5] + 1] = "ComputerCraft:CC-TurtleAdvanced"
- right[5][#right[5] + 1] = "ComputerCraft:CC-Turtle"
- right[5][#right[5] + 1] = "ComputerCraft:treasureDisk"
- right[5][#right[5] + 1] = "ComputerCraft:CC-Computer"
- right[5][#right[5] + 1] = "ComputerCraft:CC-Peripheral"
- right[5][#right[5] + 1] = "ComputerCraft:disk"
- right[5][#right[5] + 1] = "ComputerCraft:advanced_modem"
- right[5][#right[5] + 1] = "ComputerCraft:CC-Cable"
- right[5][#right[5] + 1] = "ComputerCraft:pocketComputer"
- right[5][#right[5] + 1] = "ComputerCraft:CC-TurtleExpanded"
- right[6][#right[6] + 1] = "minecraft:potion"
- right[6][#right[6] + 1] = "minecraft:sugar"
- right[6][#right[6] + 1] = "minecraft:nether_wart"
- right[6][#right[6] + 1] = "minecraft:fish,3"
- right[6][#right[6] + 1] = "minecraft:magma_cream"
- right[6][#right[6] + 1] = "minecraft:glass_bottle"
- right[6][#right[6] + 1] = "minecraft:blaze_rod"
- right[6][#right[6] + 1] = "minecraft:nether_star"
- right[6][#right[6] + 1] = "minecraft:blaze_powder"
- right[6][#right[6] + 1] = "minecraft:spider_eye"
- right[6][#right[6] + 1] = "minecraft:brewing_stand"
- right[6][#right[6] + 1] = "minecraft:fermented_spider_eye"
- right[6][#right[6] + 1] = "minecraft:golden_apple"
- right[6][#right[6] + 1] = "minecraft:speckled_melon"
- right[6][#right[6] + 1] = "minecraft:ender_eye"
- right[7][#right[7] + 1] = "minecraft:anvil"
- right[7][#right[7] + 1] = "minecraft:hopper"
- right[7][#right[7] + 1] = "minecraft:chest"
- right[7][#right[7] + 1] = "minecraft:bed"
- right[7][#right[7] + 1] = "minecraft:item_frame"
- right[7][#right[7] + 1] = "minecraft:repeater"
- right[7][#right[7] + 1] = "minecraft:torch"
- right[7][#right[7] + 1] = "minecraft:redstone_lamp"
- right[7][#right[7] + 1] = "minecraft:piston"
- right[7][#right[7] + 1] = "minecraft:sticky_piston"
- right[7][#right[7] + 1] = "minecraft:tripwire_hook"
- right[7][#right[7] + 1] = "minecraft:rail"
- right[7][#right[7] + 1] = "minecraft:golden_rail"
- right[7][#right[7] + 1] = "minecraft:birch_door"
- right[7][#right[7] + 1] = "minecraft:oak_door"
- right[7][#right[7] + 1] = "minecraft:spruce_door"
- right[7][#right[7] + 1] = "minecraft:jungle_door"
- right[7][#right[7] + 1] = "minecraft:dark_oak_door"
- right[7][#right[7] + 1] = "minecraft:acacia_door"
- right[7][#right[7] + 1] = "minecraft:wooden_door"
- right[7][#right[7] + 1] = "minecraft:redstone_torch"
- right[7][#right[7] + 1] = "minecraft:dispenser"
- right[7][#right[7] + 1] = "minecraft:furnace"
- right[7][#right[7] + 1] = "minecraft:crafting_table"
- right[7][#right[7] + 1] = "minecraft:trapped_chest"
- right[7][#right[7] + 1] = "minecraft:dropper"
- right[7][#right[7] + 1] = "minecraft:trapdoor"
- right[7][#right[7] + 1] = "minecraft:stone_button"
- right[7][#right[7] + 1] = "minecraft:wooden_pressure_plate"
- right[7][#right[7] + 1] = "minecraft:stone_pressure_plate"
- right[7][#right[7] + 1] = "minecraft:lever"
- right[7][#right[7] + 1] = "minecraft:sign"
- right[7][#right[7] + 1] = "ironchest:BlockIronChest"
- right[7][#right[7] + 1] = "minecraft:activator_rail"
- right[7][#right[7] + 1] = "minecraft:wooden_button"
- right[7][#right[7] + 1] = "minecraft:comparator"
- right[7][#right[7] + 1] = "ironchest:BlockIronChest"
- right[7][#right[7] + 1] = "minecraft:enchanting_table"
- right[7][#right[7] + 1] = "minecraft:ender_chest"
- right[7][#right[7] + 1] = "minecraft:iron_door"
- right[7][#right[7] + 1] = "minecraft:ladder"
- right[7][#right[7] + 1] = "EnderStorage:enderChest"
- right[8][#right[8] + 1] = "minecraft:stonebrick"
- right[8][#right[8] + 1] = "minecraft:stone_brick_stairs"
- right[9][#right[9] + 1] = "minecraft:planks"
- right[9][#right[9] + 1] = "minecraft:stick"
- right[10][#right[10] + 1] = "minecraft:redstone"
- right[11][#right[11] + 1] = "minecraft:redstone_block"
- right[12][#right[12] + 1] = "minecraft:coal,0"
- right[13][#right[13] + 1] = "minecraft:coal,1"
- right[14][#right[14] + 1] = "minecraft:dye,4"
- return right
- end
- function get_info(chest_item)
- local str
- local name
- name, str = chest_item:match("([^,]+),([^,]+)")
- if name then
- return name, tonumber(str)
- else
- return chest_item, nil
- end
- end
- function get_item_list()
- local chest = {}
- chest["left"] = get_item_list_left()
- chest["right"] = get_item_list_right()
- return chest
- end
- function get_item_chest_id(side, item, damage)
- local i
- local meta
- local damageRef
- local bestCandidate
- local name
- local chest
- i = 1
- meta = 1
- name = true
- chest = get_item_list()
- if (side and side ~= "left" and side ~= "right") or not item or not side then
- error("get_item_chest_id: Invalid side or nil item")
- end
- while chest[side][i] do
- meta = 1
- while chest[side][i][meta] do
- name, damageRef = get_info(chest[side][i][meta])
- if name == item and damageRef and damageRef == damage then
- return i
- elseif name == item and not damageRef then
- bestCandidate = i
- end
- meta = meta + 1
- end
- i = i + 1
- end
- return bestCandidate
- end
- function get_max_distance()
- local slot
- local maxDistance
- local data
- local tmpr
- local tmpl
- slot = 1
- maxDistance = 1
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data then
- tmpl = get_item_chest_id("left", data.name, data.damage)
- tmpr = get_item_chest_id("right", data.name, data.damage)
- maxDistance = get_max_distance_compare(maxDistance, tmpl)
- maxDistance = get_max_distance_compare(maxDistance, tmpr)
- if not tmpl and not tmpr then
- maxDistance = LENTH_MAX
- end
- end
- slot = slot + 1
- end
- return maxDistance
- end
- function get_max_distance_compare(val1, val2)
- if not val2 or val2 < val1 then
- return val1
- end
- return val2
- end
- function select_fuel()
- local slot = 1
- local data
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and (data.name == "minecraft:lava_bucket" or data.name == "minecraft:coal" or data.name == "minecraft:planks") then
- turtle.select(slot)
- return true
- end
- slot = slot + 1
- end
- if slot > 16 then
- return false
- end
- end
- --function send_logs(str)
- -- rednet.open("right")
- -- rednet.send(LOG_REPORT_ID, "Turtle ")
- -- rednet.send(LOG_REPORT_ID, os.getComputerLabel())
- -- rednet.send(LOG_REPORT_ID, ": ")
- -- rednet.send(LOG_REPORT_ID, "newline")
- -- rednet.send(LOG_REPORT_ID, str)
- -- rednet.send(LOG_REPORT_ID, "newline")
- -- rednet.send(LOG_REPORT_ID, "newline")
- -- rednet.close("right")
- --end
- function check_fuel()
- if turtle.getFuelLevel() == 0 then
- while not select_fuel() do
- print("No fuel found. Retrying in 10 seconds")
- -- send_logs("No fuel found. Retrying in 10 seconds")
- sleep(10)
- end
- turtle.refuel()
- return true
- end
- return false
- end
- function avance(i)
- if not i then
- i = 1
- end
- while i > 0 do
- if not turtle.forward() then
- print("Can't forward. Checking fuel...")
- if check_fuel() then
- print("Fuel ok !")
- else
- print("Looks I'm lost, fuel ok but can't forward")
- sleep(2)
- end
- else
- i = i - 1
- end
- end
- end
- function is_inventory_empty()
- local slot = 1
- while slot <= 16 do
- if turtle.getItemCount(slot) > 0 then
- return false
- end
- slot = slot + 1
- end
- return true
- end
- function line(side, maxDistance)
- local i = 1
- if side == "right" then
- put_under_chest(side, i)
- else
- put_under_chest(side, maxDistance)
- end
- while i < maxDistance do
- avance()
- i = i + 1
- if side == "right" then
- put_under_chest(side, i)
- else
- put_under_chest(side, maxDistance - (i - 1))
- end
- end
- end
- function put_under_chest(side, chestId)
- local slot = 1
- local data
- local tmpItem
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data then
- tmpItem = get_item_chest_id(side, data.name, data.damage)
- if tmpItem and chestId == tmpItem then
- column(data.name, data.damage)
- elseif not tmpItem and chestId == LENTH_MAX and side == "left" then
- column(data.name, data.damage)
- end
- end
- slot = slot + 1
- end
- end
- function column(name, damage)
- local slot = 1
- local data
- local offset = 0
- local bool = false
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and data.name == name and damage == data.damage then
- bool = false
- turtle.select(slot)
- while not turtle.dropDown() do
- turtle.turnRight()
- avance()
- turtle.turnLeft()
- offset = offset + 1
- end
- end
- slot = slot + 1
- end
- while offset > 0 do
- if not bool then
- turtle.turnLeft()
- bool = true
- end
- avance()
- offset = offset - 1
- end
- if bool then
- turtle.turnRight()
- end
- end
- function suck_all()
- local success = false
- while turtle.suckUp() do
- -- TODO: Send logs here
- success = true
- end
- return success
- end
- function core()
- suck_all()
- while not is_inventory_empty() do
- local max_distance
- update_unknown_list()
- max_distance = get_max_distance()
- turtle.turnRight()
- avance(3)
- turtle.turnLeft()
- line("right", max_distance)
- turtle.turnLeft()
- avance(6)
- turtle.turnLeft()
- line("left", max_distance)
- turtle.turnLeft()
- avance(3)
- turtle.turnLeft()
- suck_all()
- end
- end
- function dump(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. dump(v) .. '\n'
- end
- return s .. '}\n'
- else
- return tostring(o)
- end
- end
- function is_in_list(elem, list)
- local i
- i = 1
- while i <= #list do
- if elem == list[i] then
- return true
- end
- i = i + 1
- end
- return false
- end
- function get_known_and_unknown()
- local maxDistance
- local slot
- local data
- local tmp
- local k = {}
- local u = {}
- maxDistance = 1
- slot = 1
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data then
- tmp = tostring(data.name) .. "," .. tostring(data.damage)
- if not get_item_chest_id("left", data.name, data.damage) and
- not get_item_chest_id("right", data.name, data.damage) then
- if not is_in_list(tmp, u) then
- u[#u + 1] = tmp
- end
- print("No chest found for ", data.name, " ", data.damage)
- -- send_logs("No chest for:" .. data.name .. ", subID:".. data.damage)
- elseif not is_in_list(tmp, k) then
- k[#k + 1] = tmp
- end
- end
- slot = slot + 1
- end
- return u, k
- end
- function concatenate_arrays(t1, t2)
- local i
- i = 1
- while i <= #t2 do
- t1[#t1 + 1] = t2[i]
- i = i + 1
- end
- return t1
- end
- function purge_includes(main, sub)
- local i
- local x
- i = 1
- while i <= #main do
- x = 1
- while x <= #sub do
- if main[i] == sub[x] then
- main[i] = main[#main]
- main[#main] = nil
- end
- x = x + 1
- end
- i = i + 1
- end
- return main
- end
- function file_exists(file)
- local f
- f = io.open(file, "rb")
- if f then
- f:close()
- end
- return f ~= nil
- end
- function check_default_file(filename)
- local f
- if not file_exists(filename) then
- f = io.open(filename, "w")
- f:write("minecraft:air\n")
- f:close()
- end
- end
- function get_file_per_lines(filename)
- local lines = {}
- for line in io.lines(filename) do
- lines[#lines + 1] = line
- end
- table.sort(lines)
- return lines
- end
- function update_unknown_list()
- local lines
- local u
- local k
- check_default_file(UNKNOWN_LIST)
- u, k = get_known_and_unknown()
- io.input(UNKNOWN_LIST)
- lines = get_file_per_lines(UNKNOWN_LIST)
- io.input():close()
- lines = purge_includes(lines, k)
- lines = purge_includes(lines, u)
- lines = concatenate_arrays(lines, u)
- table.sort(lines)
- -- send_logs(dump(lines))
- io.output(UNKNOWN_LIST)
- for i, l in ipairs(lines) do
- io.write(l .. "\n")
- end
- io.output():close()
- end
- if arg[1] == "--update" or arg[1] == "-u" then
- pastebin_download(PASTE_ID, SCRIPT_NAME)
- return true
- end
- core()
- --send_logs("Fuel:" .. turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement