JFrameXI

mcdonaldsBlack

Nov 12th, 2025 (edited)
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- McDonald's V9 with redstone button press
  2. local mon = peripheral.wrap("monitor_14")
  3. local chest = peripheral.wrap("minecraft:chest_0")
  4. local redstoneSide = "back" -- Change this to the side your redstone is connected to
  5.  
  6. mon.setTextScale(0.5)
  7. mon.setBackgroundColor(colors.white)
  8. mon.clear()
  9.  
  10. local w, h = mon.getSize()
  11. local ordersPreparing = {}
  12. local ordersReady = {}
  13. local nextOrderId = 1
  14. local activeOrders = {}
  15. local prepTime = 2
  16.  
  17. local maxBurgers = 64 * 27 * 2 -- 27 single chest, *2 for double
  18.  
  19. -- Function to check if the depot is empty
  20. local function isDepotEmpty()
  21.     return next(peripheral.wrap("create:depot_0").list()) == nil
  22. end
  23.  
  24. -- Get hamburger stock
  25. local function getStock()
  26.     local total = 0
  27.     for _, item in pairs(chest.list()) do
  28.         total = total + item.count
  29.     end
  30.     return total
  31. end
  32.  
  33. local function drawStockBar()
  34.     local stock = getStock()
  35.     local barWidth = w
  36.     local filledWidth = math.floor((stock / maxBurgers) * barWidth)
  37.     local barY = h
  38.  
  39.     mon.setBackgroundColor(colors.white)
  40.     mon.setTextColor(colors.black)
  41.     mon.setCursorPos(1, barY)
  42.     mon.write(string.rep(" ", barWidth))
  43.  
  44.     if filledWidth > 0 then
  45.         mon.setBackgroundColor(colors.green)
  46.         mon.setCursorPos(1, barY)
  47.         mon.write(string.rep(" ", filledWidth))
  48.     end
  49.  
  50.     local text = stock .. " burgers"
  51.     local textX = 1 + math.floor((barWidth - #text) / 2)
  52.  
  53.     for i = 1, #text do
  54.         local charX = textX + i - 1
  55.         local char = text:sub(i, i)
  56.         if charX <= filledWidth then
  57.             mon.setBackgroundColor(colors.green)
  58.         else
  59.             mon.setBackgroundColor(colors.white)
  60.         end
  61.         mon.setCursorPos(charX, barY)
  62.         mon.setTextColor(colors.black)
  63.         mon.write(char)
  64.     end
  65.  
  66.     mon.setBackgroundColor(colors.black)
  67. end
  68.  
  69. local function drawBox(x1, y1, x2, y2, color)
  70.     mon.setBackgroundColor(color)
  71.     for y = y1, y2 do
  72.         mon.setCursorPos(x1, y)
  73.         mon.write(string.rep(" ", x2 - x1 + 1))
  74.     end
  75.     mon.setBackgroundColor(colors.white)
  76. end
  77.  
  78. local function centerText(y, text, color)
  79.     mon.setTextColor(color or colors.black)
  80.     local x = math.floor((w - #text) / 2) + 1
  81.     mon.setCursorPos(x, y)
  82.     mon.write(text)
  83. end
  84.  
  85. local lastStock = getStock()
  86.  
  87. local function updateStock()
  88.     local currentStock = getStock()
  89.     if currentStock ~= lastStock then
  90.         lastStock = currentStock
  91.         drawStockBar()
  92.     end
  93. end
  94.  
  95. local stockTimer = os.startTimer(1)
  96.  
  97. local function drawStaticUI()
  98.     mon.clear()
  99.     local logo = {
  100.         "  __  __      _____                    _     _ _     ",
  101.         " |  \\/  |    |  __ \\                  | |   | ( )    ",
  102.         " | \\  / | ___| |  | | ___  _ __   __ _| | __| |/ ___ ",
  103.         " | |\\/| |/ __| |  | |/ _ \\| '_ \\ / _` | |/ _` | / __|",
  104.         " | |  | | (__| |__| | (_) | | | | (_| | | (_| | \\__ \\",
  105.         " |_|  |_|\\___|_____/ \\___/|_| |_|\\__,_|_|\\__,_| |___/","                                                      "
  106.     }
  107.     local yOffset = 1
  108.     for _, line in ipairs(logo) do
  109.         centerText(yOffset, line, colors.black)
  110.         yOffset = yOffset + 1
  111.     end
  112.  
  113.     drawBox(2, 9, math.floor(w/2)-2, h-5, colors.red)
  114.     drawBox(math.floor(w/2)+2, 9, w-2, h-5, colors.lime)
  115.  
  116.     local btnText = " Place Order "
  117.     local btnX = math.floor((w - #btnText) / 2)
  118.     local btnY = h - 3
  119.  
  120.     mon.setBackgroundColor(colors.orange)
  121.     mon.setTextColor(colors.black)
  122.     for y = btnY - 1, btnY + 1 do
  123.         mon.setCursorPos(btnX - 1, y)
  124.         mon.write(string.rep(" ", #btnText + 2))
  125.     end
  126.  
  127.     mon.setCursorPos(btnX, btnY)
  128.     mon.write(btnText)
  129.  
  130.     drawStockBar()
  131. end
  132.  
  133. local function drawTable(x1, y1, x2, y2, color, title)
  134.     mon.setBackgroundColor(color)
  135.     mon.setTextColor(colors.black)
  136.     for y = y1, y2 do
  137.         mon.setCursorPos(x1, y)
  138.         mon.write(string.rep(" ", x2 - x1 + 1))
  139.     end
  140.     local tableWidth = x2 - x1 + 1
  141.     local titleX = x1 + math.floor((tableWidth - #title) / 2)
  142.     mon.setCursorPos(titleX, y1)
  143.     mon.write(title)
  144. end
  145.  
  146. local function updateOrdersUI()
  147.     local leftX1, leftY1 = 3, 10
  148.     local leftX2, leftY2 = math.floor(w/2)-3, h-6
  149.     local rightX1, rightY1 = math.floor(w/2)+3, 10
  150.     local rightX2, rightY2 = w-3, h-6
  151.  
  152.     drawTable(leftX1, leftY1, leftX2, leftY2, colors.red, "Preparing")
  153.     drawTable(rightX1, rightY1, rightX2, rightY2, colors.lime, "Collect")
  154.  
  155.     for i, order in ipairs(ordersPreparing) do
  156.         mon.setBackgroundColor(colors.red)
  157.         mon.setTextColor(colors.black)
  158.         mon.setCursorPos(leftX1 + 1, leftY1 + i)
  159.         local text = "Order #" .. order
  160.         mon.write(text .. string.rep(" ", leftX2 - leftX1 - #text))
  161.     end
  162.  
  163.     for i, order in ipairs(ordersReady) do
  164.         mon.setBackgroundColor(colors.lime)
  165.         mon.setTextColor(colors.black)
  166.         mon.setCursorPos(rightX1 + 1, rightY1 + i)
  167.         local text = "Order #" .. order
  168.         mon.write(text .. string.rep(" ", rightX2 - rightX1 - #text))
  169.     end
  170.  
  171.     drawStockBar()
  172. end
  173.  
  174. local function addOrder()
  175.     local thisOrder = nextOrderId
  176.     nextOrderId = nextOrderId + 1
  177.     table.insert(ordersPreparing, thisOrder)
  178.  
  179.     local prepTimer = os.startTimer(prepTime)
  180.     activeOrders[prepTimer] = {id = thisOrder, stage = "preparing"}
  181.  
  182.     updateOrdersUI()
  183. end
  184.  
  185. local function isInButton(x, y)
  186.     local btnText = " Place Order "
  187.     local btnX = math.floor((w - #btnText) / 2)
  188.     local btnY = h - 3
  189.     return x >= btnX - 1 and x <= btnX + #btnText and y >= btnY - 1 and y <= btnY + 1
  190. end
  191.  
  192. drawStaticUI()
  193. updateOrdersUI()
  194.  
  195. -- Start stock timer
  196. local stockTimer = os.startTimer(1)
  197.  
  198. while true do
  199.     local event, arg1, arg2, arg3 = os.pullEvent()
  200.    
  201.     if event == "monitor_touch" then
  202.         local x, y = arg2, arg3
  203.         if isInButton(x, y) then
  204.             addOrder()
  205.         end
  206.  
  207.     elseif event == "timer" then
  208.         local timerId = arg1
  209.  
  210.         -- === Stock update timer ===
  211.         if timerId == stockTimer then
  212.             updateStock()
  213.             stockTimer = os.startTimer(1) -- restart stock timer
  214.  
  215.         else
  216.             local order = activeOrders[timerId]
  217.             if order then
  218.                 -- Handle redstone pulse off
  219.                 if order.redstoneOff then
  220.                     redstone.setOutput(redstoneSide, false)
  221.                     activeOrders[timerId] = nil
  222.  
  223.                 -- Preparing → Collect
  224.                 elseif order.stage == "preparing" then
  225.                     -- Remove from preparing table
  226.                     for i, o in ipairs(ordersPreparing) do
  227.                         if o == order.id then
  228.                             table.remove(ordersPreparing, i)
  229.                             break
  230.                         end
  231.                     end
  232.                     -- Add to ready table
  233.                     table.insert(ordersReady, order.id)
  234.                     updateOrdersUI()
  235.  
  236.                     -- Trigger redstone pulse
  237.                     redstone.setOutput(redstoneSide, true)
  238.                     local pulseTimer = os.startTimer(1) -- must be >= 1
  239.                     activeOrders[pulseTimer] = {redstoneOff = true}
  240.  
  241.                     -- Start "check depot" timer after 3s
  242.                     local checkTimer = os.startTimer(3)
  243.                     activeOrders[checkTimer] = {id = order.id, stage = "checkDepot"}
  244.  
  245.                     activeOrders[timerId] = nil
  246.  
  247.                 -- Check if depot is empty
  248.                 elseif order.stage == "checkDepot" then
  249.                     if isDepotEmpty() then
  250.                         -- Remove from ready table
  251.                         for i, o in ipairs(ordersReady) do
  252.                             if o == order.id then
  253.                                 table.remove(ordersReady, i)
  254.                                 break
  255.                             end
  256.                         end
  257.                         updateOrdersUI()
  258.                         activeOrders[timerId] = nil
  259.                     else
  260.                         -- Recheck after 1 second
  261.                         local retryTimer = os.startTimer(1)
  262.                         activeOrders[retryTimer] = {id = order.id, stage = "checkDepot"}
  263.                         activeOrders[timerId] = nil
  264.                     end
  265.                 end
  266.             end
  267.         end
  268.     end
  269. end
Advertisement
Add Comment
Please, Sign In to add comment