se7enek

DimensionalMineshafts

Jun 1st, 2026 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.93 KB | None | 0 0
  1. --ZROBIC WYSWIETLANIE LAMP PRZED KALKULACJA, A PO KALKULACJI NADPISAC TABELE I PO TERM.CLEAR OD RAZU WYSWIETLIC DANE Z POPRZEDNIEJ PETLI
  2.  
  3. local allPositions = {
  4.    
  5.     {3, 1}, {4, 1}, {3, 2}, {4, 2},
  6.     {4, 2}, {5, 2}, {4, 3}, {5, 3},
  7.     {4, 3}, {5, 3}, {4, 4}, {5, 4},
  8.     {3, 4}, {4, 4}, {3, 5}, {4, 5},
  9.     {2, 4}, {3, 4}, {2, 5}, {3, 5},
  10.     {1, 3}, {2, 3}, {1, 4}, {2, 4},
  11.     {1, 2}, {2, 2}, {1, 3}, {2, 3},
  12.     {2, 1}, {3, 1}, {2, 2}, {3, 2}
  13.  
  14. }
  15.  
  16. -- Your fixed sections
  17. local sections = {
  18. -- Section 0 (0°-45°) - Top-right quadrant start
  19. {
  20.     {3, 1}, {4, 1}, {3, 2}, {4, 2}, {3,3}
  21. },
  22. -- Section 1 (45°-90°) - Top-right quadrant end
  23. {
  24.     {4, 2}, {5, 2}, {4, 3}, {5, 3}, {3,3}
  25. },
  26. -- Section 2 (90°-135°) - Bottom-right quadrant start
  27. {
  28.     {4, 3}, {5, 3}, {4, 4}, {5, 4}, {3,3}
  29. },
  30. -- Section 3 (135°-180°) - Bottom-right quadrant end
  31. {
  32.     {3, 4}, {4, 4}, {3, 5}, {4, 5}, {3,3}
  33. },
  34. -- Section 4 (180°-225°) - Bottom-left quadrant start
  35. {
  36.     {2, 4}, {3, 4}, {2, 5}, {3, 5}, {3,3}
  37. },
  38. -- Section 5 (225°-270°) - Bottom-left quadrant end
  39. {
  40.     {1, 3}, {2, 3}, {1, 4}, {2, 4}, {3,3}
  41. },
  42. -- Section 6 (270°-315°) - Top-left quadrant start
  43. {
  44.     {1, 2}, {2, 2}, {1, 3}, {2, 3}, {3,3}
  45. },
  46. -- Section 7 (315°-360°) - Top-left quadrant end
  47. {
  48.     {2, 1}, {3, 1}, {2, 2}, {3, 2}, {3,3}
  49. }
  50. }
  51.  
  52.  
  53. -- Main animation loop
  54. local xPos = 41  -- Center the 5x5 shape (18-5=13/2≈6.5 → start at 7)
  55. local yPos = 1
  56. local frame = 0
  57.  
  58. local lamps = {peripheral.find("occultism:dimensional_mineshaft")}
  59. local depotPeri = peripheral.find("create:depot")
  60. local depot = peripheral.getName(depotPeri)
  61. local repairing = false
  62.  
  63.  
  64.  
  65. -- Track objects sent for repair
  66. local repairQueue = {}  -- [objectIndex] = pullTime
  67.  
  68.  
  69. closethreshold = 75
  70. threshold = 50 -- percent threshold when to send lamp for repair
  71. timetorepair = 5
  72.  
  73. --51x19
  74.  
  75. logs = {}
  76.  
  77.  
  78.  
  79.  
  80. local function drawBox(size, xoff, yoff, color)
  81.     local x,y = term.getCursorPos()
  82.     term.setBackgroundColor(color)
  83.     local horizLine = string.rep(" ", size[1])
  84.     term.setCursorPos(xoff + 1, yoff + 1)
  85.     term.write(horizLine)
  86.     term.setCursorPos(xoff + 1, yoff + size[2])
  87.     term.write(horizLine)
  88.  
  89.     -- Draw vertical lines
  90.     for i=0, size[2] - 1 do
  91.         term.setCursorPos(xoff + 1, yoff + i + 1)
  92.         term.write(" ")
  93.         term.setCursorPos(xoff + size[1], yoff + i +1)
  94.         term.write(" ")
  95.     end
  96.     term.setCursorPos(x,y)
  97.     term.setBackgroundColor(colors.black)
  98.   end
  99.  
  100.   --Draw a filled box
  101.   local function drawFilledBox(size, xoff, yoff, colorOut, colorIn)
  102.     local horizLine = string.rep(" ", size[1] - 2)
  103.     drawBox(size, xoff, yoff, colorOut)
  104.     local x,y = term.getCursorPos()
  105.     term.setBackgroundColor(colorIn)
  106.     for i=2, size[2] - 1 do
  107.         term.setCursorPos(xoff + 2, yoff + i)
  108.         term.write(horizLine)
  109.     end
  110.     term.setBackgroundColor(colors.black)
  111.     term.setCursorPos(x,y)
  112.   end
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.   function addLog(message)
  120.       table.insert(logs, 1, os.date("%H:%M:%S").."] "..message)
  121.       while #logs > 3 do table.remove(logs) end
  122.   end
  123.  
  124.   function updateColors(frame)
  125.  
  126.     -- Calculate current and previous sections
  127.     local limeSection = frame % 8
  128.     local greenSection = (frame - 1 + 8) % 8
  129.    
  130.  
  131.     for _, pos in ipairs(allPositions) do
  132.         -- local key = pos[1] .. "," .. pos[2]
  133.         term.setCursorPos(xPos + pos[1], yPos + pos[2])
  134.         term.setBackgroundColor(colors.gray)
  135.         term.write(" ")
  136.     end
  137.     -- Set GREEN first (previous section becomes trail)
  138.     for _, pos in ipairs(sections[greenSection + 1]) do
  139.         term.setCursorPos(xPos + pos[1], yPos + pos[2])
  140.         term.setBackgroundColor(colors.green)
  141.         term.write(" ")
  142.     end
  143.    
  144.     -- Set LIME second (current section, overwrites green on shared coordinates)
  145.     for _, pos in ipairs(sections[limeSection + 1]) do
  146.         term.setCursorPos(xPos + pos[1], yPos + pos[2])
  147.         term.setBackgroundColor(colors.lime)
  148.         term.write(" ")
  149.     end
  150. end
  151.  
  152.  
  153. function repairObject(obj)
  154.     if repairing then return end  -- Already repairing, skip
  155.     -- Send object for repair
  156.     obj.pushItems(depot, 1)
  157.     repairing = true
  158.     -- Schedule when to pull it back (5 seconds from now)
  159.     repairQueue[obj] = os.clock() + timetorepair
  160.     addLog("Sent miner lamp to repair Depot")
  161.   end
  162.    
  163.   function checkRepairReturns()
  164.     local currentTime = os.clock()
  165.    
  166.     for obj, pullTime in pairs(repairQueue) do
  167.       if currentTime >= pullTime then
  168.         -- Time to pull it back
  169.         obj.pullItems(depot, 1)  -- Use same target/slot/count
  170.         repairQueue[obj] = nil
  171.         repairing = false
  172.         addLog("Retrieved miner lamp from repair Depot")
  173.       end
  174.     end
  175.   end
  176.  
  177.  
  178.   term.clear()
  179.  
  180.   lampsOld = {}
  181.  
  182.   addLog("Program started.")
  183.  
  184.   while true do
  185.  
  186.       term.setBackgroundColor(colors.black)
  187.       term.clear()
  188.  
  189.       frame = (frame + 1) % 8
  190.       updateColors(frame)
  191.  
  192.       drawFilledBox({34,11}, 1, 1, colors.cyan, colors.black) -- draw mineshafts box
  193.       term.setCursorPos(22,2)
  194.       term.setBackgroundColor(colors.black)
  195.       term.setTextColor(colors.cyan)
  196.       term.write(" Mineshafts ")
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.     for i,lamp in ipairs(lampsOld) do
  212.  
  213.         k = i - 1
  214.         v = math.floor(k/7)
  215.         term.setCursorPos(4 + v*10, 4 + (k - v * 7))
  216.         term.setTextColor(colors.lightGray)
  217.        
  218.         -- if lampsOld[i].percent < threshold then
  219.         --     term.setTextColor(colors.red)
  220.         -- elseif lampsOld[i].percent < closethreshold then
  221.         --     term.setTextColor(colors.orange)
  222.         -- else
  223.         --     term.setTextColor(colors.lightGray)
  224.         -- end
  225.  
  226.         term.write(lamp)
  227.         end
  228.  
  229.     lampsOld = {}
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.       drawFilledBox({14,5}, 36, 7, colors.green, colors.black) -- draw storage box
  239.       term.setCursorPos(42,8)
  240.       term.setBackgroundColor(colors.black)
  241.       term.setTextColor(colors.green)
  242.       term.write(" Depot ")
  243.  
  244.       term.setCursorPos(39, 10)
  245.       term.setTextColor(colors.black)
  246.       if not repairing then
  247.           term.setBackgroundColor(colors.lime)
  248.           term.write("   IDLE   ")
  249.       else
  250.               term.setBackgroundColor(colors.red)
  251.               term.write("   BUSY   ")
  252.       end
  253.      
  254.      
  255.      
  256.      
  257.  
  258.  
  259.       drawFilledBox({49,5}, 1, 13, colors.gray, colors.black) -- draw logs box
  260.       term.setCursorPos(42,14)
  261.       term.setBackgroundColor(colors.black)
  262.       term.setTextColor(colors.gray)
  263.       term.write(" Logs ")
  264.  
  265.       -- tempfun()
  266.  
  267.       -- temp = math.random(1,50)
  268.       -- if temp > 0 and temp < 4 then
  269.       -- addLog(logsSET[temp])
  270.       -- end
  271.      
  272.       term.setTextColor(colors.lightGray)
  273.       for i = 1, #logs do
  274.           term.setCursorPos(3, 14 + i)
  275.           term.write(logs[i])
  276.       end
  277.  
  278.  
  279.      
  280.  
  281.  
  282.  
  283.       for i,lamp in ipairs(lamps) do
  284.           if i > 21 then break end
  285.  
  286.           if lamp.getItemDetail(1) then
  287.  
  288.           maxdura = lamp.getItemDetail(1).maxDamage
  289.           dura = maxdura - lamp.getItemDetail(1).damage
  290.           percent = math.floor(dura/maxdura*100)
  291.           --print(dura.."/"..maxdura.." ("..percent.."%)")
  292.          
  293.           if percent < threshold and not repairing then
  294.               repairObject(lamp)
  295.           else
  296.             lampsOld[i] = dura.."/"..maxdura
  297.             -- lampsOld[i].percent = percent
  298.           end
  299.  
  300.          
  301.           --term.write(dura.."/"..maxdura)
  302.            
  303.           end
  304.            
  305.           end --koniec lamp
  306.            
  307.        
  308.            
  309.            
  310.           checkRepairReturns()
  311.      
  312.  
  313.      -- parallel.waitForAny(
  314.       --     function()
  315.       --         os.pullEvent("key")
  316.       --         os.shutdown()
  317.       --     end,
  318.       --     function()
  319.       --         sleep(0.5)
  320.       --     end
  321.       -- )
  322.  
  323.       sleep(0.5)
  324.   end
  325.  
  326.   term.setCursorPos(1,19)
Advertisement
Add Comment
Please, Sign In to add comment