Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DelegatingResourcePack extends ResourcePack
- {
- private final List<DelegatableResourcePack> delegates = new ArrayList<>();
- public DelegatingResourcePack(String name, File resourcePackFileIn)
- {
- super(new File(name));
- }
- public void addDelegate(DelegatableResourcePack pack)
- {
- synchronized(delegates)
- {
- this.delegates.add(pack);
- }
- }
- @Override
- public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType type, String pathIn, int maxDepth, Predicate<String> filter)
- {
- synchronized(delegates)
- {
- return delegates.stream()
- .flatMap(r -> r.getAllResourceLocations(type, pathIn, maxDepth, filter).stream())
- .collect(Collectors.toList());
- }
- }
- @Override
- public Set<String> getResourceNamespaces(ResourcePackType type)
- {
- synchronized (delegates)
- {
- return delegates.stream()
- .flatMap(r -> r.getResourceNamespaces(type).stream())
- .collect(Collectors.toSet());
- }
- }
- @Override
- public void close() throws IOException
- {
- synchronized(delegates)
- {
- for (ResourcePack pack : delegates)
- {
- pack.close();
- }
- }
- }
- @Override
- protected InputStream getInputStream(String resourcePath) throws IOException
- {
- synchronized (delegates)
- {
- for (DelegatableResourcePack pack : delegates)
- {
- try
- {
- return pack.getInputStream(resourcePath);
- }
- catch (ResourcePackFileNotFoundException e) {}
- }
- }
- throw new ResourcePackFileNotFoundException(this.file, resourcePath);
- }
- @Override
- protected boolean resourceExists(String resourcePath)
- {
- synchronized (delegates)
- {
- for (DelegatableResourcePack pack : delegates)
- {
- if (pack.resourceExists(resourcePath))
- {
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment