Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get q7maGyKb SM User Input
- SDM = require("SDM")
- CVF = require("CVF")
- SMUI = {}
- local function askForCoords(promptText, num)
- while true do
- print(promptText)
- if num == 2 then
- local input = read()
- local x, z = input:match("(-?%d+)%s+(-?%d+)")
- if x and z then
- return tonumber(x), tonumber(z)
- else
- print("Invalid Format. Pls try again: dirX dirZ")
- end
- else
- local input = read()
- local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
- if x and y and z then
- return tonumber(x), tonumber(y), tonumber(z)
- else
- print("Invalid Format. Pls try again: x y z")
- end
- end
- end
- end
- local function isChestOnLeft()
- print("Is the chest on the left side of this section enter '1'.\n")
- print("For the right side press Enter.")
- local input = read()
- print("\n")
- if input == "1" then
- return true
- end
- return false
- end
- local function checkAllChests()
- print("Enter '1' to select Blocks to check.\n")
- print("Press Enter to check all chests.")
- local input = read()
- print("\n")
- if input == "1" then
- return false
- end
- return true
- end
- local function continueAdding()
- print("Enter '1' to stop.\n")
- print("Press Enter to enter more blocks.")
- local input = read()
- print("\n")
- if input == "1" then
- return false
- end
- return true
- end
- local function isChestInitialized()
- print("Do you want to issue a task to build chests enter '1'.")
- print("Press Enter to only initialize them.")
- local input = read()
- print("\n")
- if input == "1" then
- return false
- end
- return true
- end
- local function isCoordCorrect()
- print("Enter '1' to create the task.")
- print("Press Enter to cancel task.")
- local input = read()
- print("\n")
- if input == "1" then
- return true
- end
- return false
- end
- local function getBlockName(x, y, z)
- return tostring(x) .. " " .. tostring(y) .. " " .. tostring(z)
- end
- function SMUI.requestItem()
- local tIn = SDM.getRequestedItem()
- if not tIn or #textutils.serialize(tIn) > 2 then
- sleep(0.5)
- return
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Which item do you want to take out of the Storage?")
- local userInput = read()
- userInput = userInput:gsub("%s+$", "")
- local reqNum = tonumber(userInput:match(" (%d+)$"))
- local itemName = userInput:gsub(" %d+$", "")
- local itemNum = SDM.getStoredItemNumbers(itemName)
- local preTask = {}
- local item = {}
- if reqNum and itemNum >= reqNum then
- item = SDM.findItem(itemName)
- local info = {
- name = item.name, dName = item.dName,
- stackSize = item.stackSize, number = reqNum
- }
- SDM.setRequestedItem(info)
- print("Request successfully created.")
- sleep(2)
- return
- elseif itemNum == 0 then
- print("This item is currently not stored in the System.")
- print("Press Enter to continue")
- read()
- return
- else
- item = SDM.findItem(itemName)
- print("Available number of type '" .. item.dName .. "':\t\t" .. tostring(itemNum))
- print("How many do you want?")
- reqNum = tonumber(read())
- if not reqNum or reqNum < 0 then
- print("Invalid entry.")
- print("Press Enter to continue")
- read()
- return
- elseif reqNum > itemNum then
- print("Not enough items available in the System.")
- print("Press Enter to continue")
- read()
- return
- elseif reqNum == 0 then
- return
- end
- local info = {
- name = item.name, dName = item.dName,
- stackSize = item.stackSize, number = reqNum
- }
- SDM.setRequestedItem(info)
- print("Request successfully created.")
- sleep(2)
- return
- end
- end
- function SMUI.initSystem()
- if SDM.isFullyInitialized() then print("System Initialized") return true end
- local initData = {}
- print("System is not fully initialized.")
- print("Starting initialisation.\n")
- local x, y, z = askForCoords("Pls enter Coords of first chest (x y z):")
- local dirX, dirZ = askForCoords("Pls enter the direction of the system (dirX dirZ):", 2)
- local posC1 = {x=x, y=y, z=z}
- local dirSys = {x = dirX, z = dirZ}
- local cBlockCoords = {}
- cBlockCoords["0 0 0"] = posC1
- SDM.setChestBlockCoords(cBlockCoords)
- local taskInfo = {
- coords = posC1,
- taskType = "create chests",
- bLeft = false
- }
- if isChestInitialized() then
- taskInfo.taskType = "init chests"
- end
- local posOut = 0
- local strPosOut = ""
- initData.blockHeight = 8
- initData.colBlockNum = 12
- initData.initChestCoord = posC1
- initData.dirSection = dirSys
- initData.dirTopBelt = CVF.getRightDir(dirSys)
- initData.dirBottomBelt = CVF.getLeftDir(dirSys)
- initData.yModulo = y % initData.blockHeight
- initData.lowBeltY = y - 1
- initData.upBeltY = y
- print("\n")
- if CVF.isXDir(initData.dirTopBelt) then
- initData.chestRowMod = x % 4
- initData.chestColMod = z % initData.colBlockNum
- initData.elevPos = z - dirZ
- initData.beltPos = z - 2 * dirZ
- posOut = z - 4 * dirZ
- strPosOut = "z = " .. tostring(posOut)
- else
- initData.chestRowMod = z % 4
- initData.chestColMod = x % initData.colBlockNum
- initData.elevPos = x - dirX
- initData.beltPos = x - 2 * dirX
- posOut = x - 4 * dirX
- strPosOut = "x = " .. tostring(posOut)
- end
- if isChestOnLeft() then
- taskInfo.bLeft = true
- initData.bLeftStart = true
- if CVF.isXDir(initData.dirTopBelt) then
- initData.sectionMod = (x + 2 * initData.dirTopBelt.x) % 8
- initData.leftSecMod = (x + 1 * initData.dirTopBelt.x) % 8
- initData.rightSecMod = (x + 3 * initData.dirTopBelt.x) % 8
- else
- initData.sectionMod = (z + 2 * initData.dirTopBelt.z) % 8
- initData.leftSecMod = (z + 1 * initData.dirTopBelt.z) % 8
- initData.rightSecMod = (z + 3 * initData.dirTopBelt.z) % 8
- end
- else
- initData.bLeftStart = false
- if CVF.isXDir(initData.dirTopBelt) then
- initData.sectionMod = (x + 2 * initData.dirBottomBelt.x) % 8
- initData.leftSecMod = (x + 3 * initData.dirBottomBelt.x) % 8
- initData.rightSecMod = (x + 1 * initData.dirBottomBelt.x) % 8
- else
- initData.sectionMod = (z + 2 * initData.dirBottomBelt.z) % 8
- initData.leftSecMod = (z + 3 * initData.dirBottomBelt.z) % 8
- initData.rightSecMod = (z + 1 * initData.dirBottomBelt.z) % 8
- end
- end
- SDM.setChestPreTask(taskInfo)
- print("\n")
- print("Place the 'Outgoing Task' Disk Drive at coordinates with")
- print(strPosOut .. "\t\ty = " .. tostring(y - 2))
- while true do
- local xOT, yOT, zOT = askForCoords("Please enter the coordinates (x y z):")
- if CVF.isXDir(initData.dirTopBelt) then
- if zOT == posOut and yOT == (y - 2) then
- initData.diskOutCoord = {x = xOT, y = yOT, z = zOT}
- initData.entryModulo = xOT % 2
- initData.exitModulo = (xOT + 1) % 2
- break
- end
- else
- if xOT == posOut and yOT == (y - 2) then
- initData.diskOutCoord = {x = xOT, y = yOT, z = zOT}
- initData.entryModulo = zOT % 2
- initData.exitModulo = (zOT + 1) % 2
- break
- end
- end
- print("Wrong coords.")
- end
- print("\n")
- local vecDiff = CVF.add(dirSys, CVF.mult(7, initData.dirBottomBelt))
- initData.diskFinishCoord = CVF.add(initData.diskOutCoord, vecDiff)
- local strX = "x = " .. tostring(initData.diskFinishCoord.x)
- local strY = "y = " .. tostring(initData.diskFinishCoord.y)
- local strZ = "z = " .. tostring(initData.diskFinishCoord.z)
- print("Place the 'Finished Task' Disk Drive at coordinates")
- print(strX, strY, strZ)
- read()
- local vecDiff = CVF.mult(-1, initData.dirBottomBelt)
- vecDiff.y = 1
- local chest1Coord = CVF.add(initData.diskOutCoord, vecDiff)
- chest2Coord = CVF.add(chest1Coord, initData.dirTopBelt)
- print("Place the Double Chest for chests at")
- strX = "x = " .. tostring(chest1Coord.x)
- strY = "y = " .. tostring(chest1Coord.y)
- strZ = "z = " .. tostring(chest1Coord.z)
- print("1. ", strX, strY, strZ, "and")
- strX = "x = " .. tostring(chest2Coord.x)
- strY = "y = " .. tostring(chest2Coord.y)
- strZ = "z = " .. tostring(chest2Coord.z)
- print("2. ", strX, strY, strZ)
- read()
- local chest3Coord = CVF.add(chest2Coord, initData.dirTopBelt)
- chest3Coord.y = chest3Coord.y + 1
- chest3Coord = CVF.add(chest3Coord, initData.dirTopBelt)
- local chest4Coord = CVF.add(chest3Coord, initData.dirTopBelt)
- print("Place the double chest for pickaxes at")
- strX = "x = " .. tostring(chest3Coord.x)
- strY = "y = " .. tostring(chest3Coord.y)
- strZ = "z = " .. tostring(chest3Coord.z)
- print("1. ", strX, strY, strZ, "and")
- strX = "x = " .. tostring(chest4Coord.x)
- strY = "y = " .. tostring(chest4Coord.y)
- strZ = "z = " .. tostring(chest4Coord.z)
- print("2. ", strX, strY, strZ)
- read()
- initData.pickaxeChestCoord = chest4Coord
- vecDiff = CVF.add(CVF.mult(4, initData.dirBottomBelt), CVF.mult(-3, dirSys))
- local chest5Coords = CVF.add(initData.diskFinishCoord, vecDiff)
- chest5Coords.y = chest5Coords.y + 2
- initData.chestOutCoord = chest5Coords
- local chest6Coords = CVF.add(chest5Coords, initData.dirBottomBelt)
- print("Place the output double chest at")
- strX = "x = " .. tostring(chest5Coords.x)
- strY = "y = " .. tostring(chest5Coords.y)
- strZ = "z = " .. tostring(chest5Coords.z)
- print("1. ", strX, strY, strZ, "and")
- strX = "x = " .. tostring(chest6Coords.x)
- strY = "y = " .. tostring(chest6Coords.y)
- strZ = "z = " .. tostring(chest6Coords.z)
- print("2. ", strX, strY, strZ)
- read()
- local chest7Coords = CVF.add(chest6Coords, initData.dirBottomBelt)
- initData.chestRefuelCoord = chest7Coords
- print("Place the refuel chest for turtles at")
- strX = "x = " .. tostring(chest7Coords.x)
- strY = "y = " .. tostring(chest7Coords.y)
- strZ = "z = " .. tostring(chest7Coords.z)
- print("1. ", strX, strY, strZ)
- read()
- SDM.setInitData(initData)
- if SDM.isFullyInitialized() then print("System Initialized") return true end
- return false
- end
- function SMUI.initChestTask()
- if not SDM.isFullyInitialized() then print("System not Initialized") return false end
- local preTask = SDM.getChestPreTask()
- if preTask and #textutils.serialize(preTask) > 2 then return false end
- term.clear()
- term.setCursorPos(1, 1)
- local initData = SDM.getInitData()
- local taskInfo = {
- coords = {},
- taskType = "create chests",
- bLeft = false
- }
- local cInit = initData.initChestCoord
- local strC1 = "(x = " .. tostring(cInit.x) .. ", y = " .. tostring(cInit.y) .. ", z = " .. tostring(cInit.z) .. ")\n"
- local strMsg1 = "Pls enter the Block Coords.\n"
- local strMsg2 = "Initial Block is 0 0 0 ('forward' 'up' 'right')\n"
- local strMsg3 = "\tThe equivalent coord is\n" .. strC1
- local strMsg = strMsg1 .. strMsg2 .. strMsg3
- local forDir, upDir, rightDir = askForCoords(strMsg)
- if forDir < 0 then
- print("\nForward direction can't be negative.")
- return false
- end
- local strChest = getBlockName(forDir, upDir, rightDir)
- local CB_Coords = SDM.getChestBlockCoords()
- if CB_Coords[strChest] then
- print("\nChest block already in system.")
- return false
- end
- if isChestInitialized() then
- taskInfo.taskType = "init chests"
- end
- term.clear()
- term.setCursorPos(1, 1)
- local diff = CVF.mult(forDir * initData.colBlockNum, initData.dirSection)
- diff = CVF.add(diff, CVF.mult(rightDir * 4, initData.dirTopBelt))
- diff.y = upDir * initData.blockHeight
- local posChest = CVF.add(diff, cInit)
- CB_Coords[strChest] = posChest
- taskInfo.coords = posChest
- if rightDir % 2 == 0 then
- taskInfo.bLeft = initData.bLeftStart
- else
- taskInfo.bLeft = not initData.bLeftStart
- end
- local strC2 = "(x = " .. tostring(posChest.x) .. ", y = " .. tostring(posChest.y) .. ", z = " .. tostring(posChest.z) .. ")"
- print("New coords are: ", strC2)
- if not isCoordCorrect() then return false end
- SDM.setChestPreTask(taskInfo)
- SDM.setChestBlockCoords(CB_Coords)
- return true
- end
- function SMUI.orderInventoryCheck()
- if not SDM.isFullyInitialized() then print("System not Initialized") return false end
- local preTask = SDM.getInvCheckPreTask()
- if preTask and #textutils.serialize(preTask) > 2 then return false end
- term.clear()
- term.setCursorPos(1, 1)
- local taskInfo = {
- taskType = "check chests",
- bAllBlocks = false,
- blockList = {}
- }
- taskInfo.bAllBlocks = checkAllChests()
- local CB_Coords = SDM.getChestBlockCoords()
- if not taskInfo.bAllBlocks then
- while true do
- local x, y, z = askForCoords("Enter the Block coord ('f' 'u' 'r')")
- local strBlock = getBlockName(x, y, z)
- print("\n")
- if CB_Coords[strBlock] and not taskInfo.blockList[strBlock] then
- taskInfo.blockList[strBlock] = CB_Coords[strBlock]
- print("Block (", strBlock ,") successfully entered.\n")
- elseif taskInfo.blockList[strBlock] then
- print("Block (", strBlock ,") already entered.\n")
- else
- print("Block (", strBlock ,") does not exist.\n")
- end
- if continueAdding() then
- term.clear()
- term.setCursorPos(1, 1)
- else
- break
- end
- end
- else
- taskInfo.blockList = {}
- end
- SDM.setInvCheckPreTask(taskInfo)
- return true
- end
- return SMUI
Advertisement
Add Comment
Please, Sign In to add comment