net.minecraft.resource.Resource Java Examples

The following examples show how to use net.minecraft.resource.Resource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NinePatch.java    From LibGui with MIT License 6 votes vote down vote up
@Override
protected Map<Identifier, Properties> prepare(ResourceManager manager, Profiler profiler) {
	Collection<Identifier> ids = manager.findResources("textures", s -> s.endsWith(SUFFIX));
	Map<Identifier, Properties> result = new HashMap<>();

	for (Identifier input : ids) {
		try (Resource resource = manager.getResource(input);
			 InputStream stream = resource.getInputStream()) {
			Properties props = new Properties();
			props.load(stream);
			Identifier textureId = new Identifier(input.getNamespace(), input.getPath().substring(0, input.getPath().length() - SUFFIX.length()));
			result.put(textureId, props);
		} catch (Exception e) {
			LibGuiClient.logger.error("Error while loading metadata file {}, skipping...", input, e);
		}
	}

	return result;
}
 
Example #2
Source File: NpcClothingFeature.java    From MineLittlePony with MIT License 5 votes vote down vote up
private <K> VillagerResourceMetadata.HatType loadHatType(Map<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) {
    return cache.computeIfAbsent(key, k -> {
        try (Resource res = resourceManager.getResource(findTexture(type, registry.getId(k)))) {
            VillagerResourceMetadata meta = res.getMetadata(VillagerResourceMetadata.READER);
            if (meta != null) {
                return meta.getHatType();
            }
        } catch (IOException e) { }
        return HatType.NONE;
    });
}
 
Example #3
Source File: ExistingFileHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@VisibleForTesting
public Resource getResource(Identifier identifier, ResourceType type, String pathSuffix, String pathPrefix) throws IOException {
	return getManager(type).getResource(getLocation(identifier, pathSuffix, pathPrefix));
}