Advertisement
Rijen

v3

May 11th, 2023
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local items = { -- множитель, название руды, забираем руду, dmg, отдаём слиток, dmg, название слитка, ore_dictionary
  2.   {"2","Золотая руда","minecraft:gold_ore","0","minecraft:gold_ingot","0","Золотой слиток","ingotGold"},
  3.   {"2","Железная руда","minecraft:iron_ore","0","minecraft:iron_ingot","0","Железный слиток","ingotIron"},
  4.   {"2","IC2 Медная руда","IC2:blockOreCopper","0","IC2:itemIngot","0","Медный слиток","ingotCopper"},
  5.   {"2","IC2 Оловянная руда","IC2:blockOreTin","0","IC2:itemIngot","1","Оловяный слиток","ingotTin"},
  6.   {"10","Лазуритовая руда","minecraft:lapis_ore","0","minecraft:dye","4","Лазурит","dye"},
  7.   {"5","Красная руда","minecraft:redstone_ore","0","minecraft:redstone","0","Красная пыль","dustRedstone"},
  8.   {"4","Адская Оловянная руда","NetherOres:tile.netherores.ore.0","7","IC2:itemIngot","1","Оловянный слиток","ingotTin"},
  9.   {"4","Адская Медная Руда","NetherOres:tile.netherores.ore.0","6","IC2:itemIngot","0","Медный слиток","ingotCopper"},
  10.   {"3","Дракониевая руда","DraconicEvolution:draconiumOre","0","DraconicEvolution:draconiumIngot","0","Дракониевый слиток","БЛа-бла"},
  11. }
  12.  
  13. local unicode = require("unicode")
  14. local com = require("component")
  15. local interface = com.isAvailable("me_interface") and com.me_interface or error("нет ме интерфейса")
  16. local db = com.isAvailable("database") and com.database or error("нет базы данных")
  17. local pim = com.isAvailable("pim") and com.pim or error("нет пима")
  18. local size = pim.getInventorySize()
  19. local gpu = com.gpu
  20. local w, h = gpu.getResolution()
  21.  
  22. gpu.setResolution(80,h)
  23. w=80
  24.  
  25. local net_count,line_count = 0,0
  26. local event=require("event")
  27. local function declension(number)
  28.   local dec = ""
  29.   local rest = number % 10
  30.   local str = string.sub(number,string.len(number)-1)
  31.   if str == "11" or str == "12" or str == "13" or str == "14" then
  32.     dec = " слитков"
  33.   elseif rest == 1 then
  34.     dec = " слиток"
  35.   elseif rest == 2 or rest == 3 or rest == 4 then
  36.     dec = " слитка"
  37.   else
  38.     dec = " слитков"
  39.   end
  40.   return number..dec
  41. end
  42.  
  43. local function center(coord,text,color)
  44.   gpu.setForeground(color)
  45.   gpu.set(math.floor(w/2-unicode.len(text)/2),coord,text)
  46. end
  47.  
  48. local function color_text(w,line,text,color)
  49.   gpu.setForeground(color)
  50.   gpu.set(w,line,text)
  51. end
  52.  
  53. local function print_items()
  54.   local line,size,fill = 3,0,true
  55.   local network = interface.getItemsInNetwork()
  56.   for ind = 1,#items do
  57.     for net = 1,#network do
  58.       if network[net].name == items[ind][5] then
  59.         if network[net].damage == tonumber(items[ind][6]) then
  60.           if network[net].size >= tonumber(items[ind][1]) then
  61.             if #network ~= net_count then
  62.               if fill then
  63.                 gpu.fill(1,1,w,h," ")
  64.                 fill = not fill
  65.               end
  66.               color_text(5,line,items[ind][2],0x00FF00)
  67.               color_text(28,line,"1",0xFF00FF)
  68.               color_text(30,line,"-->",0xFFFF00)
  69.               color_text(34,line,"X "..items[ind][1],0xFF00FF)
  70.               color_text(42,line,items[ind][7],0x00FF00)
  71.               color_text(63,line,"доступно",0xFFFF00)
  72.               color_text(73,line,tostring(network[net].size),0xFF00FF)
  73.               color_text(3,line+1,string.rep("─",76),0xFFFFFF)
  74.               size = size + network[net].size
  75.             else
  76.               size = size + network[net].size
  77.               color_text(73,line,tostring(network[net].size.."   "),0xFF00FF)
  78.             end
  79.             line = line + 2
  80.           end
  81.         end
  82.       end
  83.     end
  84.   end
  85.   net_count = #network
  86.   if line == 3 or line ~= line_count then
  87.     net_count = 0
  88.   end
  89.   line_count = line
  90.   gpu.fill(1,1,w,1," ")
  91.   if size > 0 then
  92.     center(1,"обмен руды, всего доступно "..declension(size),0xFFFF00)
  93.   else
  94.     gpu.fill(1,1,w,h," ")
  95.     center(h/2,"ВСЕ ИДИТЕ НАХУЙ, ХУЙ ВАМ А НЕ ОБМЕНИК .!. ",0xFF1493)
  96.   end
  97. end
  98.  
  99. local function pushItem(name,count,label)
  100.   db.clear(1)
  101.   interface.store(name,db.address,1)
  102.   interface.setInterfaceConfiguration(1,db.address,1,64)
  103.   local drop = 0
  104.   while true do
  105.     if drop == count then
  106.       interface.setInterfaceConfiguration(1,db.address,1,0)
  107.       net_count = 0
  108.       break
  109.     else
  110.       local dropcount = interface.pushItem("UP",1,count-drop)
  111.       drop = drop + dropcount
  112.       if dropcount == 0 then
  113.         gpu.fill(1,1,w,h," ")
  114.         center(h/2,"освободите место в инвентаре",0xFF0000)
  115.         center(h/2+2,"Ожидаю выдать "..label,0xFFFFFF)
  116.         center(h/2+4,"всего "..count-drop,0xFFFFFF)
  117.         os.sleep(1)
  118.       end
  119.     end
  120.   end
  121. end
  122.  
  123. local function exchange_ore_dict()
  124.   gpu.fill(1,h/2+2,w,1,' ')
  125.   center(h/2+2,"Для обмена встаньте на PIM и не сходите до окончания обмена", 0xffffff)
  126.   local nick = nil
  127.   e, nick, uuid, adr  = event.pull(5,'player_on')  
  128.   if nick==nil then
  129.       return
  130.   end
  131.  
  132.   gpu.fill(1,h/2+2,w,1,' ')
  133.   center(h/2+2,"Приветствую тебя, "..nick, 0xffffff)
  134.   local ore_dict,item_count = "",false
  135.   local size = pim.getInventorySize()
  136.   local data = pim.getAllStacks(0)
  137.   for slot =1, size do
  138.     if data[slot] then
  139.       for ind = 1,#items do
  140.         if data[slot].id == items[ind][3] then
  141.           if data[slot].dmg == tonumber(items[ind][4]) then
  142.             ore_dict = items[ind][3]..items[ind][4]
  143.             break
  144.           end
  145.         end
  146.       end
  147.  
  148.       local network = interface.getItemsInNetwork()
  149.       for ind2 = 1,#items do
  150.         if ore_dict == items[ind2][3]..items[ind2][4] then
  151.  
  152.           local ore = items[ind2][5]
  153.           local dmg = items[ind2][6]
  154.           local ore_name = items[ind2][2]
  155.           for net = 1,#network do
  156.             if network[net].name == ore then
  157.               if network[net].damage == tonumber(dmg) then
  158.                 if network[net].size >= tonumber(items[ind2][1]) then
  159.                   item_count = pim.pushItem("DOWN",slot,(network[net].size/items[ind2][1]))
  160.  
  161.                   if item_count==nil then
  162.                       gpu.fill(1,1,w,1,' ')
  163.                       center(1,"Не удалось загрузить предмет, вы сошли с PIM. А вас просили не сходить...", 0xff0000)
  164.                   elseif item_count==0 then
  165.                       gpu.fill(1,1,w,1,' ')
  166.                       center(1,"Ошибка загрузки МЭ", 0xff0000)
  167.                   else
  168.  
  169.                       local drop_count = item_count*items[ind2][1]
  170.                       local ingot_name = items[ind2][7]
  171.                       gpu.fill(1,1,w,1," ")
  172.                       center(1,"Меняю  "..item_count.."  "..ore_name.."  на  "..drop_count.."  "..ingot_name,0xFFFFFF)
  173.                       pushItem({name = ore,damage = tonumber(dmg)},drop_count,ingot_name)
  174.                   end
  175.  
  176.                   break
  177.                 end
  178.               end
  179.             end
  180.           end
  181.          
  182.          
  183.           if item_count then
  184.             item_count = false
  185.             ore_dict = ""
  186.             break
  187.           end
  188.         end
  189.       end
  190.     end
  191.    
  192.   end
  193.  
  194.  
  195. end
  196.  
  197.  
  198. function draw_img(img,x,y,fore,back)
  199.   fore =fore or 0xffffff
  200.   back = back or 0x0
  201.    oldFG = gpu.getForeground()
  202.   gpu.setForeground(fore)
  203.   local i=0
  204.   for line in img:gmatch("([^\n]*)\n?") do
  205.     gpu.set(x,y+i,line)
  206.     i=i+1
  207.   end
  208.  
  209.   gpu.setForeground(oldFG)
  210. end
  211.  
  212. local img = require('mcskill_img2')
  213. local cl = require('copyleft')
  214. gpu.fill(1,1,w,h," ")
  215. while true do
  216.   print_items()
  217.   draw_img(img,1,h-13,0x00a400)
  218.   cl()
  219.   exchange_ore_dict()
  220.   os.sleep(0.5)
  221. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement