Hastwell

CC EnderTank Scanner

Oct 10th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. starttime = os.clock()
  2.  
  3. local periList = peripheral.getNames()
  4. local enderTank = nil
  5. local enderChest = nil
  6. for i = 1, #periList do
  7.     if peripheral.getType(periList[i]) == "ender_tank" and enderTank == nil then
  8.         enderTank = peripheral.wrap(periList[i])
  9.         print("EnderTank mounted as "..periList[i])
  10.     elseif peripheral.getType(periList[i]) == "ender_chest" and enderChest == nil then
  11.         enderChest = peripheral.wrap(periList[i])
  12.         print("EnderChest mounted as "..periList[i])
  13.     end
  14. end
  15.  
  16. local colorindex = {
  17.   colors.white,
  18.   colors.orange,
  19.   colors.magenta,
  20.   colors.lightBlue,
  21.   colors.yellow,
  22.   colors.lime,
  23.   colors.pink,
  24.   colors.gray,
  25.   colors.lightGray,
  26.   colors.cyan,
  27.   colors.purple,
  28.   colors.blue,
  29.   colors.brown,
  30.   colors.green,
  31.   colors.red,
  32.   colors.black
  33. }
  34. local colornames = {
  35. "White",
  36. "Orange",
  37. "Magenta",
  38. "LightBlue",
  39. "Yellow",
  40. "Lime",
  41. "Pink",
  42. "Gray",
  43. "GightGray",
  44. "Cyan",
  45. "Purple",
  46. "Blue",
  47. "Brown",
  48. "Green",
  49. "Red",
  50. "Black"}
  51.  
  52. print("Ready to scan")
  53.  
  54. local function setTank(c1,c2,c3)
  55.     -- for some reason, ender tanks set thir colors backwards
  56.     if enderTank ~= nil then enderTank.setColors(c3,c2,c1) end
  57. end
  58. local function setChest(c1,c2,c3)
  59.     if enderChest ~= nil then enderChest.setColors(c1,c2,c3) end
  60. end
  61. local function tankInfo()
  62.     -- available keys are rawName (localized name), amount (mB), capacity (mB), name (internal name), id (liquid id)
  63.     return enderTank.getTankInfo('')[1]
  64. end
  65.  
  66. -- available keys for chest.getStackInSlot(n) are:
  67. -- |- name (Sign)
  68. -- |- rawName (item.sign)
  69. -- |- id
  70. -- |- dmg (0)
  71. -- |- maxSize (16 - max size of stack)
  72. -- |- ench(table)
  73. --      Empty for sign
  74. --      "Efficiency V"
  75. -- |- qty
  76.  
  77. local function niceColorName(a,b,c)
  78.     return colornames[a]..' '..colornames[b]..' '..colornames[c]
  79. end
  80.  
  81. f = fs.open('_tanks','w')
  82. numcols = 16
  83. for a = 1, 1 do
  84.     for b = 1, 1 do
  85.         for c = 1, numcols do
  86.             setTank(colorindex[a], colorindex[b], colorindex[c])
  87.             setChest(colorindex[a], colorindex[b], colorindex[c])
  88.            
  89.             tankData = tankInfo()
  90.             if tankData.rawName ~= nil then
  91.                 entry = "Tank "..niceColorName(a,b,c).." contains "..tankData.amount.." mB of "..tankData.rawName
  92.                 print(entry)
  93.                 f.writeLine(entry)
  94.             end
  95.            
  96.             chestHasAnything = false
  97.             for invitr = 1, enderChest.getInventorySize() do
  98.                 inv = enderChest.getStackInSlot(invitr)
  99.                 if inv ~= nil then
  100.                     if not chestHasAnything then
  101.                         entry = "Chest "..niceColorName(a,b,c).." contains:"
  102.                         print(entry)
  103.                         f.writeLine(entry)
  104.                         -- don't print this message again
  105.                         chestHasAnything = true
  106.                     end
  107.                    
  108.                     entry = "x"..inv.qty.." "..inv.name.."("..inv.id..":"..inv.dmg..")"
  109.                     print(entry)
  110.                     f.writeLine(entry)
  111.                    
  112.                     for k,v in pairs(inv.ench) do
  113.                         entry = "|- "..v
  114.                         print(entry)
  115.                         f.writeLine(entry)
  116.                     end
  117.                    
  118.                 end
  119.             end
  120.         end
  121.     end
  122. end
  123. f.close()
  124. print(string.format("elapsed time: %.2f\n", os.clock() - starttime))
Advertisement
Add Comment
Please, Sign In to add comment