Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DISK_NAMES = {
- incoming = "Incoming Task",
- user = "User Task",
- outgoing = "Outgoing Task",
- finished = "Finished Task",
- settings = "Settings",
- storage = "Data Storage",
- init = "Turtle Initializing"
- }
- local TASK_TYPES = {
- createChests = "create_chests",
- storeItems = "store_items",
- getItems = "get_items",
- checkInventory = "check_inventory",
- initializeChests = "initialize_chests"
- }
- local TASK_FILE = "task_list.txt"
- function getDiskByLabel(label)
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == label then
- return disk, disk.getMountPath()
- end
- end
- end
- return nil, nil
- end
- function askForCoords(promptText)
- while true do
- print(promptText)
- 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("Ungültiges Format. Bitte erneut eingeben als: x y z")
- end
- end
- end
- function getTaskList(path)
- if not fs.exists(path) then return {} end
- local file = fs.open(path, "r")
- local data = textutils.unserialize(file.readAll())
- file.close()
- return data or {}
- end
- function saveTaskList(path, taskList)
- local file = fs.open(path, "w")
- file.write(textutils.serialize(taskList))
- file.close()
- end
- function addTaskToList(path, task)
- local tasks = getTaskList(path)
- table.insert(tasks, task)
- saveTaskList(path, tasks)
- end
- function addUserTask()
- print("Welches Item soll geholt werden?")
- local name = read()
- print("\n")
- print("Wie viele davon?")
- local count = read()
- count = tonumber(count)
- local task = {
- taskType = TASK_TYPES.getItems,
- itemName = "minecraft:" .. name,
- itemCount = count
- }
- local disk, path = getDiskByLabel(DISK_NAMES.user)
- local taskFilePath = fs.combine(path, TASK_FILE)
- addTaskToList(taskFilePath, task)
- end
- function addIncomingTask()
- print("Welches Item soll gelagert werden?")
- local name = read()
- print("\n")
- print("Wie viele davon?")
- local count = read()
- print("\n")
- count = tonumber(count)
- print("Wie groß ist ein Stack davon?")
- local size = read()
- print("\n")
- size = tonumber(size)
- local x1, y1, z1 = askForCoords("Position der Zielkiste eingeben (x y z):")
- local task = {
- taskType = TASK_TYPES.storeItems,
- itemName = "minecraft:" .. name,
- itemCount = count,
- stackSize = size,
- coord = {x = x1, y = y1, z = z1}
- }
- local disk, path = getDiskByLabel(DISK_NAMES.incoming)
- local taskFilePath = fs.combine(path, TASK_FILE)
- addTaskToList(taskFilePath, task)
- end
- while true do
- print()
- print("Items anfordern oder lagern?")
- print("[1] Item soll geholt werden")
- print("[2] Item soll gelagert werden")
- write("Auswahl (1 oder 2): ")
- local choice = read()
- if choice == "1" then
- addUserTask()
- elseif choice == "2" then
- addIncomingTask()
- else
- print("Ungültige Eingabe. Bitte erneut versuchen.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement