Blackhome

UserInput

Feb 1st, 2026 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.14 KB | Gaming | 0 0
  1.     -- pastebin get q7maGyKb SM User Input
  2.  
  3.     SDM = require("SDM")
  4.     CVF = require("CVF")
  5.  
  6.     SMUI = {}
  7.  
  8.     local function askForCoords(promptText, num)
  9.         while true do
  10.             print(promptText)
  11.             if num == 2 then
  12.                 local input = read()
  13.                 local x, z = input:match("(-?%d+)%s+(-?%d+)")
  14.                 if x and z then
  15.                     return tonumber(x), tonumber(z)
  16.                 else
  17.                     print("Invalid Format. Pls try again: dirX dirZ")
  18.                 end
  19.             else
  20.                 local input = read()
  21.                 local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
  22.                 if x and y and z then
  23.                     return tonumber(x), tonumber(y), tonumber(z)
  24.                 else
  25.                     print("Invalid Format. Pls try again: x y z")
  26.                 end
  27.             end
  28.         end
  29.     end
  30.     local function isChestOnLeft()
  31.         print("Is the chest on the left side of this section enter '1'.\n")
  32.         print("For the right side press Enter.")
  33.         local input = read()
  34.        
  35.         print("\n")
  36.  
  37.         if input == "1" then
  38.             return true
  39.         end
  40.         return false
  41.     end
  42.  
  43.     local function checkAllChests()
  44.         print("Enter '1' to select Blocks to check.\n")
  45.         print("Press Enter to check all chests.")
  46.         local input = read()
  47.        
  48.         print("\n")
  49.  
  50.         if input == "1" then
  51.             return false
  52.         end
  53.         return true
  54.     end
  55.  
  56.     local function continueAdding()
  57.         print("Enter '1' to stop.\n")
  58.         print("Press Enter to enter more blocks.")
  59.         local input = read()
  60.        
  61.         print("\n")
  62.  
  63.         if input == "1" then
  64.             return false
  65.         end
  66.         return true
  67.     end
  68.  
  69.     local function isChestInitialized()
  70.         print("Do you want to issue a task to build chests enter '1'.")
  71.         print("Press Enter to only initialize them.")
  72.         local input = read()
  73.  
  74.         print("\n")
  75.  
  76.         if input == "1" then
  77.             return false
  78.         end
  79.         return true
  80.     end
  81.  
  82.     local function isCoordCorrect()
  83.         print("Enter '1' to create the task.")
  84.         print("Press Enter to cancel task.")
  85.         local input = read()
  86.        
  87.         print("\n")
  88.  
  89.         if input == "1" then
  90.             return true
  91.         end
  92.         return false
  93.     end
  94.  
  95.     local function getBlockName(x, y, z)
  96.         return tostring(x) .. " " .. tostring(y) .. " " .. tostring(z)
  97.     end
  98.  
  99.     function SMUI.requestItem()
  100.         local tIn = SDM.getRequestedItem()
  101.  
  102.         if not tIn or #textutils.serialize(tIn) > 2 then
  103.             sleep(0.5)
  104.             return
  105.         end
  106.  
  107.         term.clear()
  108.         term.setCursorPos(1, 1)
  109.         print("Which item do you want to take out of the Storage?")
  110.         local userInput = read()
  111.  
  112.         userInput = userInput:gsub("%s+$", "")
  113.         local reqNum = tonumber(userInput:match(" (%d+)$"))
  114.         local itemName =  userInput:gsub(" %d+$", "")
  115.  
  116.         local itemNum = SDM.getStoredItemNumbers(itemName)
  117.        
  118.         local preTask = {}
  119.  
  120.         local item = {}
  121.         if reqNum and itemNum >= reqNum then
  122.             item = SDM.findItem(itemName)
  123.             local info = {
  124.                 name = item.name, dName = item.dName,
  125.                 stackSize = item.stackSize, number = reqNum
  126.             }
  127.             SDM.setRequestedItem(info)
  128.             print("Request successfully created.")
  129.             sleep(2)
  130.             return
  131.         elseif itemNum == 0 then
  132.             print("This item is currently not stored in the System.")
  133.             print("Press Enter to continue")
  134.             read()
  135.             return
  136.         else
  137.             item = SDM.findItem(itemName)
  138.             print("Available number of type '" .. item.dName .. "':\t\t" .. tostring(itemNum))
  139.             print("How many do you want?")
  140.             reqNum = tonumber(read())
  141.  
  142.             if not reqNum or reqNum < 0 then
  143.                 print("Invalid entry.")
  144.                 print("Press Enter to continue")
  145.                 read()
  146.                 return
  147.             elseif reqNum > itemNum then
  148.                 print("Not enough items available in the System.")
  149.                 print("Press Enter to continue")
  150.                 read()
  151.                 return
  152.             elseif reqNum == 0 then
  153.                 return
  154.             end
  155.  
  156.             local info = {
  157.                 name = item.name, dName = item.dName,
  158.                 stackSize = item.stackSize, number = reqNum
  159.             }
  160.             SDM.setRequestedItem(info)
  161.             print("Request successfully created.")
  162.             sleep(2)
  163.             return
  164.         end
  165.  
  166.     end
  167.  
  168.     function SMUI.initSystem()
  169.         if SDM.isFullyInitialized() then print("System Initialized") return true end
  170.  
  171.         local initData = {}
  172.  
  173.         print("System is not fully initialized.")
  174.         print("Starting initialisation.\n")
  175.  
  176.         local x, y, z = askForCoords("Pls enter Coords of first chest (x y z):")
  177.         local dirX, dirZ = askForCoords("Pls enter the direction of the system (dirX dirZ):", 2)
  178.         local posC1 = {x=x, y=y, z=z}
  179.         local dirSys = {x = dirX, z = dirZ}
  180.  
  181.         local cBlockCoords = {}
  182.         cBlockCoords["0 0 0"] = posC1
  183.         SDM.setChestBlockCoords(cBlockCoords)
  184.  
  185.         local taskInfo = {
  186.             coords = posC1,
  187.             taskType = "create chests",
  188.             bLeft = false
  189.         }
  190.         if isChestInitialized() then
  191.             taskInfo.taskType = "init chests"
  192.         end
  193.  
  194.         local posOut = 0
  195.         local strPosOut = ""
  196.        
  197.         initData.blockHeight = 8
  198.         initData.colBlockNum = 12
  199.         initData.initChestCoord = posC1
  200.         initData.dirSection = dirSys
  201.         initData.dirTopBelt = CVF.getRightDir(dirSys)
  202.         initData.dirBottomBelt = CVF.getLeftDir(dirSys)
  203.         initData.yModulo = y % initData.blockHeight
  204.        
  205.         initData.lowBeltY = y - 1
  206.         initData.upBeltY = y
  207.  
  208.         print("\n")
  209.  
  210.         if CVF.isXDir(initData.dirTopBelt) then
  211.             initData.chestRowMod = x % 4
  212.             initData.chestColMod = z % initData.colBlockNum
  213.             initData.elevPos = z - dirZ
  214.             initData.beltPos = z - 2 * dirZ
  215.  
  216.             posOut = z - 4 * dirZ
  217.             strPosOut = "z = " .. tostring(posOut)
  218.         else
  219.             initData.chestRowMod = z % 4
  220.             initData.chestColMod = x % initData.colBlockNum
  221.             initData.elevPos = x - dirX
  222.             initData.beltPos = x - 2 * dirX
  223.  
  224.             posOut = x - 4 * dirX
  225.             strPosOut = "x = " .. tostring(posOut)
  226.         end
  227.  
  228.         if isChestOnLeft() then
  229.             taskInfo.bLeft = true
  230.             initData.bLeftStart = true
  231.  
  232.             if CVF.isXDir(initData.dirTopBelt) then
  233.                 initData.sectionMod = (x + 2 * initData.dirTopBelt.x) % 8
  234.                 initData.leftSecMod = (x + 1 * initData.dirTopBelt.x) % 8
  235.                 initData.rightSecMod = (x + 3 * initData.dirTopBelt.x) % 8
  236.             else
  237.                 initData.sectionMod = (z + 2 * initData.dirTopBelt.z) % 8
  238.                 initData.leftSecMod = (z + 1 * initData.dirTopBelt.z) % 8
  239.                 initData.rightSecMod = (z + 3 * initData.dirTopBelt.z) % 8
  240.             end
  241.         else
  242.             initData.bLeftStart = false
  243.  
  244.             if CVF.isXDir(initData.dirTopBelt) then
  245.                 initData.sectionMod = (x + 2 * initData.dirBottomBelt.x) % 8
  246.                 initData.leftSecMod = (x + 3 * initData.dirBottomBelt.x) % 8
  247.                 initData.rightSecMod = (x + 1 * initData.dirBottomBelt.x) % 8
  248.             else
  249.                 initData.sectionMod = (z + 2 * initData.dirBottomBelt.z) % 8
  250.                 initData.leftSecMod = (z + 3 * initData.dirBottomBelt.z) % 8
  251.                 initData.rightSecMod = (z + 1 * initData.dirBottomBelt.z) % 8
  252.             end
  253.         end
  254.  
  255.         SDM.setChestPreTask(taskInfo)
  256.  
  257.         print("\n")
  258.         print("Place the 'Outgoing Task' Disk Drive at coordinates with")
  259.         print(strPosOut .. "\t\ty = " .. tostring(y - 2))
  260.         while true do
  261.             local xOT, yOT, zOT = askForCoords("Please enter the coordinates (x y z):")
  262.             if CVF.isXDir(initData.dirTopBelt) then
  263.                 if zOT == posOut and yOT == (y - 2) then
  264.                     initData.diskOutCoord = {x = xOT, y = yOT, z = zOT}
  265.                     initData.entryModulo = xOT % 2
  266.                     initData.exitModulo = (xOT + 1) % 2
  267.                     break
  268.                 end
  269.             else
  270.                 if xOT == posOut and yOT == (y - 2) then
  271.                     initData.diskOutCoord = {x = xOT, y = yOT, z = zOT}
  272.                     initData.entryModulo = zOT % 2
  273.                     initData.exitModulo = (zOT + 1) % 2
  274.                     break
  275.                 end
  276.             end
  277.             print("Wrong coords.")
  278.         end
  279.  
  280.         print("\n")
  281.         local vecDiff = CVF.add(dirSys, CVF.mult(7, initData.dirBottomBelt))
  282.         initData.diskFinishCoord = CVF.add(initData.diskOutCoord, vecDiff)
  283.  
  284.         local strX = "x = " .. tostring(initData.diskFinishCoord.x)
  285.         local strY = "y = " .. tostring(initData.diskFinishCoord.y)
  286.         local strZ = "z = " .. tostring(initData.diskFinishCoord.z)
  287.         print("Place the 'Finished Task' Disk Drive at coordinates")
  288.         print(strX, strY, strZ)
  289.         read()
  290.  
  291.         local vecDiff = CVF.mult(-1, initData.dirBottomBelt)
  292.         vecDiff.y = 1
  293.         local chest1Coord = CVF.add(initData.diskOutCoord, vecDiff)
  294.         chest2Coord = CVF.add(chest1Coord, initData.dirTopBelt)
  295.  
  296.         print("Place the Double Chest for chests at")
  297.         strX = "x = " .. tostring(chest1Coord.x)
  298.         strY = "y = " .. tostring(chest1Coord.y)
  299.         strZ = "z = " .. tostring(chest1Coord.z)
  300.         print("1. ", strX, strY, strZ, "and")
  301.         strX = "x = " .. tostring(chest2Coord.x)
  302.         strY = "y = " .. tostring(chest2Coord.y)
  303.         strZ = "z = " .. tostring(chest2Coord.z)
  304.         print("2. ", strX, strY, strZ)
  305.         read()
  306.  
  307.         local chest3Coord = CVF.add(chest2Coord, initData.dirTopBelt)
  308.         chest3Coord.y = chest3Coord.y + 1
  309.         chest3Coord = CVF.add(chest3Coord, initData.dirTopBelt)
  310.         local chest4Coord = CVF.add(chest3Coord, initData.dirTopBelt)
  311.  
  312.         print("Place the double chest for pickaxes at")
  313.         strX = "x = " .. tostring(chest3Coord.x)
  314.         strY = "y = " .. tostring(chest3Coord.y)
  315.         strZ = "z = " .. tostring(chest3Coord.z)
  316.         print("1. ", strX, strY, strZ, "and")
  317.         strX = "x = " .. tostring(chest4Coord.x)
  318.         strY = "y = " .. tostring(chest4Coord.y)
  319.         strZ = "z = " .. tostring(chest4Coord.z)
  320.         print("2. ", strX, strY, strZ)
  321.         read()
  322.  
  323.         initData.pickaxeChestCoord = chest4Coord
  324.  
  325.         vecDiff = CVF.add(CVF.mult(4, initData.dirBottomBelt), CVF.mult(-3, dirSys))
  326.    
  327.         local chest5Coords = CVF.add(initData.diskFinishCoord, vecDiff)
  328.         chest5Coords.y = chest5Coords.y + 2
  329.         initData.chestOutCoord = chest5Coords
  330.  
  331.         local chest6Coords = CVF.add(chest5Coords, initData.dirBottomBelt)
  332.  
  333.         print("Place the output double chest at")
  334.         strX = "x = " .. tostring(chest5Coords.x)
  335.         strY = "y = " .. tostring(chest5Coords.y)
  336.         strZ = "z = " .. tostring(chest5Coords.z)
  337.         print("1. ", strX, strY, strZ, "and")
  338.         strX = "x = " .. tostring(chest6Coords.x)
  339.         strY = "y = " .. tostring(chest6Coords.y)
  340.         strZ = "z = " .. tostring(chest6Coords.z)
  341.         print("2. ", strX, strY, strZ)
  342.         read()
  343.  
  344.         local chest7Coords = CVF.add(chest6Coords, initData.dirBottomBelt)
  345.         initData.chestRefuelCoord = chest7Coords
  346.  
  347.         print("Place the refuel chest for turtles at")
  348.         strX = "x = " .. tostring(chest7Coords.x)
  349.         strY = "y = " .. tostring(chest7Coords.y)
  350.         strZ = "z = " .. tostring(chest7Coords.z)
  351.         print("1. ", strX, strY, strZ)
  352.         read()
  353.  
  354.         SDM.setInitData(initData)
  355.  
  356.         if SDM.isFullyInitialized() then print("System Initialized") return true end
  357.  
  358.         return false
  359.     end
  360.  
  361.     function SMUI.initChestTask()
  362.         if not SDM.isFullyInitialized() then print("System not Initialized") return false end
  363.         local preTask = SDM.getChestPreTask()
  364.         if preTask and #textutils.serialize(preTask) > 2 then return false end
  365.  
  366.  
  367.         term.clear()
  368.         term.setCursorPos(1, 1)
  369.  
  370.         local initData = SDM.getInitData()
  371.  
  372.         local taskInfo = {
  373.             coords = {},
  374.             taskType = "create chests",
  375.             bLeft = false
  376.         }
  377.         local cInit = initData.initChestCoord
  378.         local strC1 = "(x = " .. tostring(cInit.x) .. ", y = " .. tostring(cInit.y) .. ", z = " .. tostring(cInit.z) .. ")\n"
  379.         local strMsg1 = "Pls enter the Block Coords.\n"
  380.         local strMsg2 = "Initial Block is 0 0 0 ('forward' 'up' 'right')\n"
  381.         local strMsg3 =  "\tThe equivalent coord is\n" .. strC1
  382.  
  383.         local strMsg = strMsg1 .. strMsg2 .. strMsg3
  384.  
  385.        
  386.         local forDir, upDir, rightDir = askForCoords(strMsg)
  387.  
  388.         if forDir < 0 then
  389.             print("\nForward direction can't be negative.")
  390.             return false
  391.         end
  392.  
  393.         local strChest = getBlockName(forDir, upDir, rightDir)
  394.         local CB_Coords = SDM.getChestBlockCoords()
  395.         if CB_Coords[strChest] then
  396.             print("\nChest block already in system.")
  397.             return false
  398.         end
  399.  
  400.         if isChestInitialized() then
  401.             taskInfo.taskType = "init chests"
  402.         end
  403.  
  404.         term.clear()
  405.         term.setCursorPos(1, 1)
  406.  
  407.         local diff = CVF.mult(forDir * initData.colBlockNum, initData.dirSection)
  408.                 diff = CVF.add(diff, CVF.mult(rightDir * 4, initData.dirTopBelt))
  409.                 diff.y = upDir * initData.blockHeight
  410.        
  411.         local posChest = CVF.add(diff, cInit)
  412.         CB_Coords[strChest] = posChest
  413.  
  414.         taskInfo.coords = posChest
  415.  
  416.         if rightDir % 2 == 0 then
  417.             taskInfo.bLeft = initData.bLeftStart
  418.         else
  419.             taskInfo.bLeft = not initData.bLeftStart
  420.         end
  421.  
  422.  
  423.  
  424.         local strC2 = "(x = " .. tostring(posChest.x) .. ", y = " .. tostring(posChest.y) .. ", z = " .. tostring(posChest.z) .. ")"
  425.         print("New coords are:  ", strC2)
  426.         if not isCoordCorrect() then return false end
  427.  
  428.         SDM.setChestPreTask(taskInfo)
  429.         SDM.setChestBlockCoords(CB_Coords)
  430.  
  431.         return true
  432.     end
  433.  
  434.     function SMUI.orderInventoryCheck()
  435.         if not SDM.isFullyInitialized() then print("System not Initialized") return false end
  436.         local preTask = SDM.getInvCheckPreTask()
  437.         if preTask and #textutils.serialize(preTask) > 2 then return false end
  438.  
  439.         term.clear()
  440.         term.setCursorPos(1, 1)
  441.  
  442.         local taskInfo = {
  443.             taskType = "check chests",
  444.             bAllBlocks = false,
  445.             blockList = {}
  446.         }
  447.         taskInfo.bAllBlocks = checkAllChests()
  448.  
  449.         local CB_Coords = SDM.getChestBlockCoords()
  450.  
  451.         if not taskInfo.bAllBlocks then
  452.             while true do
  453.                 local x, y, z = askForCoords("Enter the Block coord ('f' 'u' 'r')")
  454.                 local strBlock = getBlockName(x, y, z)
  455.                 print("\n")
  456.  
  457.                 if CB_Coords[strBlock] and not taskInfo.blockList[strBlock] then
  458.                     taskInfo.blockList[strBlock] = CB_Coords[strBlock]
  459.                     print("Block (", strBlock ,") successfully entered.\n")
  460.                 elseif taskInfo.blockList[strBlock] then
  461.                     print("Block (", strBlock ,") already entered.\n")
  462.                 else
  463.                     print("Block (", strBlock ,") does not exist.\n")
  464.                 end
  465.  
  466.                 if continueAdding() then
  467.                     term.clear()
  468.                     term.setCursorPos(1, 1)
  469.                 else
  470.                     break
  471.                 end
  472.             end
  473.         else
  474.             taskInfo.blockList = {}
  475.         end
  476.  
  477.         SDM.setInvCheckPreTask(taskInfo)
  478.  
  479.         return true
  480.     end
  481.  
  482.     return SMUI
Advertisement
Add Comment
Please, Sign In to add comment