Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local interface = com.isAvailable("me_interface") and com.me_interface or error("No ME interface")
- local shell = require("shell")
- local mainItemToCraft = {name = "AdvancedSolarPanel:BlockAdvSolarPanel", damage = 7}
- local products = {
- redstone = { name = "minecraft:redstone", damage = 0, count = 100000 },
- iron = { name = "minecraft:iron_ingot", damage = 0, count = 216000 },
- copper = { name = "ThermalFoundation:material", damage = 64, count = 116000 },
- tin = { name = "ThermalFoundation:material", damage = 65, count = 66000 },
- coal = { name = "minecraft:coal", damage = 0, count = 400000 }
- }
- local orePriceWis = 3
- local wisItem = {displayName= "Вис Материя", name="dwcity:Vis_materia", dmg = 0, mod_name="dwcity"}
- local oresForCraft = {
- redstone = { displayName = "Красная руда", name = "minecraft:redstone_ore", damage = 0, product = products.redstone, craftCount = 8, productOutput = 128 },
- iron = { displayName = "Железная руда", name = "minecraft:iron_ore", damage = 0, product = products.iron, craftCount = 8, productOutput = 16 },
- copper = { displayName = "Медная руда", name = "IC2:copperOre", damage = 0, product = products.copper, craftCount = 8, productOutput = 16 },
- coal = { displayName = "Угольная руда", name = "minecraft:coal_ore", damage = 0, product = products.coal, craftCount = 12, productOutput = 36},
- tin = { displayName = "Оловянная руда", name = "IC2:tinOre", damage = 0, product = products.tin, craftCount = 8, productOutput = 16}
- }
- local function getCraftablesAll()
- local craftables = {}
- for key, value in pairs(oresForCraft) do
- local craftableLocal = interface.getCraftables({name = value.name, damage = value.damage})[1]
- if craftableLocal then
- table.insert(craftables, craftableLocal)
- end
- end
- return craftables
- end
- local craftables = getCraftablesAll()
- local function getTableOfWhatInNetworkNow()
- local tableToCraftLeft = {}
- local network = interface.getItemsInNetwork()
- for ind1 = 1, #network do
- local itemInNetwork = network[ind1]
- for key, itemProduct in pairs(products) do
- if itemInNetwork.name == itemProduct.name and itemInNetwork.damage == itemProduct.damage then
- --найдено в сети продукт
- local productCountInNetwork = itemInNetwork.size
- --теперь нужно определить к какой руде относится продукт
- local oreForProduct = oresForCraft[key]
- --считаем сколько руды в продукте (например 36 слитков это 18 руды)
- local countInOre = productCountInNetwork * oreForProduct.craftCount / oreForProduct.productOutput
- --создаем обьект для помещения в таблицу
- if tableToCraftLeft[key] then
- tableToCraftLeft[key] = tableToCraftLeft[key] + countInOre
- else
- tableToCraftLeft[key] = countInOre
- end
- end
- end
- for key, itemForCraft in pairs(oresForCraft) do
- if itemInNetwork.name == itemForCraft.name and itemInNetwork.damage == itemForCraft.damage then
- --найдено в сети предмет для крафта
- local oreCountInNetwork = itemInNetwork.size
- if tableToCraftLeft[key] then
- tableToCraftLeft[key] = tableToCraftLeft[key] + oreCountInNetwork
- else
- tableToCraftLeft[key] = oreCountInNetwork
- end
- end
- end
- end
- return tableToCraftLeft
- end
- local function getTableOfWhatNeedToCreate()
- print("Инициализация таблицы того, что нужно создать")
- local tableOfWhatInNetwork = getTableOfWhatInNetworkNow()
- local tableOfOresNeedToCrateFull = {}
- for key, ore in pairs(oresForCraft) do
- local oreCountNeed = (ore.product.count / ore.productOutput) * ore.craftCount
- local needToCreate = oreCountNeed - tableOfWhatInNetwork[key]
- if needToCreate > 0 then
- tableOfOresNeedToCrateFull[key] = needToCreate
- end
- end
- print("Инициализация таблицы того, что нужно создать кончена. ")
- return tableOfOresNeedToCrateFull
- end
- local function addCraftablesToItemsForCraft()
- shell.execute("cls")
- print("Инициализация таблиц для крафта")
- for key, itemForCraft in pairs(oresForCraft) do
- for _, itemCraftTable in pairs(craftables) do
- if type(itemCraftTable) == "table" then
- local itemCrafted = itemCraftTable.getItemStack()
- --print(itemCrafted.name.." == "..itemForCraft.name.." and "..itemCrafted.damage.." == "..itemForCraft.damage)
- if itemCrafted.name == itemForCraft.name and itemCrafted.damage == itemForCraft.damage then
- print("Найдена таблица для "..itemForCraft.displayName)
- itemForCraft.craftable = itemCraftTable
- end
- end
- end
- end
- print("Инициализация таблиц для крафта кончена. ")
- end
- function getWisInNetwork(network)
- for index = 1, #network do
- if network[index].name == wisItem.name then
- return network[index].size
- end
- end
- end
- addCraftablesToItemsForCraft()
- local tableToCreate = getTableOfWhatNeedToCreate()
- local function createFromTableToCreate(tableCreation)
- local wisSpent = 0
- for key, countToCreate in pairs(tableCreation) do
- local oreToCreate = oresForCraft[key]
- print("Сейчас создаю "..oreToCreate.displayName .. " "..countToCreate.." штук")
- local oreLeft = countToCreate
- while oreLeft > 0 do
- local wisInNetwork = interface.getItemDetail({id = wisItem.name, dmg = wisItem.dmg}).all().qty
- print("Вис в сети: "..wisInNetwork)
- local canCraftFromWis = math.floor((wisInNetwork / orePriceWis) * oreToCreate.craftCount) - 8
- print("Можно создать из вис: "..canCraftFromWis)
- local requestOreValue = 0
- if canCraftFromWis > oreLeft then
- requestOreValue = oreLeft
- elseif canCraftFromWis < oreLeft and canCraftFromWis > 0 then
- requestOreValue = canCraftFromWis
- elseif canCraftFromWis == 0 then
- os.sleep(60)
- print("Простаиваю 60 секунд. Ожидаю вис в системе")
- end
- local wisSpentForCraft = math.floor((requestOreValue / oreToCreate.craftCount) * orePriceWis )
- wisSpent = wisSpent + wisSpentForCraft
- local request = oreToCreate.craftable.request(requestOreValue)
- print("В процессе: "..requestOreValue.." штук")
- repeat
- os.sleep(60)
- until (request.isCanceled() or request.isDone())
- oreLeft = oreLeft - requestOreValue
- print("Создано "..countToCreate-oreLeft.."/"..countToCreate)
- end
- end
- print("Создание окончено. Потрачено "..wisSpent.." вис.")
- local mainItemToCraftTable = interface.getCraftables({name = mainItemToCraft.name, damage = mainItemToCraft.damage})[1]
- if mainItemToCraftTable then
- --сделать ожидание нужного количества ресурсов в мэ
- --после этого запустить крафт
- end
- end
- createFromTableToCreate(tableToCreate)
Advertisement
Add Comment
Please, Sign In to add comment