Advertisement
mrWhiskasss

singularity by zayats

Jul 19th, 2023
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --by zayats
  2.  
  3. local items = {
  4.     {"Редстоун сингулярность", "minecraft:redstone_block", 0, 6000, "Avaritia:Singularity", 3},
  5.     {"Железная сингулярность", "minecraft:iron_block", 0, 5000, "Avaritia:Singularity", 0},
  6.     {"Кварцевая сингулярность", "minecraft:quartz_block", 0, 6000, "Avaritia:Singularity", 4},
  7.     {"Лазуритовая сингулярность", "minecraft:lapis_block", 0, 6000, "Avaritia:Singularity", 2},
  8.     {"Алмазная сингулярность", "minecraft:diamond_block", 0, 3000, "universalsingularities:universal.vanilla.singularity", 2},
  9.     {"Золотая сингулярность", "minecraft:gold_block", 0, 3000, "Avaritia:Singularity", 1},
  10.     {"Медная сингулярность", "ThermalFoundation:Storage", 0, 5000, "Avaritia:Singularity", 5},
  11.     {"Оловянная сингулярность", "ThermalFoundation:Storage", 1, 5000, "Avaritia:Singularity", 6},
  12.     {"Свинцовая сингулярность", "ThermalFoundation:Storage", 3, 3000, "Avaritia:Singularity", 7},
  13.     {"Серебрянная сингулярность", "ThermalFoundation:Storage", 2, 3000, "Avaritia:Singularity", 8},
  14.     {"Никелевая сингулярность", "ThermalFoundation:Storage", 4, 19800, "Avaritia:Singularity", 9}
  15. }
  16.  
  17. local requestSize = 1
  18.  
  19. local component = require "component"
  20. local unicode = require "unicode"
  21. local event = require "event"
  22. local computer = require "computer"
  23. local gpu = component.gpu
  24. local ae = component.me_interface
  25. local function drawTable()
  26.     local w, h = 40, #items + 2
  27.     gpu.setResolution(w, h)
  28.     gpu.fill(1, 1, w, 1, "─")
  29.     gpu.fill(1, 1, 1, h, "│")
  30.     gpu.fill(w, 1, 1, h, "│")
  31.     gpu.fill(1, h, w, 1, "─")
  32.     gpu.set(1, 1, "┌")
  33.     gpu.set(w, 1, "┐")
  34.     gpu.set(1, h, "└")
  35.     gpu.set(w, h, "┘")
  36.     gpu.set(2, 1, "[Название]")
  37.     gpu.set(29, 1, "[Кол-во]")
  38. end
  39. local function convert(value)
  40.     if value>= 10^9 then
  41.         return string.format("%0.1fG", value/10^9)
  42.     elseif value>= 10^6 then
  43.         return string.format("%0.1fM", value/10^6)
  44.     elseif value>= 10^3 then
  45.         return string.format("%0.1fK", value/10^3)
  46.     else
  47.         return string.format("%d", value)
  48.     end
  49. end
  50. local function getSize(name, dmg)
  51.     for _, item in ipairs(ae.getItemsInNetwork()) do
  52.         if item.name == name and item.damage == dmg then
  53.             return item.size
  54.         end
  55.     end
  56.     return 0
  57. end
  58. local function drawButton(x, y, text, tColor)
  59.     local oldfColor =gpu.getForeground()
  60.     gpu.setForeground(tColor)
  61.     gpu.set(x, y, text)
  62.     gpu.setForeground(oldfColor)
  63. end
  64. local function draw()
  65.     for i = 2, #items do
  66.         gpu.set(2, i, items[i - 1][1])
  67.         drawButton(37, i, "+", 0x00FF00)
  68.         gpu.set(29, i, tostring(items[i - 1][4]))
  69.     end
  70. end
  71. local function start(item)
  72.     local id, dmg, blockSize = item[2], item[3], item[4]
  73.     local drop = 0
  74.     gpu.set(2, #items+1, (item[1] .. " x" .. drop .. " / " .. blockSize))
  75.     while true do
  76.         if drop >= blockSize then
  77.             gpu.fill(2, #items+1, w - 2, 1, " ")
  78.             return
  79.         else
  80.             local dropcount = ae.exportItem({id = item[2], dmg = item[3]}, "DOWN", blockSize - drop).size
  81.             gpu.set(2, #items+1, (item[1] .. " " .. drop .. " / "  .. (blockSize - drop)))
  82.             drop = drop + dropcount
  83.             if dropcount == 0 then
  84.                 os.sleep(0.05)
  85.             end
  86.         end
  87.     end
  88. end
  89.  
  90. local function craft(id)
  91.     local item = items[id]
  92.     local size = getSize(item[2], item[3])
  93.     gpu.set(2, #items + 1, ("Доступно: " .. size .. " / " .. item[4]))
  94.     if size < (item[4] * requestSize) then
  95.         if getSize(item[2], item[3]) >= item[4] then
  96.             gpu.set(2, #items + 1, ("Доступно: " .. size .. " / " .. item[4]))
  97.             start(item)
  98.         end
  99.         ae.requestCrafting({id = item[2], dmg = item[3]}, ((item[4] * requestSize) - size))
  100.         while true do
  101.             gpu.set(2, #items + 1, ("Доступно: " .. getSize(item[2], item[3]) .. " / " .. item[4]))
  102.             if getSize(item[2], item[3]) >= item[4] then
  103.                 start(item)
  104.             end
  105.             os.sleep(0.1)
  106.         end
  107.     else
  108.         start(item)
  109.     end
  110. end
  111. function detect(_, _, x, y)
  112.     if x ~= nil then
  113.         for i = 1, #items do
  114.             if x == 37 and i == y then
  115.                 computer.beep(1000, 0.1)
  116.                 craft(y - 1)
  117.             end
  118.         end
  119.     end
  120. end
  121. drawTable()
  122. draw()
  123. while true do
  124.     gpu.fill(2, #items+1, 40 - 2, 1, " ")
  125.     event.listen("touch", detect)
  126.     os.sleep(0.01)
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement