Advertisement
MrHerobrine

[ComputerCraft] blockstatus

Jan 25th, 2022 (edited)
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. local side = "top"
  2. local mon = peripheral.find("monitor")
  3.  
  4. local function fill(colr)           -- заполняет к ебеням всё, что видит указанным цветом
  5.     mon.setBackgroundColor(colr)
  6.     mon.clear()
  7. end
  8.  
  9. local function draw(startX,startY,endX,endY,colr)   --рисует прямоугольник от и до указанных координат
  10.     mon.setBackgroundColor(colr)
  11.     for xcord=startX, endX do
  12.         for ycord=startY, endY do
  13.             mon.setCursorPos(xcord, ycord) mon.write(" ")
  14.         end
  15.     end
  16. end
  17.  
  18. local function bar(xcord,ycord,width,min,max,bgclr) -- рисует прогресс-бар, по координатам x,y указанной ширины и цвета
  19.     mon.setBackgroundColor(bgclr)
  20.     mon.setTextColour(0x8000)
  21.     for point=1, width do       -- рисуем пустую шкалу
  22.         mon.setCursorPos(xcord-1+point,ycord) mon.write("\143")
  23.     end
  24.     local wdth = math.floor(width/(max/min)) -- считаем заполнение из width, min и max
  25.     mon.setTextColour(0x1)
  26.     for point=1,wdth do         -- рисуем заполненный участок шкалы
  27.         mon.setCursorPos(xcord-1+point,ycord) mon.write("\143")
  28.     end
  29. end
  30.  
  31.  
  32. mon.setTextScale(0.5)
  33.  
  34. fill(0x80)  -- чистим экран
  35. draw(3,1,13,1,0x8000)   -- рисуем чёлку сверху и пишем функциональное название софтины
  36.     mon.setCursorPos(5, 1) mon.setTextColour(0x1) mon.write("Status:")
  37. draw(6,10,10,10,0x200)  -- дырка внизу интерфейса
  38. draw(1,3,15,9,0x100)    -- заполняем фон для тушки интерфейса
  39.  
  40.  
  41. mon.setTextColour(0x20) mon.setCursorPos(1, 4) mon.write("I\187")
  42. mon.setTextColour(0x2) mon.setCursorPos(1, 8) mon.write("O\171")
  43.  
  44. while true do
  45.     local comp = peripheral.wrap(side)
  46.   if comp ~= nil then
  47.     info = comp.list()
  48.  
  49.     -- пишем сколько барахла уже готово
  50.     if info[2] ~= nil then mon.setBackgroundColor(0x200) mon.setTextColour(0x8000) mon.setCursorPos(7, 10) mon.write("x"..info[2]["count"])
  51.     else mon.setBackgroundColor(0x200) mon.setTextColour(0x8000) mon.setCursorPos(7, 10) mon.write("x0  ") end
  52.  
  53.     -- а тут мы рисуем шкалу и циферки количества блоков внутри штуки
  54.     if info[1] ~= nil then
  55.         if info[1]["count"]<10 then mon.setBackgroundColor(0x100) mon.setCursorPos(1, 6) mon.write(" "..info[1]["count"] .."/"..64)
  56.         else mon.setBackgroundColor(0x100) mon.setCursorPos(1, 6) mon.write(info[1]["count"] .."/"..64) end
  57.         bar(7,6,9,info[1]["count"],64,0x100)
  58.         mon.setTextColour(0x1) mon.setCursorPos(4, 4) mon.write(string.match(info[1]["name"], ':(.*)'))
  59.             -- если нихуя не осталось, не даём программе сломаться
  60.  
  61.     else
  62.         mon.setBackgroundColor(0x100) mon.setCursorPos(1, 6) mon.write(" ".. 0 .."/"..64)
  63.         bar(7,6,9,0,64,0x100)
  64.         mon.setTextColour(0x1) mon.setCursorPos(4, 4) mon.write("                ")
  65.     end
  66.  
  67.     if info[2] ~= nil then
  68.         mon.setTextColour(0x1) mon.setCursorPos(4, 8) mon.write(string.match(info[2]["name"], ':(.*)'))
  69.     else
  70.         mon.setTextColour(0x1) mon.setCursorPos(4, 8) mon.write("                ")
  71.     end
  72.   end
  73.   os.sleep(0.5)
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement