use of net.minecraft.client.resources.IResource in project MinecraftForge by MinecraftForge.
the class AnimationStateMachine method load.
/**
* Load a new instance if AnimationStateMachine at specified location, with specified custom parameters.
*/
@SideOnly(Side.CLIENT)
public static IAnimationStateMachine load(IResourceManager manager, ResourceLocation location, ImmutableMap<String, ITimeValue> customParameters) {
try {
ClipResolver clipResolver = new ClipResolver();
ParameterResolver parameterResolver = new ParameterResolver(customParameters);
Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(clipResolver);
TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(parameterResolver);
IResource resource = manager.getResource(location);
AnimationStateMachine asm = asmGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), AnimationStateMachine.class);
clipResolver.asm = asm;
parameterResolver.asm = asm;
asm.initialize();
//System.out.println(location + ": " + json);
return asm;
} catch (IOException e) {
FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
return missing;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "Exception loading Animation State Machine %s, skipping", location);
return missing;
} finally {
Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(null);
TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(null);
}
}
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) {
// Remove the index from the resource path so we can find the original texture.
location = new ResourceLocation(location.getResourceDomain(), location.getResourcePath().replace("_" + index, ""));
BufferedImage image;
IResource resource = null;
try {
resource = manager.getResource(location);
image = ImageIO.read(resource.getInputStream());
} catch (IOException ex) {
Game.log(Level.WARN, "Failed to load sub-texture from {0}: {1}", location.getResourcePath(), ex.getLocalizedMessage());
return true;
} finally {
if (resource != null)
try {
resource.getInputStream().close();
} catch (IOException ignored) {
}
}
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(Level.WARN, "Failed to load sub-texture from {0} - {1}x{2}: {3}", location.getResourcePath(), 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);
return false;
}
use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.
the class SplashTextHandler method addTexts.
public void addTexts(List<String> splashes, ResourceLocation loc) {
IResource resource = null;
try {
resource = Minecraft.getMinecraft().getResourceManager().getResource(loc);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(resource.getInputStream(), Charsets.UTF_8));
String s;
while ((s = bufferedreader.readLine()) != null) {
if (s.length() == 0 || s.charAt(0) == '#')
continue;
s = s.trim();
if (!s.isEmpty()) {
splashes.add(s);
}
}
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(resource);
}
}
use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.
the class CommandImg method call.
@Override
public void call(ITypesetter out, ITokenizer tokenizer) throws TruthError {
String imgName = tokenizer.getParameter("domain:path/to/image.png");
String scaleOrWidth = tokenizer.getOptionalParameter();
String heightS = tokenizer.getOptionalParameter();
ResourceLocation rl = new ResourceLocation(imgName);
try {
Minecraft mc = Minecraft.getMinecraft();
IResource r = mc.getResourceManager().getResource(rl);
if (r == null) {
throw new TruthError("Not found: " + imgName);
}
} catch (Throwable e) {
e.printStackTrace();
throw new TruthError(e.getMessage());
}
WordImage img;
if (heightS != null) {
int width = Integer.parseInt(scaleOrWidth);
int height = Integer.parseInt(heightS);
img = new WordImage(rl, width, height);
} else {
img = new WordImage(rl);
if (scaleOrWidth != null) {
img.scale(Double.parseDouble(scaleOrWidth));
}
}
if (out.hasFixedWidth()) {
img.fitToPage(out.getWidth(), Integer.MAX_VALUE);
}
out.write(img);
}
use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.
the class WordImage method autosize.
private void autosize() {
Pair<Integer, Integer> cached = size_cache.get(resource);
if (cached != null) {
width = cached.getLeft();
height = cached.getRight();
return;
}
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
try {
IResource iresource = resourceManager.getResource(resource);
BufferedImage bufferedimage = TextureUtil.readBufferedImage(iresource.getInputStream());
this.width = bufferedimage.getWidth();
this.height = bufferedimage.getHeight();
size_cache.put(resource, Pair.of(width, height));
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations