JFrameXI

mcdonaldsBlack

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