Advertisement
Blackhome

test Task Creator

Jun 5th, 2025 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1.  
  2. local DISK_NAMES = {
  3.     incoming = "Incoming Task",
  4.     user = "User Task",
  5.     outgoing = "Outgoing Task",
  6.     finished = "Finished Task",
  7.     settings = "Settings",
  8.     storage = "Data Storage",
  9.     init = "Turtle Initializing"
  10. }
  11.  
  12. local TASK_TYPES = {
  13.     createChests = "create_chests",
  14.     storeItems = "store_items",
  15.     getItems = "get_items",
  16.     checkInventory = "check_inventory",
  17.     initializeChests = "initialize_chests"
  18. }
  19.  
  20. local TASK_FILE = "task_list.txt"
  21.  
  22. function getDiskByLabel(label)
  23.     for _, side in ipairs(peripheral.getNames()) do
  24.         if peripheral.getType(side) == "drive" then
  25.             local disk = peripheral.wrap(side)
  26.             if disk.getDiskLabel() == label then
  27.                 return disk, disk.getMountPath()
  28.             end
  29.         end
  30.     end
  31.     return nil, nil
  32. end
  33.  
  34. function askForCoords(promptText)
  35.     while true do
  36.         print(promptText)
  37.         local input = read()
  38.         local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
  39.         if x and y and z then
  40.             return tonumber(x), tonumber(y), tonumber(z)
  41.         else
  42.             print("Ungültiges Format. Bitte erneut eingeben als: x y z")
  43.         end
  44.     end
  45. end
  46.  
  47. function getTaskList(path)
  48.     if not fs.exists(path) then return {} end
  49.     local file = fs.open(path, "r")
  50.     local data = textutils.unserialize(file.readAll())
  51.     file.close()
  52.     return data or {}
  53. end
  54.  
  55. function saveTaskList(path, taskList)
  56.     local file = fs.open(path, "w")
  57.     file.write(textutils.serialize(taskList))
  58.     file.close()
  59. end
  60.  
  61. function addTaskToList(path, task)
  62.     local tasks = getTaskList(path)
  63.     table.insert(tasks, task)
  64.     saveTaskList(path, tasks)
  65. end
  66.  
  67.  
  68. function addUserTask()
  69.     print("Welches Item soll geholt werden?")
  70.     local name = read()
  71.     print("\n")
  72.     print("Wie viele davon?")
  73.     local count = read()
  74.     count = tonumber(count)
  75.    
  76.     local task = {
  77.         taskType = TASK_TYPES.getItems,
  78.         itemName = "minecraft:" .. name,
  79.         itemCount = count
  80.     }
  81.  
  82.     local disk, path = getDiskByLabel(DISK_NAMES.user)
  83.     local taskFilePath = fs.combine(path, TASK_FILE)
  84.  
  85.     addTaskToList(taskFilePath, task)
  86. end
  87.  
  88. function addIncomingTask()
  89.     print("Welches Item soll gelagert werden?")
  90.     local name = read()
  91.     print("\n")
  92.     print("Wie viele davon?")
  93.     local count = read()
  94.     print("\n")
  95.     count = tonumber(count)
  96.     print("Wie groß ist ein Stack davon?")
  97.     local size = read()
  98.     print("\n")
  99.     size = tonumber(size)
  100.  
  101.     local x1, y1, z1 = askForCoords("Position der Zielkiste eingeben (x y z):")
  102.  
  103.     local task = {
  104.         taskType = TASK_TYPES.storeItems,
  105.         itemName = "minecraft:" .. name,
  106.         itemCount = count,
  107.         stackSize = size,
  108.         coord = {x = x1, y = y1, z = z1}
  109.     }
  110.  
  111.     local disk, path = getDiskByLabel(DISK_NAMES.incoming)
  112.     local taskFilePath = fs.combine(path, TASK_FILE)
  113.  
  114.     addTaskToList(taskFilePath, task)
  115. end
  116.  
  117. while true do
  118.     print()
  119.     print("Items anfordern oder lagern?")
  120.     print("[1] Item soll geholt werden")
  121.     print("[2] Item soll gelagert werden")
  122.     write("Auswahl (1 oder 2): ")
  123.     local choice = read()
  124.  
  125.     if choice == "1" then
  126.         addUserTask()
  127.     elseif choice == "2" then
  128.         addIncomingTask()
  129.     else
  130.         print("Ungültige Eingabe. Bitte erneut versuchen.")
  131.     end
  132.  
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement