use of net.minecraft.client.resources.IResource in project Railcraft by Railcraft.
the class TextureAtlasSheet method load.
@Override
public boolean load(IResourceManager manager, ResourceLocation location, Function<ResourceLocation, TextureAtlasSprite> resourceGetter) {
// Remove the index from the resource path so we can find the original texture.
ResourceLocation fullLocation = new ResourceLocation(location.getNamespace(), location.getPath().replace("_" + index, ""));
BufferedImage image;
try (IResource resource = manager.getResource(fullLocation)) {
image = ImageIO.read(resource.getInputStream());
} catch (IOException ex) {
Game.log().msg(Level.WARN, "Failed to load sub-texture from {0}: {1}", fullLocation.getPath(), ex.getLocalizedMessage());
return true;
}
int mipmapLevels = Minecraft.getMinecraft().gameSettings.mipmapLevels;
int size = image.getHeight() / rows;
int x = index % columns;
int y = index / columns;
BufferedImage subImage;
try {
subImage = image.getSubimage(x * size, y * size, size, size);
} catch (RasterFormatException ex) {
Game.log().msg(Level.WARN, "Failed to load sub-texture from {0} - {1}x{2}: {3}", fullLocation.getPath(), image.getWidth(), image.getHeight(), ex.getLocalizedMessage());
return true;
}
this.height = subImage.getHeight();
this.width = subImage.getWidth();
int[] rgbaData = new int[height * width];
subImage.getRGB(0, 0, width, height, rgbaData, 0, width);
int[][] imageData = new int[1 + mipmapLevels][];
imageData[0] = rgbaData;
framesTextureData.add(imageData);
// Hack to use sheet textures for advancement backgrounds
Game.log("models").msg(Level.INFO, "registering custom textures {0}", location);
Minecraft.getMinecraft().getTextureManager().loadTexture(location, new Texture(subImage));
return false;
}
use of net.minecraft.client.resources.IResource in project TechReborn by TechReborn.
the class ModelHelper method getReaderForResource.
public static Reader getReaderForResource(ResourceLocation location) throws IOException {
ResourceLocation file = new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + ".json");
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(file);
return new BufferedReader(new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8));
}
use of net.minecraft.client.resources.IResource in project Galacticraft by micdoodle8.
the class OBJLoaderGC method loadModel.
@Override
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
IModel model = null;
if (cache.containsKey(modelLocation)) {
model = cache.get(modelLocation);
} else {
try {
String prefix = modelLocation.getResourcePath().contains("models/") ? "" : "models/";
ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), prefix + modelLocation.getResourcePath());
IResource resource = manager.getResource(file);
if (resource != null) {
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
try {
model = parser.parse().process(ImmutableMap.of("flip-v", "true"));
} finally {
resource.getInputStream().close();
cache.put(modelLocation, model);
}
}
} catch (IOException e) {
throw e;
}
}
if (model == null)
return ModelLoaderRegistry.getMissingModel();
return model;
}
Aggregations