use of net.minecraft.client.resources.IResource in project MorePlanets by SteveKunG.
the class OBJLoaderMP method loadModel.
@Override
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
IModel model = null;
if (this.cache.containsKey(modelLocation)) {
model = this.cache.get(modelLocation);
} else {
try {
ResourceLocation file = new ResourceLocation(modelLocation.getNamespace(), "models/obj/" + modelLocation.getPath());
IResource resource = this.manager.getResource(file);
if (resource != null) {
OBJModel.Parser parser = new OBJModel.Parser(resource, this.manager);
try {
model = parser.parse().process(ImmutableMap.of("flip-v", "true"));
} finally {
resource.getInputStream().close();
this.cache.put(modelLocation, model);
}
}
} catch (IOException e) {
throw e;
}
}
if (model == null) {
return ModelLoaderRegistry.getMissingModel();
}
return model;
}
use of net.minecraft.client.resources.IResource in project MinecraftForge by MinecraftForge.
the class ModelBlockAnimation method loadVanillaAnimation.
/**
* Load armature associated with a vanilla model.
*/
public static ModelBlockAnimation loadVanillaAnimation(IResourceManager manager, ResourceLocation armatureLocation) {
try {
IResource resource = null;
try {
resource = manager.getResource(armatureLocation);
} catch (FileNotFoundException e) {
// this is normal. FIXME: error reporting?
return defaultModelBlockAnimation;
}
ModelBlockAnimation mba = mbaGson.fromJson(new InputStreamReader(resource.getInputStream(), "UTF-8"), ModelBlockAnimation.class);
//String json = mbaGson.toJson(mba);
return mba;
} catch (IOException e) {
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
return defaultModelBlockAnimation;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "Exception loading vanilla model animation %s, skipping", armatureLocation);
return defaultModelBlockAnimation;
}
}
use of net.minecraft.client.resources.IResource in project GregTech by GregTechCE.
the class MetaTileEntityRenderer method postInit.
public static void postInit() {
try {
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("models/block/block.json"));
try (InputStreamReader reader = new InputStreamReader(resource.getInputStream())) {
ModelBlock modelBlock = ModelBlock.deserialize(reader);
for (TransformType transformType : TransformType.values()) {
ItemTransformVec3f vec3f = modelBlock.getAllTransforms().getTransform(transformType);
BLOCK_TRANSFORMS.put(transformType, new TRSRTransformation(vec3f));
}
}
} catch (IOException exception) {
GTLog.logger.error("Failed to load default block transforms", exception);
}
}
use of net.minecraft.client.resources.IResource in project Charset by CharsetMC.
the class ColorPaletteParser method onTextureStitchPre.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTextureStitchPre(TextureStitchEvent.Pre event) {
this.data = null;
try {
for (IResource resource : Minecraft.getMinecraft().getResourceManager().getAllResources(COLOR_PALETTE_LOC)) {
Data data = gson.fromJson(new InputStreamReader(resource.getInputStream()), Data.class);
if (data.version != 1) {
ModCharset.logger.warn("Unsupported version of color_palette.json found in " + resource.getResourcePackName() + " - not loaded.");
continue;
}
if (this.data == null) {
this.data = data;
} else {
this.data.add(data);
}
}
} catch (IOException e) {
e.printStackTrace();
}
MinecraftForge.EVENT_BUS.post(new ColorPaletteUpdateEvent(this));
}
use of net.minecraft.client.resources.IResource in project BuildCraft by BuildCraft.
the class ResourceLoaderContext method startLoading.
public InputStreamReader startLoading(ResourceLocation location) throws IOException {
if (!loaded.add(location)) {
throw new JsonSyntaxException("Already loaded " + location + " from " + loadingStack.peek());
}
loadingStack.push(location);
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(location);
return new InputStreamReader(res.getInputStream(), StandardCharsets.UTF_8);
}
Aggregations