Advertisement
serafim7

обменник руды для варпа [OpenComputers]

Sep 11th, 2021 (edited)
2,110
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.20 KB | None | 0 0
  1. --[[обменник руды by serafim  pastebin.com/jaYhuD0k  update 04.10.21
  2.                                
  3. пример сборки:
  4. https://i.imgur.com/bnqCk5a.png
  5. https://i.imgur.com/3SphwaG.png
  6.  
  7. требования:
  8. пк второго уровня (золотой)
  9. видеокарта второго уровня
  10. адаптер 2 штуки
  11. база данных первого уровня
  12. МЕ интерфейс
  13. сундук
  14.  
  15. --]]
  16.  
  17. local items = { -- множитель, название руды, забираем руду, dmg, отдаём слиток, dmg, название слитка, ore_dictionary
  18.   {"3","Дракониевая руда","DraconicEvolution:draconiumOre","0","DraconicEvolution:draconiumDust","0","Дракониевая пыль","dustDraconium"},
  19.   {"2","Алмазная руда","minecraft:diamond_ore","0","minecraft:diamond","0","Алмаз","gemDiamond"},
  20.   {"2","Изумрудная руда","minecraft:emerald_ore","0","minecraft:emerald","0","Изумруд","gemEmerald"},
  21.   {"2","Золотая руда","minecraft:gold_ore","0","minecraft:gold_ingot","0","Золотой слиток","ingotGold"},
  22.   {"2","Железная руда","minecraft:iron_ore","0","minecraft:iron_ingot","0","Железный слиток","ingotIron"},
  23.   {"2","IC2 Медная руда","IC2:blockOreCopper","0","IC2:itemIngot","0","Медный слиток","ingotCopper"},
  24.   {"2","IC2 Оловянная руда","IC2:blockOreTin","0","IC2:itemIngot","1","Оловяный слиток","ingotTin"},
  25.   {"2","IC2 Свинцовая руда","IC2:blockOreLead","0","IC2:itemIngot","5","Свинцовый слиток","ingotLead"},
  26.   {"2","TE Медная руда","ThermalFoundation:Ore","0","ThermalFoundation:material","64","Медный слиток","ingotCopper"},
  27.   {"2","TE Оловянная руда","ThermalFoundation:Ore","1","ThermalFoundation:material","65","Оловяный слиток","ingotTin"},
  28.   {"2","TE Никелевая руда","ThermalFoundation:Ore","4","ThermalFoundation:material","68","Никелевый слиток","ingotNickel"},
  29.   {"2","TE Серебряная руда","ThermalFoundation:Ore","2","ThermalFoundation:material","66","Серебряный слиток","ingotSilver"},
  30.   {"2","TE Платиновая руда","ThermalFoundation:Ore","5","ThermalFoundation:material","69","Платиновый слиток","ingotPlatinum"},
  31.   {"2","Руда истинного кварца","appliedenergistics2:tile.OreQuartz","0","appliedenergistics2:item.ItemMultiMaterial","0","Истинный кварц","crystalCertusQuartz"},
  32.   {"3","Кварцевая руда","minecraft:quartz_ore","0","minecraft:quartz","0","Кварц","gemQuartz"},
  33.   {"8","Лазуритовая руда","minecraft:lapis_ore","0","minecraft:dye","4","Лазурит","dye"},
  34.   {"8","Красная руда","minecraft:redstone_ore","0","minecraft:redstone","0","Красная пыль","dustRedstone"},
  35.   {"2","Угольная руда","minecraft:coal_ore","0","minecraft:coal","0","Уголь","coal"}
  36. }
  37.  
  38. local unicode = require("unicode")
  39. local com = require("component")
  40. local interface = com.isAvailable("me_interface") and com.me_interface or error("нет ме интерфейса")
  41. local db = com.isAvailable("database") and com.database or error("нет базы данных")
  42. local chest = com.isAvailable("chest") and com.chest or error("нет сундука")
  43. local size = chest.getInventorySize()
  44. local gpu = com.gpu
  45. local w, h = gpu.getResolution()
  46. local net_count,line_count = 0,0
  47.  
  48. local function declension(number)
  49.   local dec = ""
  50.   local rest = number % 10
  51.   local str = string.sub(number,string.len(number)-1)
  52.   if str == "11" or str == "12" or str == "13" or str == "14" then
  53.     dec = " слитков"
  54.   elseif rest == 1 then
  55.     dec = " слиток"
  56.   elseif rest == 2 or rest == 3 or rest == 4 then
  57.     dec = " слитка"
  58.   else
  59.     dec = " слитков"
  60.   end
  61.   return number..dec
  62. end
  63.  
  64. local function center(coord,text,color)
  65.   gpu.setForeground(color)
  66.   gpu.set(math.floor(w/2-unicode.len(text)/2),coord,text)
  67. end
  68.  
  69. local function color_text(w,line,text,color)
  70.   gpu.setForeground(color)
  71.   gpu.set(w,line,text)
  72. end
  73.  
  74. local function print_items()
  75.   local line,size,fill = 3,0,true
  76.   local network = interface.getItemsInNetwork()
  77.   for ind = 1,#items do
  78.     for net = 1,#network do
  79.       if network[net].name == items[ind][5] then
  80.         if network[net].damage == tonumber(items[ind][6]) then
  81.           if network[net].size >= tonumber(items[ind][1]) then
  82.             if #network ~= net_count then
  83.               if fill then
  84.                 gpu.fill(1,1,w,h," ")
  85.                 fill = not fill
  86.               end
  87.               color_text(5,line,items[ind][2],0x00FF00)
  88.               color_text(28,line,"1",0xFF00FF)
  89.               color_text(30,line,"-->",0xFFFF00)
  90.               color_text(34,line,"X "..items[ind][1],0xFF00FF)
  91.               color_text(42,line,items[ind][7],0x00FF00)
  92.               color_text(63,line,"доступно",0xFFFF00)
  93.               color_text(73,line,tostring(network[net].size),0xFF00FF)
  94.               color_text(3,line+1,string.rep("─",76),0xFFFFFF)
  95.               size = size + network[net].size
  96.             else
  97.               size = size + network[net].size
  98.               color_text(73,line,tostring(network[net].size.."   "),0xFF00FF)
  99.             end
  100.             line = line + 2
  101.           end
  102.         end
  103.       end
  104.     end
  105.   end
  106.   net_count = #network
  107.   if line == 3 or line ~= line_count then
  108.     net_count = 0
  109.   end
  110.   line_count = line
  111.   gpu.fill(1,1,w,1," ")
  112.   if size > 0 then
  113.     center(1,"обмен руды, всего доступно "..declension(size),0xFFFF00)
  114.   else
  115.     gpu.fill(1,1,w,h," ")
  116.     center(h/2,"обменник руды пустой",0xFF0000)
  117.   end
  118. end
  119.  
  120. local function pushItem(name,count,label)
  121.   db.clear(1)
  122.   interface.store(name,db.address,1)
  123.   interface.setInterfaceConfiguration(1,db.address,1,64)
  124.   local drop = 0
  125.   while true do
  126.     if drop == count then
  127.       interface.setInterfaceConfiguration(1,db.address,1,0)
  128.       net_count = 0
  129.       break
  130.     else
  131.       local dropcount = interface.pushItem("UP",1,count-drop)
  132.       drop = drop + dropcount
  133.       if dropcount == 0 then
  134.         gpu.fill(1,1,w,h," ")
  135.         center(h/2,"освободите место в сундуке",0xFF0000)
  136.         center(h/2+2,"Ожидаю выдать "..label,0xFFFFFF)
  137.         center(h/2+4,"всего "..count-drop,0xFFFFFF)
  138.         os.sleep(1)
  139.       end
  140.     end
  141.   end
  142. end
  143.  
  144. local function exchange_ore_dict()
  145.   local ore_dict,item_count = "",false
  146.   local data = chest.getAllStacks(0)
  147.   for slot = 1,size do
  148.     if data[slot] then
  149.       for ind = 1,#items do
  150.         if data[slot].id == items[ind][3] then
  151.           if data[slot].dmg == tonumber(items[ind][4]) then
  152.             ore_dict = items[ind][8]
  153.             break
  154.           end
  155.         end
  156.       end
  157.       local network = interface.getItemsInNetwork()
  158.       for ind2 = 1,#items do
  159.         if ore_dict == items[ind2][8] then
  160.           local ore = items[ind2][5]
  161.           local dmg = items[ind2][6]
  162.           local ore_name = items[ind2][2]
  163.           for net = 1,#network do
  164.             if network[net].name == ore then
  165.               if network[net].damage == tonumber(dmg) then
  166.                 if network[net].size >= tonumber(items[ind2][1]) then  
  167.                   item_count = chest.pushItem("DOWN",slot,(network[net].size/items[ind2][1]))
  168.                   local drop_count = item_count*items[ind2][1]
  169.                   local ingot_name = items[ind2][7]
  170.                   gpu.fill(1,1,w,1," ")
  171.                   center(1,"Меняю  "..item_count.."  "..ore_name.."  на  "..drop_count.."  "..ingot_name,0xFFFFFF)
  172.                   pushItem({name = ore,damage = tonumber(dmg)},drop_count,ingot_name)
  173.                   break
  174.                 end
  175.               end
  176.             end
  177.           end
  178.           if item_count then
  179.             item_count = false
  180.             ore_dict = ""
  181.             break
  182.           end
  183.         end
  184.       end
  185.     end
  186.   end
  187. end
  188.  
  189. gpu.fill(1,1,w,h," ")
  190. gpu.setResolution(80,h)
  191. while true do
  192.   print_items()
  193.   exchange_ore_dict()
  194.   os.sleep(0.5)
  195. end
Advertisement
Comments
  • Rijen
    360 days
    # text 0.09 KB | 0 0
    1. Продолжение на тему, используется PIM
    2. https://pastebin.com/JXdK09U7
Add Comment
Please, Sign In to add comment
Advertisement