Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ZROBIC WYSWIETLANIE LAMP PRZED KALKULACJA, A PO KALKULACJI NADPISAC TABELE I PO TERM.CLEAR OD RAZU WYSWIETLIC DANE Z POPRZEDNIEJ PETLI
- local allPositions = {
- {3, 1}, {4, 1}, {3, 2}, {4, 2},
- {4, 2}, {5, 2}, {4, 3}, {5, 3},
- {4, 3}, {5, 3}, {4, 4}, {5, 4},
- {3, 4}, {4, 4}, {3, 5}, {4, 5},
- {2, 4}, {3, 4}, {2, 5}, {3, 5},
- {1, 3}, {2, 3}, {1, 4}, {2, 4},
- {1, 2}, {2, 2}, {1, 3}, {2, 3},
- {2, 1}, {3, 1}, {2, 2}, {3, 2}
- }
- -- Your fixed sections
- local sections = {
- -- Section 0 (0°-45°) - Top-right quadrant start
- {
- {3, 1}, {4, 1}, {3, 2}, {4, 2}, {3,3}
- },
- -- Section 1 (45°-90°) - Top-right quadrant end
- {
- {4, 2}, {5, 2}, {4, 3}, {5, 3}, {3,3}
- },
- -- Section 2 (90°-135°) - Bottom-right quadrant start
- {
- {4, 3}, {5, 3}, {4, 4}, {5, 4}, {3,3}
- },
- -- Section 3 (135°-180°) - Bottom-right quadrant end
- {
- {3, 4}, {4, 4}, {3, 5}, {4, 5}, {3,3}
- },
- -- Section 4 (180°-225°) - Bottom-left quadrant start
- {
- {2, 4}, {3, 4}, {2, 5}, {3, 5}, {3,3}
- },
- -- Section 5 (225°-270°) - Bottom-left quadrant end
- {
- {1, 3}, {2, 3}, {1, 4}, {2, 4}, {3,3}
- },
- -- Section 6 (270°-315°) - Top-left quadrant start
- {
- {1, 2}, {2, 2}, {1, 3}, {2, 3}, {3,3}
- },
- -- Section 7 (315°-360°) - Top-left quadrant end
- {
- {2, 1}, {3, 1}, {2, 2}, {3, 2}, {3,3}
- }
- }
- -- Main animation loop
- local xPos = 41 -- Center the 5x5 shape (18-5=13/2≈6.5 → start at 7)
- local yPos = 1
- local frame = 0
- local lamps = {peripheral.find("occultism:dimensional_mineshaft")}
- local depotPeri = peripheral.find("create:depot")
- local depot = peripheral.getName(depotPeri)
- local repairing = false
- -- Track objects sent for repair
- local repairQueue = {} -- [objectIndex] = pullTime
- closethreshold = 75
- threshold = 50 -- percent threshold when to send lamp for repair
- timetorepair = 5
- --51x19
- logs = {}
- local function drawBox(size, xoff, yoff, color)
- local x,y = term.getCursorPos()
- term.setBackgroundColor(color)
- local horizLine = string.rep(" ", size[1])
- term.setCursorPos(xoff + 1, yoff + 1)
- term.write(horizLine)
- term.setCursorPos(xoff + 1, yoff + size[2])
- term.write(horizLine)
- -- Draw vertical lines
- for i=0, size[2] - 1 do
- term.setCursorPos(xoff + 1, yoff + i + 1)
- term.write(" ")
- term.setCursorPos(xoff + size[1], yoff + i +1)
- term.write(" ")
- end
- term.setCursorPos(x,y)
- term.setBackgroundColor(colors.black)
- end
- --Draw a filled box
- local function drawFilledBox(size, xoff, yoff, colorOut, colorIn)
- local horizLine = string.rep(" ", size[1] - 2)
- drawBox(size, xoff, yoff, colorOut)
- local x,y = term.getCursorPos()
- term.setBackgroundColor(colorIn)
- for i=2, size[2] - 1 do
- term.setCursorPos(xoff + 2, yoff + i)
- term.write(horizLine)
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(x,y)
- end
- function addLog(message)
- table.insert(logs, 1, os.date("%H:%M:%S").."] "..message)
- while #logs > 3 do table.remove(logs) end
- end
- function updateColors(frame)
- -- Calculate current and previous sections
- local limeSection = frame % 8
- local greenSection = (frame - 1 + 8) % 8
- for _, pos in ipairs(allPositions) do
- -- local key = pos[1] .. "," .. pos[2]
- term.setCursorPos(xPos + pos[1], yPos + pos[2])
- term.setBackgroundColor(colors.gray)
- term.write(" ")
- end
- -- Set GREEN first (previous section becomes trail)
- for _, pos in ipairs(sections[greenSection + 1]) do
- term.setCursorPos(xPos + pos[1], yPos + pos[2])
- term.setBackgroundColor(colors.green)
- term.write(" ")
- end
- -- Set LIME second (current section, overwrites green on shared coordinates)
- for _, pos in ipairs(sections[limeSection + 1]) do
- term.setCursorPos(xPos + pos[1], yPos + pos[2])
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- end
- end
- function repairObject(obj)
- if repairing then return end -- Already repairing, skip
- -- Send object for repair
- obj.pushItems(depot, 1)
- repairing = true
- -- Schedule when to pull it back (5 seconds from now)
- repairQueue[obj] = os.clock() + timetorepair
- addLog("Sent miner lamp to repair Depot")
- end
- function checkRepairReturns()
- local currentTime = os.clock()
- for obj, pullTime in pairs(repairQueue) do
- if currentTime >= pullTime then
- -- Time to pull it back
- obj.pullItems(depot, 1) -- Use same target/slot/count
- repairQueue[obj] = nil
- repairing = false
- addLog("Retrieved miner lamp from repair Depot")
- end
- end
- end
- term.clear()
- lampsOld = {}
- addLog("Program started.")
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- frame = (frame + 1) % 8
- updateColors(frame)
- drawFilledBox({34,11}, 1, 1, colors.cyan, colors.black) -- draw mineshafts box
- term.setCursorPos(22,2)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.cyan)
- term.write(" Mineshafts ")
- for i,lamp in ipairs(lampsOld) do
- k = i - 1
- v = math.floor(k/7)
- term.setCursorPos(4 + v*10, 4 + (k - v * 7))
- term.setTextColor(colors.lightGray)
- -- if lampsOld[i].percent < threshold then
- -- term.setTextColor(colors.red)
- -- elseif lampsOld[i].percent < closethreshold then
- -- term.setTextColor(colors.orange)
- -- else
- -- term.setTextColor(colors.lightGray)
- -- end
- term.write(lamp)
- end
- lampsOld = {}
- drawFilledBox({14,5}, 36, 7, colors.green, colors.black) -- draw storage box
- term.setCursorPos(42,8)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.write(" Depot ")
- term.setCursorPos(39, 10)
- term.setTextColor(colors.black)
- if not repairing then
- term.setBackgroundColor(colors.lime)
- term.write(" IDLE ")
- else
- term.setBackgroundColor(colors.red)
- term.write(" BUSY ")
- end
- drawFilledBox({49,5}, 1, 13, colors.gray, colors.black) -- draw logs box
- term.setCursorPos(42,14)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.gray)
- term.write(" Logs ")
- -- tempfun()
- -- temp = math.random(1,50)
- -- if temp > 0 and temp < 4 then
- -- addLog(logsSET[temp])
- -- end
- term.setTextColor(colors.lightGray)
- for i = 1, #logs do
- term.setCursorPos(3, 14 + i)
- term.write(logs[i])
- end
- for i,lamp in ipairs(lamps) do
- if i > 21 then break end
- if lamp.getItemDetail(1) then
- maxdura = lamp.getItemDetail(1).maxDamage
- dura = maxdura - lamp.getItemDetail(1).damage
- percent = math.floor(dura/maxdura*100)
- --print(dura.."/"..maxdura.." ("..percent.."%)")
- if percent < threshold and not repairing then
- repairObject(lamp)
- else
- lampsOld[i] = dura.."/"..maxdura
- -- lampsOld[i].percent = percent
- end
- --term.write(dura.."/"..maxdura)
- end
- end --koniec lamp
- checkRepairReturns()
- -- parallel.waitForAny(
- -- function()
- -- os.pullEvent("key")
- -- os.shutdown()
- -- end,
- -- function()
- -- sleep(0.5)
- -- end
- -- )
- sleep(0.5)
- end
- term.setCursorPos(1,19)
Advertisement
Add Comment
Please, Sign In to add comment