Advertisement
nikita2007558

автокрафт сингулярок

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