Advertisement
Guest User

PeripheralMan

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1.  
  2. function Select(peripheralType)
  3.  
  4.   local peripherals = peripheral.getNames();
  5.   local selectedPeripherals = {};
  6.  
  7.   for _, device in pairs(peripherals) do
  8.    
  9.     if peripheral.getType(device) == peripheralType then
  10.      
  11.       selectedPeripherals[device] = peripheral.wrap(device);
  12.      
  13.     end
  14.    
  15.   end
  16.  
  17.   return selectedPeripherals;
  18.  
  19. end
  20.  
  21. function SelectTanksByContents(contentType)
  22.  
  23.   local filteredTanks = {};
  24.   for k, v in pairs(Select("thermalexpansion_tank")) do
  25.     if GetTankInfo(v).Contents.Name == contentType then
  26.       table.insert(filteredTanks, v);
  27.     end
  28.   end
  29.  
  30.   return filteredTanks;
  31.  
  32. end
  33.  
  34. function GetAllTankContentTypes()
  35.  
  36.   local contentTypes = {};
  37.   local tanks = Select("thermalexpansion_tank");
  38.   for k,v in pairs(tanks) do
  39.     local contentType = GetTankInfo(v).Contents.Name
  40.    
  41.     if contentTypes[contentType] == nil then
  42.       contentTypes[contentType] = contentType;
  43.     end
  44.   end
  45.  
  46.   return contentTypes;
  47.  
  48. end
  49.  
  50. function PrintMethods(deviceName, wrappedDevice)
  51.  
  52.   local methods = peripheral.getMethods(deviceName);
  53.  
  54.   for k, v in pairs(methods) do
  55.     textutils.pagedPrint(k);
  56.   end
  57.  
  58.   if wrappedDevice ~= nil then
  59.     textutils.pagedPrint(wrappedDevice.listMethods());
  60.   end
  61.  
  62. end
  63.  
  64. function GetTankInfo(tank)
  65.  
  66.   local tankInfo = tank.getTankInfo()[1];
  67.   local properTankInfo = {};
  68.   properTankInfo.Capacity = tankInfo.capacity;
  69.   properTankInfo.Contents = {
  70.     Name = tankInfo.contents.rawName,
  71.     Amount = tankInfo.contents.amount
  72.   };
  73.  
  74.   return properTankInfo;
  75.  
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement