nanakisan

Untitled

Oct 6th, 2020
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Declare variables
  2. -- The chest needs to be to the right of the computer
  3. local enderChest = peripheral.wrap("right")
  4. -- The chest needs to be on top of the computer
  5. local enderTank = peripheral.wrap("top")
  6. local chest = getChestFromPin(n)
  7. local tank = getChestFromPin(n)
  8. local colors = {"white", "red", "blue", "yellow", "green", "black", "cyan", "magenta", "pink", "orange", "lightblue", "lime", "gray", "lightgray", "purple", "brown"}
  9.  
  10. -- The % sign is called a modulo operator
  11. function getChestFromPin(n)
  12.     local third = n % 16
  13.     n = n / 16
  14.     n = math.floor(n);
  15.     local second = n % 16
  16.     n = n / 16
  17.     n = math.floor(n);
  18.     local first = n % 16
  19.     return {colors[(first + 1)], colors[(second + 1)], colors[(third + 1)]}
  20. end
  21.  
  22. -- This functions prints on the screen which chest color combos have items in them
  23. function addPinToList(n, id)
  24.     if id == "chest" then
  25.  
  26.         print("Items found in ["..chest[1]..", "..chest[2]..", "..chest[3].."]")
  27.     elseif id == "tank" then
  28.         local contents = enderTank.getTankInfo("")
  29.         print(contents[1].name.." found in ["..tank[1]..", "..tank[2]..", "..tank[3].."]")
  30.         contents = nil
  31.     end
  32.     return "Added pin to list"
  33. end
  34.  
  35. -- Checks for existence of contents in ender tank
  36. function tank()
  37.     -- 4096 is the number of possible color combinations (16x16x16)
  38.     for pin = 1, 4096, 1 do
  39.         -- Call function based on current iteration's color combination
  40.         local chest = getChestFromPin(pin)
  41.     enderTank.setColorNames(chest[1], chest[2], chest[3])
  42.         -- Checks for presence of any existing items in the chest of the current color combination
  43.         local contents = enderTank.getTankInfo("")
  44.         if contents[1].name ~= nil then
  45.             addPinToList(pin, "tank")
  46.         end
  47.     end
  48.     -- Print message once all iterations are complete
  49.     print("Enter 'exit' to return to main menu.")
  50.     input = read()
  51.     if input == "exit" then
  52.         main()
  53.     end
  54.     return "Scanned tank."
  55. end
  56.  
  57. -- Checks for existence of contents in ender chest
  58. function chest()
  59.     -- 4096 is the number of possible color combinations (16x16x16)
  60.     for pin = 1, 4096, 1 do
  61.         -- Call function based on current iteration's color combination
  62.         local chest = getChestFromPin(pin)
  63.     enderChest.setColorNames(chest[1], chest[2], chest[3])
  64.         -- Checks for presence of any existing items in the chest of the current color combination
  65.         local contents = enderChest.getAllStacks()
  66.         if contents[1] ~= nil then
  67.             addPinToList(pin, "chest")
  68.         end
  69.     end
  70.     -- Print message once all iterations are complete
  71.     print("Enter 'exit' to return to main menu.")
  72.     input = read()
  73.     if input == "exit" then
  74.         main()
  75.     end
  76.     return "Scanned chest."
  77. end
  78.  
  79. -- Welcome message, tells user how to use the program and accept's user's prompt
  80. function main()
  81.     term.clear()
  82.     term.setCursorPos(1, 1)
  83.  
  84.     print("Enter 'chest' (right) or 'tank' (top) to begin.")
  85.  
  86.     input = read()
  87.  
  88.     if input == "chest" then
  89.         chest()
  90.     elseif input == "tank" then
  91.         tank()
  92.     end
  93. end
  94.  
  95. main()
Advertisement
Add Comment
Please, Sign In to add comment