andrelisboa1

mvbSmartStorage

Jun 16th, 2025 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | Software | 0 0
  1. local monitor = peripheral.find("monitor")
  2.  
  3. function writeToMonitor(x, y, txt, color)
  4.   monitor.setTextColor(color)
  5.   monitor.setCursorPos(x, y)
  6.   monitor.write(txt)
  7. end
  8.  
  9. -- Table of keys.
  10. keyMapping = {
  11.   -- Maps (x * 100 + y) to the key.
  12.   [308] = "1", [408] = "2", [508] = "3", [608] = "4", [708] = "5", [808] = "6", [908] = "7", [1008] = "8", [1108] = "9", [1208] = "0", [1308] = "'", [1608] = "bk",
  13.   [309] = "Q", [409] = "W", [509] = "E", [609] = "R", [709] = "T", [809] = "Y", [909] = "U", [1009] = "I", [1109] = "O", [1209] = "P",
  14.   [310] = "A", [410] = "S", [510] = "D", [610] = "F", [710] = "G", [810] = "H", [910] = "J", [1010] = "K", [1110] = "L",
  15.   [311] = "Z", [411] = "X", [511] = "C", [611] = "V", [711] = "B", [811] = "N", [911] = "M", [1011] = ":", [1511] = " "
  16. }
  17. keyChars = {
  18.   [308] = "1", [408] = "2", [508] = "3", [608] = "4", [708] = "5", [808] = "6", [908] = "7", [1008] = "8", [1108] = "9", [1208] = "0", [1308] = "'", [1608] = "<",
  19.   [309] = "Q", [409] = "W", [509] = "E", [609] = "R", [709] = "T", [809] = "Y", [909] = "U", [1009] = "I", [1109] = "O", [1209] = "P",
  20.   [310] = "A", [410] = "S", [510] = "D", [610] = "F", [710] = "G", [810] = "H", [910] = "J", [1010] = "K", [1110] = "L",
  21.   [311] = "Z", [411] = "X", [511] = "C", [611] = "V", [711] = "B", [811] = "N", [911] = "M", [1011] = ":", [1511] = " "
  22. }
  23. --
  24.  
  25. -- Data.
  26. screen = "startMenu"
  27. textInput = ""
  28. lastKeyX = 0
  29. lastKeyY = 0
  30. lastKeyText = " "
  31. --
  32.  
  33. while screen ~= "exit" do
  34.   monitor.clear()
  35.   if screen == "startMenu" then
  36.     writeToMonitor(1, 1, "[ Welcome to the ]", colors.yellow)
  37.     writeToMonitor(1, 2, "[ Smart Storage! ]", colors.yellow)
  38.  
  39.     writeToMonitor(1, 5, "[_Store_All______]", colors.green)
  40.     writeToMonitor(1, 7, "[_Turn_Off_______]", colors.red)
  41.     local event, side, cx, cy = os.pullEvent("monitor_touch")
  42.    
  43.     -- print("The monitor on side " .. side .. " was touched at (" .. x .. ", " .. y .. ")")
  44.     if cy == 7 then
  45.       monitor.clear()
  46.       screen = "exit"
  47.     elseif cy == 5 then
  48.       screen = "storeAll"
  49.     end
  50.   elseif screen == "storeAll" then
  51.     local chest = peripheral.find("minecraft:chest")
  52.     writeToMonitor(1, 1, "[Input Contents: ]", colors.yellow)
  53.     for slot, item in pairs(chest.list()) do
  54.       print(("%d x %s in slot %d"):format(item.count, item.name, slot))
  55.     end
  56.     local event, side, cx, cy = os.pullEvent("monitor_touch")
  57.   elseif screen == "testKeyboard" then
  58.     writeToMonitor(1, 2, textInput .. "|", colors.cyan)
  59.     writeToMonitor(1, 7,   "__________________", colors.white)
  60.     writeToMonitor(1, 8,   "| 1234567890' [<]|", colors.white)
  61.     writeToMonitor(1, 9,   "| QWERTYUIOP   | |", colors.white)
  62.     writeToMonitor(1, 10,  "| ASDFGHJKL   -' |", colors.white)
  63.     writeToMonitor(1, 11,  "| ZXCVBNM:   [ ] |", colors.white)
  64.     if lastKeyX ~= 0 then
  65.       monitor.setCursorPos(lastKeyX, lastKeyY)
  66.       monitor.blit(lastKeyText, "0", "d")
  67.     end
  68.     local event, side, cx, cy = os.pullEvent("monitor_touch")
  69.     cxy = cx * 100 + cy
  70.  
  71.     if keyMapping[cxy] then
  72.       local k = keyMapping[cxy]
  73.       if k == "bk" then
  74.         -- Delete last character.        
  75.         textInput = textInput:sub(1, -2)
  76.       else
  77.         textInput = textInput .. k
  78.       end
  79.       lastKeyText = keyChars[cxy]
  80.       lastKeyX = cx
  81.       lastKeyY = cy
  82.     end
  83.    
  84.   end
  85. end
  86.  
Advertisement
Add Comment
Please, Sign In to add comment