tterrag1098

Untitled

Oct 4th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. public class DelegatingResourcePack extends ResourcePack
  2. {
  3. private final List<DelegatableResourcePack> delegates = new ArrayList<>();
  4.  
  5. public DelegatingResourcePack(String name, File resourcePackFileIn)
  6. {
  7. super(new File(name));
  8. }
  9.  
  10. public void addDelegate(DelegatableResourcePack pack)
  11. {
  12. synchronized(delegates)
  13. {
  14. this.delegates.add(pack);
  15. }
  16. }
  17.  
  18. @Override
  19. public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType type, String pathIn, int maxDepth, Predicate<String> filter)
  20. {
  21. synchronized(delegates)
  22. {
  23. return delegates.stream()
  24. .flatMap(r -> r.getAllResourceLocations(type, pathIn, maxDepth, filter).stream())
  25. .collect(Collectors.toList());
  26. }
  27. }
  28.  
  29. @Override
  30. public Set<String> getResourceNamespaces(ResourcePackType type)
  31. {
  32. synchronized (delegates)
  33. {
  34. return delegates.stream()
  35. .flatMap(r -> r.getResourceNamespaces(type).stream())
  36. .collect(Collectors.toSet());
  37. }
  38. }
  39.  
  40. @Override
  41. public void close() throws IOException
  42. {
  43. synchronized(delegates)
  44. {
  45. for (ResourcePack pack : delegates)
  46. {
  47. pack.close();
  48. }
  49. }
  50. }
  51.  
  52. @Override
  53. protected InputStream getInputStream(String resourcePath) throws IOException
  54. {
  55. synchronized (delegates)
  56. {
  57. for (DelegatableResourcePack pack : delegates)
  58. {
  59. try
  60. {
  61. return pack.getInputStream(resourcePath);
  62. }
  63. catch (ResourcePackFileNotFoundException e) {}
  64. }
  65. }
  66. throw new ResourcePackFileNotFoundException(this.file, resourcePath);
  67. }
  68.  
  69. @Override
  70. protected boolean resourceExists(String resourcePath)
  71. {
  72. synchronized (delegates)
  73. {
  74. for (DelegatableResourcePack pack : delegates)
  75. {
  76. if (pack.resourceExists(resourcePath))
  77. {
  78. return true;
  79. }
  80. }
  81. }
  82. return false;
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment