Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ore_dict = {
- {
- 'Железная руда',
- 'Железный слиток',
- 2,
- take = {name='minecraft:iron_ore',damage=0},
- give = {name='minecraft:iron_ingot',damage=0}
- },
- {
- 'Золотая руда',
- 'Золотой слиток',
- 2,
- take = {name='minecraft:gold_ore',damage=0},
- give = {name='minecraft:gold_ingot',damage=0}
- },
- {
- 'Никилевая руда',
- 'Никелевый слиток',
- 2,
- take = {name='ThermalFoundation:blockOreNickel',damage=0},
- give = {name='ThermalFoundation:material',damage=68}
- },
- {
- 'Мифриловая руда',
- 'Мифриловый слиток',
- 2,
- take = {name='ThermalFoundation:blockOreMithril',damage=0},
- give = {name='ThermalFoundation:material',damage=70}
- },
- {
- 'Платиновая руда',
- 'Платиновый слиток',
- 2,
- take = {'ThermalFoundation:blockOrePlatinum',damage=0},
- give = {name='ThermalFoundation:material',damage=69}
- },
- {
- 'Свинцовая руда',
- 'Свинцовый слиток',
- 2,
- take = {name='IC2:lead_ore',damage=0},
- give = {name='IC2:itemIngot',damage=5}
- },
- {
- 'Серебрянная руда',
- 'Серебрянный слиток',
- 2,
- take = {name='ThermalFoundation:blockOreSilver',damage=0},
- give = {name='IC2:itemIngot',damage=6}
- },
- {
- 'Медная руда',
- 'Медный слиток',
- 2,
- take = {name='IC2:blockOreCopper',damage=0},
- give = {name='IC2:itemIngot',damage=0}
- },
- {
- 'Оловянная руда',
- 'Оловянный слиток',
- 2,
- take = {name='IC2:blockOreTin',damage=0},
- give = {name='IC2:itemIngot',damage=1}
- },
- {
- 'Адская Медная Руда',
- 'Медный слиток',
- 4,
- take = {name='NetherOres:tile.netherores.ore.0',damage=6},
- give = {name='IC2:itemIngot',damage=0}
- },
- {
- 'Адская Оловянная руда',
- 'Оловянный слиток',
- 4,
- take = {name='NetherOres:tile.netherores.ore.0',damage=7},
- give = {name='IC2:itemIngot',damage=1}
- },
- {
- 'Кварцевая руда',
- 'Кварц',
- 3,
- take = {name='minecraft:quartz_ore',damege=0},
- give = {name='minecraft:quartz',damege=0}
- },
- {
- 'Серная руда',
- 'Сера',
- 24,
- take = {name='NetherOres:tile.netherores.1',damage=5},
- give = {name='IC2:itemDust',damage=13}
- },
- }
- local unicode = require('unicode')
- local computer = require("computer")
- local com = require('component')
- local event = require('event')
- local me = com.isAvailable("me_interface") and com.me_interface or error("нет ме интерфейса")
- local db = com.isAvailable("database") and com.database or error("нет базы данных")
- local pim = com.isAvailable("pim") and com.pim or error("нет пима")
- local gpu = com.gpu
- local w,h = 48,30
- local defBG, defFG = gpu.getBackground(),gpu.getForeground()
- gpu.setResolution(w,h)
- local function center(height,text,color)
- gpu.setForeground(color)
- gpu.set(math.floor(w/2-unicode.len(text)/2),height,text)
- end
- local function populateQty()
- local totalOre = 0
- for i,ore in pairs(ore_dict) do
- local item = me.getItemsInNetwork(ore.give)
- if item == nil then
- return 0
- else
- if item.n then
- item = item[1]
- ore.qty = item.size
- totalOre = totalOre+item.size
- end
- end
- end
- return totalOre
- end
- local function displayOres()
- local line = 10
- for i, ore in pairs(ore_dict) do
- local print_row = line+(i)
- gpu.setForeground(0x00ff00)
- gpu.set(1,print_row,ore[1])
- gpu.set(28,print_row,ore[2])
- gpu.setForeground(0xFF00FF)
- gpu.set(23,print_row,'1')
- gpu.set(24,print_row,'к'..ore[3])
- end
- end
- local function updateOres()
- local totalOre = populateQty()
- gpu.fill(1,1,w,h-16," ")
- if totalOre==0 then
- else
- displayOres()
- end
- end
- local function giveIngot(toGive,ore)
- db.clear(2)
- me.store(ore.give,db.address,1)
- me.setInterfaceConfiguration(1,db.address,1,64)
- local totalGive = 0
- while totalGive < toGive do
- local gived = me.pushItem("UP",1,toGive-totalGive)
- totalGive = totalGive+gived
- if gived == 0 then
- end
- end
- end
- local function exchangeOre(slot,ore)
- local curSlot = pim.getStackInSlot(slot)
- if curSlot == nil then
- return
- end
- local userOreQty = curSlot.qty
- local giveQty = userOreQty*ore[3]
- if ore.qty<giveQty then
- end
- -- Количетсво могло измениться..
- local takedOre = pim.pushItem("DOWN",slot, userOreQty)
- if takedOre == nil then
- elseif takedOre == 0 then
- else
- local giveQty = takedOre*ore[3]
- giveIngot(giveQty,ore)
- end
- end
- local function checkInventory()
- local size = pim.getInventorySize()
- local data = pim.getAllStacks(0)
- for slot =1, size do
- if data[slot] then
- for i,ore in pairs(ore_dict) do
- if data[slot].id==ore.take.name and data[slot].dmg == ore.take.damage then
- exchangeOre(slot, ore)
- end
- end
- end
- end
- updateOres()
- if pim.getInventoryName() ~= 'pim' then
- checkInventory()
- else
- -- Может быть, мы не поймали событие когда юзер ушел
- event.push('player_off')
- end
- end
- function handleEvent(eventID,...)
- local args = {...}
- if eventID == 'interrupted' then
- gpu.setBackground(defBG)
- gpu.setForeground(defFG)
- gpu.fill(1,1,w,h," ")
- os.exit()
- return true
- elseif eventID =='player_on' then
- updateOres()
- checkInventory()
- elseif eventID =='player_off' then
- checkInventory()
- updateOres()
- end
- end
- function drawStat()
- gpu.setForeground(0x444444)
- gpu.set(2, h-1, string.format("RAM: %.1fkB / %.1fkB", (computer.totalMemory() - computer.freeMemory()) / 1024, computer.totalMemory() / 1024))
- end
- local oreTimeFn = function()
- updateOres()
- -- Каджый 10 такт обновляем экран
- for i=1,1 do
- coroutine.yield()
- end
- end
- local oreTimer = coroutine.create(oreTimeFn)
- while true do
- drawStat()
- handleEvent(event.pull(1))
- if coroutine.status(oreTimer) == 'dead' then
- oreTimer = coroutine.create(oreTimeFn)
- else
- coroutine.resume(oreTimer)
- end
- end
Add Comment
Please, Sign In to add comment