Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require('component')
- local thread = require('thread')
- local event = require('event')
- local sides = require('sides')
- local gpu = component.gpu
- -----------------------------------------
- -- Прога для автоматизации крафтов в блад меджик алтаре.
- -- Для функционирования системы нужено иметь:
- -- т1 компьютер кейс, т1 графическую карту, т1 ЖД, т1 цпу
- -- и две т1 оперативы. Для взаимодействия с аларём
- -- используется transposer. Ставим транспосер вплотную к алтарю
- -- и к транспозеру 2 инвенторя входной и выходной. Указываем название
- -- инвенторей ниже, если все инвентори имею разные имена, либо
- -- указываем стороны света относительно транспосера (input_side/output_side/altar_side)
- -- Подключаем транспозез к компьютер кейсу при помощи кабелей из ОК.
- -- Запускаем программу, кидаем итем в инпут чест, ждём результат.
- --
- -- Для заливки программы можно использовать простое копирование
- -- через колёсико мыши (но придётся копировать за 2 раза, по 200 строк),
- -- либо крафтить т2 кейс и интернет карту.
- --
- -- В конфиге программы прописаны почти все рецепты GTNH и сколько LP нужно на крафты.
- -- Поэтому перед стартом крафта проверяется текущий уровень эссенции и, если
- -- он больше или равен требуемому в рецепте, предмет будет помещён в алтарь для крафта.
- -- После окончания крафта предмет перемещается в отпут чест. Переменная CheckInterval
- -- определяет, насколько часто проверять алтарь.
- --
- -- Программа умеет работать с орбами. Если в алтаре лежит блад орб,
- -- программа переложит его в оутпут чест и будет выполнять крафты.
- -- После выполнения всех крафтов, программа пытается вернуть орб в алтарь.
- -- Поэтому позаботьтесь о том, чтоб из оутпут честа орба никуда не пропадала.
- --
- -- Доп фича: программа выводит текущий уровень крови в алтаре и его вместимомсть.
- -----------------------------------------
- local CheckInterval = 1 -- loop cooldown (sec)
- local updateGuiInterval = 1
- local altar_side = nil -- if nil -> autodetect
- local input_side = nil -- if nil -> autodetect
- local output_side = nil -- if nil -> autodetect
- local altar_name = "tile.bloodAltar" -- if altar_side == nil required altar name
- local input_name = "tile.extrautils:chestFull" -- if input_side == nil required input chest name
- local output_name = "tile.appliedenergistics2.BlockInterface" -- if output_side == nil required output chest name
- local bm_recipe_config = {
- ["minecraft:bucket:0"] = 1,
- ["minecraft:tnt"] = 10,
- ["minecraft:cake"] = 10,
- ["minecraft:iron_ingot:0"] = 6,
- ["minecraft:dye:14"] = 0.2,
- ["minecraft:cookie"] = 2,
- ["minecraft:paper"] = 10,
- ["MagicBees:frameMagic"] = 5,
- ["Botania:flower"] = 15,
- ["minecraft:log:0"] = 5,
- ["minecraft:log:1"] = 5,
- ["minecraft:log:2"] = 5,
- ["minecraft:log:3"] = 5,
- ["minecraft:log2:0"] = 5,
- ["minecraft:log2:1"] = 5,
- ["minecraft:glass:0"] = 0.2,
- ["minecraft:ice"] = 0.4,
- ["minecraft:packed_ice"] = 0.6,
- ["minecraft:iron_block:0"] = 64,
- ["minecraft:glowstone:0"] = 28,
- ["BloodArsenal:blood_infused_diamond_unactive:0"] = 120,
- ["gregtech:gt.metaitem.02:30500"] = 12,
- ["minecraft:glowstone_dust:0"] = 7,
- ["witchery:ingredient:102"] = 5,
- ["BloodArsenal:heart:0"] = 100,
- ["dreamcraft:item.WeakOrb:0"] = 5,
- ["dreamcraft:item.ApprenticeOrb:0"] = 10,
- ["dreamcraft:item.MagicianOrb:0"] = 30,
- ["dreamcraft:item.MasterOrb:0"] = 60,
- ["dreamcraft:item.ArchmageOrb:0"] = 120,
- ["dreamcraft:item.TranscendentOrb:0"] = 300,
- ["dreamcraft:item.ArcaneSlate:0"] = 1,
- ["AWWayofTime:blankSlate:0"] = 2.5,
- ["AWWayofTime:reinforcedSlate:0"] = 7.5,
- ["AWWayofTime:imbuedSlate:0"] = 20,
- ["AWWayofTime:demonicSlate:0"] = 60,
- ["IC2:itemFluidCell:0"] = 1,
- ["Thaumcraft:ItemEssence:0"] = 4,
- ["IC2:itemBatCrystal:1"] = 5,
- ["AWWayofTime:sacrificialKnife:0"] = 10,
- ["AWWayofTime:blankSpell:0"] = 20,
- ["AWWayofTime:emptySocket:0"] = 40,
- ["Thaumcraft:blockCrystal:0"] = 5,
- ["Thaumcraft:blockCrystal:1"] = 5,
- ["Thaumcraft:blockCrystal:2"] = 5,
- ["Thaumcraft:blockCrystal:3"] = 5,
- ["Thaumcraft:blockCrystal:5"] = 10,
- ["Thaumcraft:blockCrystal:6"] = 100,
- ["EnderZoo:enderFragment:0"] = 5,
- ["AWWayofTime:telepositionFocus:0"] = 20,
- ["Thaumcraft:blockCosmeticSolid:4"] = 5,
- ["thaumicbases:voidBlock:0"] = 10,
- ["gregtech:gt.blockmetal8:13"] = 50,
- ["BloodArsenal:blood_infused_diamond_active"] = 10,
- ["minecraft:sandstone"] = 3.5,
- ["ForbiddenMagic:WandCores:6"] = 50,
- }
- local bm_orb_config = {
- ["AWWayofTime:weakBloodOrb"] = true,
- ["AWWayofTime:apprenticeBloodOrb"] = true,
- ["AWWayofTime:magicianBloodOrb"] = true,
- ["AWWayofTime:masterBloodOrb"] = true,
- ["AWWayofTime:archmageBloodOrb"] = true,
- ["AWWayofTime:transcendentBloodOrb"] = true,
- ["ForbiddenMagic:EldritchOrb"] = true,
- ["Avaritia:Orb_Armok"] = true
- }
- local tr = nil
- local d_limit = 5 -- debud recursion limit
- local cur_item_name = nil
- local saved_orb_name = nil
- function main()
- init()
- init_gui()
- local resetBColor, resetFColor = gpu.getBackground(), gpu.getForeground()
- local background = {}
- table.insert(background, event.listen("key_up", function (key, address, char)
- if char == string.byte('q') then
- event.push('exit')
- end
- end))
- table.insert(background, event.timer(CheckInterval, failFast(check_craft), math.huge))
- table.insert(background, event.timer(updateGuiInterval, failFast(update_gui), math.huge))
- local _, err = event.pull("exit")
- for _, b in ipairs(background) do
- if type(b) == 'table' and b.kill then
- b:kill()
- else
- event.cancel(b)
- end
- end
- gpu.setBackground(resetBColor)
- gpu.setForeground(resetFColor)
- if err then
- io.stderr:write(err)
- os.exit(1)
- else
- os.exit(0)
- end
- end
- function failFast(fn)
- return function(...)
- local res = table.pack(xpcall(fn, debug.traceback, ...))
- if not res[1] then
- event.push('exit', res[2])
- end
- return table.unpack(res, 2)
- end
- end
- function errorExit(...)
- out(...)
- event.push('exit')
- end
- ----------------------- DEBUG ---------------------------
- function object_to_string(level, object)
- local function get_tabs(num)
- local msg = ""
- for i = 0, num do msg = msg .. " " end
- return msg
- end
- if level == nil then level = 0 end
- local message = " "
- if object == nil then
- message = message .. "nil"
- elseif type(object) == "boolean" or type(object) == "number" then
- message = message .. tostring(object) end
- if type(object) == "string" then
- message = message..object end
- if type(object) == "function" then
- message = message.."\"__function\"" end
- if type(object) == "table" then
- if level <= d_limit then
- message = message .. "\n" .. get_tabs(level) .. "{\n"
- for key, next_object in pairs(object) do
- message = message .. get_tabs(level + 1) .. "\"" .. key .. "\"" .. ":" .. object_to_string(level + 1, next_object) .. ",\n";
- end
- message = message .. get_tabs(level) .. "}"
- else
- message = message .. "\"" .. "__table" .. "\""
- end
- end
- return message
- end
- function rec_obj_to_string(object, ...)
- arg = {...}
- if #arg > 0 then
- return object_to_string(0, object) .. rec_obj_to_string(...)
- else
- return object_to_string(0, object)
- end
- end
- function out(...)
- local message = rec_obj_to_string(...)
- print(message)
- end
- ----------------------- LOOP ---------------------------
- function check_craft()
- if cur_item_name then
- local item_in_altar = tr.getStackInSlot(altar_side, 1)
- if item_in_altar == nil then
- cur_item_name = nil
- elseif item_in_altar.name .. ":" .. math.floor(item_in_altar.damage) ~= cur_item_name then
- transfer_item(altar_side, output_side, 1, 1)
- end
- else
- local in_item_slot, item = get_first_item(input_side, bm_recipe_config)
- if item then
- local item_in_altar = tr.getStackInSlot(altar_side, 1)
- if item_in_altar then
- if bm_orb_config[item_in_altar.name] then
- transfer_item(altar_side, output_side, 1, 1)
- saved_orb_name = item_in_altar.name
- end
- else
- local fluid = tr.getFluidInTank(altar_side, 1)
- if fluid and fluid.amount >= bm_recipe_config[item] * 1000 then
- tr.transferItem(input_side, altar_side, 1, in_item_slot, 1)
- cur_item_name = item
- end
- end
- elseif saved_orb_name then
- local out_chest_size = tr.getInventorySize(output_side)
- local selected_slot = nil
- for i = 1, out_chest_size do --find orb
- local item_in_outchest = tr.getStackInSlot(output_side, i)
- if item_in_outchest and item_in_outchest.name == saved_orb_name then
- selected_slot = i
- break
- end
- end
- if selected_slot then
- if tr.getStackInSlot(altar_side, 1) == nil then
- tr.transferItem(output_side, altar_side, 1, selected_slot, 1)
- saved_orb_name = nil
- end
- else
- saved_orb_name = nil
- end
- end
- end
- end
- -------------------- SUPPORTED FUNCTION -----------------------
- function transfer_item(in_side, out_side, item_cnt, in_slot)
- local out_chest_size = tr.getInventorySize(out_side)
- local item_in_inchest = tr.getStackInSlot(in_side, in_slot)
- local selected_slot = nil
- -- find slot in output chest
- for i = 1, out_chest_size do
- local item_in_outchest = tr.getStackInSlot(out_side, i)
- if item_in_outchest == nil then
- if not selected_slot then
- selected_slot = i
- end
- elseif item_in_outchest.name == item_in_inchest.name and
- item_in_outchest.maxSize - item_in_outchest.size > 0 then
- selected_slot = i
- break
- end
- end
- if (selected_slot) then
- tr.transferItem(in_side, out_side, item_cnt, in_slot, selected_slot)
- end
- end
- function get_first_item(side, filter)
- local inv_size = tr.getInventorySize(side)
- for i = 1, inv_size do
- item = tr.getStackInSlot(side, i)
- if item then
- if not filter or filter[item.name .. ":" .. math.floor(item.damage)] then
- return i, item.name .. ":" .. math.floor(item.damage)
- end
- end
- end
- end
- function init()
- tr = link_component("transposer")
- if tr == nil then
- errorExit("Transposer not found")
- return
- end
- if altar_side == nil then
- altar_side = detect_named_side(altar_name)
- if altar_side == nil then
- errorExit("Altar: ", altar_name, " not found or not located next to the Transposer")
- return
- end
- end
- if input_side == nil then
- input_side = detect_named_side(input_name)
- if input_side == nil then
- errorExit("Input: ", input_name, " not found or not located next to the Transposer")
- return
- end
- end
- if output_side == nil then
- output_side = detect_named_side(output_name)
- if output_side == nil then
- errorExit("Output: ", output_name, " not found or not located next to the Transposer")
- return
- end
- end
- print("altar_side", altar_side)
- print("input_side", input_side)
- print("output_side", output_side)
- end
- function link_component(comp_name)
- components = component.list(comp_name)
- ret_comp = nil
- for addr, name in pairs(components) do
- if ret_comp == nil then
- ret_comp = component.proxy(addr)
- print("Link component " .. name .. " to address " .. ret_comp.address)
- else
- print("Warning: More then one component " .. name .. " found. Used: " .. ret_comp.address)
- end
- end
- return ret_comp
- end
- function detect_named_side(name)
- for i = 0,5 do
- local loc_name = tr.getInventoryName(i)
- if loc_name == name then
- return i
- end
- end
- end
- -------------------- GUI FUNCTION -----------------------
- function clear_screen()
- local x, y = gpu.getResolution()
- gpu.fill(1, 1, x, y, " ")
- end
- function update_gui()
- local fluid = tr.getFluidInTank(altar_side)
- if fluid and fluid[1] and fluid[1].name == "lifeessence" then
- gpu.set(1, 2, math.floor(fluid[1].amount) .. "/" .. math.floor(fluid[1].capacity) .. " ")
- end
- end
- function init_gui()
- gpu.setResolution(14, 2)
- clear_screen()
- gpu.set(1, 1, "Altar Essense:")
- update_gui()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement