Advertisement
Rijen

OreExchange

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