use of net.minecraft.client.resources.IResource in project ForestryMC by ForestryMC.
the class ModelUtil method loadMultipartMBD.
private static ModelBlockDefinition loadMultipartMBD(ResourceLocation location, ResourceLocation fileIn) {
List<ModelBlockDefinition> list = Lists.newArrayList();
Minecraft mc = Minecraft.getMinecraft();
IResourceManager manager = mc.getResourceManager();
try {
for (IResource resource : manager.getAllResources(fileIn)) {
list.add(loadModelBlockDefinition(location, resource));
}
} catch (IOException e) {
throw new RuntimeException("Encountered an exception when loading model definition of model " + fileIn, e);
}
return new ModelBlockDefinition(list);
}
use of net.minecraft.client.resources.IResource in project ForestryMC by ForestryMC.
the class TextureMapForestry method loadTextureAtlas.
@Override
public void loadTextureAtlas(IResourceManager resourceManager) {
int i = Minecraft.getGLMaximumTextureSize();
Stitcher stitcher = new Stitcher(i, i, 0, 0);
this.mapUploadedSprites.clear();
this.listAnimatedSprites.clear();
ProgressManager.ProgressBar bar = ProgressManager.push("Texture stitching", this.mapRegisteredSprites.size());
for (Map.Entry<String, TextureAtlasSprite> entry : this.mapRegisteredSprites.entrySet()) {
TextureAtlasSprite textureatlassprite = entry.getValue();
ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite);
bar.step(resourcelocation.getResourcePath());
IResource iresource = null;
if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) {
if (textureatlassprite.load(resourceManager, resourcelocation, l -> mapRegisteredSprites.get(l.toString()))) {
continue;
}
} else
try {
PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(resourceManager.getResource(resourcelocation));
iresource = resourceManager.getResource(resourcelocation);
boolean flag = iresource.getMetadata("animation") != null;
textureatlassprite.loadSprite(pngsizeinfo, flag);
} catch (RuntimeException runtimeexception) {
FMLClientHandler.instance().trackBrokenTexture(resourcelocation, runtimeexception.getMessage());
continue;
} catch (IOException ioexception) {
FMLClientHandler.instance().trackMissingTexture(resourcelocation);
continue;
} finally {
IOUtils.closeQuietly(iresource);
}
stitcher.addSprite(textureatlassprite);
}
ProgressManager.pop(bar);
this.missingImage.generateMipmaps(0);
stitcher.addSprite(this.missingImage);
bar = ProgressManager.push("Texture creation", 2);
bar.step("Stitching");
stitcher.doStitch();
Log.info("Created: {}x{} {}-atlas", stitcher.getCurrentWidth(), stitcher.getCurrentHeight(), this.basePath);
bar.step("Allocating GL texture");
TextureUtil.allocateTextureImpl(this.getGlTextureId(), 0, stitcher.getCurrentWidth(), stitcher.getCurrentHeight());
Map<String, TextureAtlasSprite> map = Maps.newHashMap(this.mapRegisteredSprites);
ProgressManager.pop(bar);
bar = ProgressManager.push("Texture mipmap and upload", stitcher.getStichSlots().size());
for (TextureAtlasSprite textureatlassprite1 : stitcher.getStichSlots()) {
bar.step(textureatlassprite1.getIconName());
if (textureatlassprite1 == this.missingImage || this.generateMipmaps(resourceManager, textureatlassprite1)) {
String s = textureatlassprite1.getIconName();
map.remove(s);
this.mapUploadedSprites.put(s, textureatlassprite1);
try {
TextureUtil.uploadTextureMipmap(textureatlassprite1.getFrameTextureData(0), textureatlassprite1.getIconWidth(), textureatlassprite1.getIconHeight(), textureatlassprite1.getOriginX(), textureatlassprite1.getOriginY(), false, false);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Texture being stitched together");
crashreportcategory.addCrashSection("Atlas path", this.basePath);
crashreportcategory.addCrashSection("Sprite", textureatlassprite1);
throw new ReportedException(crashreport);
}
if (textureatlassprite1.hasAnimationMetadata()) {
this.listAnimatedSprites.add(textureatlassprite1);
}
}
}
for (TextureAtlasSprite textureatlassprite2 : map.values()) {
textureatlassprite2.copyFrom(this.missingImage);
}
ProgressManager.pop(bar);
}
use of net.minecraft.client.resources.IResource in project Binnie by ForestryMC.
the class StyleSheetParser method parseSheet.
@SideOnly(Side.CLIENT)
public static StyleSheet parseSheet(IResourceManager manager, ResourceLocation location) {
try {
IResource res = manager.getResource(location);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(res.getInputStream(), Charsets.UTF_8));
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(bufferedreader).getAsJsonObject();
Map<String, ParsedTextureSheet> textureSheets = parseTextureSheets(jsonObject);
Map<String, Texture> textures = parseTextures(jsonObject, textureSheets);
IOUtils.closeQuietly(bufferedreader);
return new StyleSheet(textures);
} catch (IOException e) {
throw new RuntimeException("Failed to load default stylesheet for Binnie's Mods.", e);
}
}
use of net.minecraft.client.resources.IResource in project ArsMagica2 by Mithion.
the class ArcaneCompendium method getPackagedCompendium.
private InputStream getPackagedCompendium(Language lang) {
ResourceLocation rLoc = new ResourceLocation("arsmagica2", String.format("docs/ArcaneCompendium_%s.xml", lang.getLanguageCode()));
IResource resource = null;
try {
resource = Minecraft.getMinecraft().getResourceManager().getResource(rLoc);
} catch (IOException e) {
} finally {
if (resource == null) {
LogHelper.info("Unable to find localized compendium. Defaulting to en_US");
rLoc = new ResourceLocation("arsmagica2", "docs/ArcaneCompendium_en_US.xml");
try {
resource = Minecraft.getMinecraft().getResourceManager().getResource(rLoc);
} catch (IOException e) {
}
}
}
if (resource != null)
return resource.getInputStream();
throw new MissingResourceException("No packaged version of the compendium was found. You may have a corrupted download.", "compendium", "Arcane Compendium");
}
use of net.minecraft.client.resources.IResource in project ImmersiveEngineering by BluSunrize.
the class TileRenderAutoWorkbench method getBlueprintDrawable.
public static BlueprintLines getBlueprintDrawable(ItemStack stack, World world) {
if (stack.isEmpty())
return null;
EntityPlayer player = ClientUtils.mc().player;
ArrayList<BufferedImage> images = new ArrayList<>();
try {
IBakedModel ibakedmodel = ClientUtils.mc().getRenderItem().getItemModelWithOverrides(stack, world, player);
if (ibakedmodel == null || ibakedmodel.isGui3d())
return new BlueprintLinesEmpty();
HashSet<String> textures = new HashSet();
Collection<BakedQuad> quads = ibakedmodel.getQuads(null, null, 0);
for (BakedQuad quad : quads) if (quad != null && quad.getSprite() != null)
textures.add(quad.getSprite().getIconName());
for (String s : textures) {
ResourceLocation rl = new ResourceLocation(s);
rl = new ResourceLocation(rl.getNamespace(), String.format("%s/%s%s", "textures", rl.getPath(), ".png"));
IResource resource = ClientUtils.mc().getResourceManager().getResource(rl);
BufferedImage bufferedImage = TextureUtil.readBufferedImage(resource.getInputStream());
if (bufferedImage != null)
images.add(bufferedImage);
}
} catch (Exception e) {
e.printStackTrace();
}
if (images.isEmpty())
return null;
ArrayList<Pair<TexturePoint, TexturePoint>> lines = new ArrayList();
HashSet testSet = new HashSet();
HashMultimap<Integer, TexturePoint> area = HashMultimap.create();
int wMax = 0;
for (BufferedImage bufferedImage : images) {
Set<Pair<TexturePoint, TexturePoint>> temp_lines = new HashSet<>();
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
if (h > w)
h = w;
if (w > wMax)
wMax = w;
for (int hh = 0; hh < h; hh++) for (int ww = 0; ww < w; ww++) {
int argb = bufferedImage.getRGB(ww, hh);
float r = (argb >> 16 & 255) / 255f;
float g = (argb >> 8 & 255) / 255f;
float b = (argb & 255) / 255f;
float intesity = (r + b + g) / 3f;
int alpha = (argb >> 24) & 255;
if (alpha > 0) {
boolean added = false;
// Check colour sets for similar colour to shade it later
TexturePoint tp = new TexturePoint(ww, hh, w);
if (!testSet.contains(tp)) {
for (Integer key : area.keySet()) {
for (TexturePoint p : area.get(key)) {
float mod = w / (float) p.scale;
int pColour = bufferedImage.getRGB((int) (p.x * mod), (int) (p.y * mod));
float dR = (r - (pColour >> 16 & 255) / 255f);
float dG = (g - (pColour >> 8 & 255) / 255f);
float dB = (b - (pColour & 255) / 255f);
double delta = Math.sqrt(dR * dR + dG * dG + dB * dB);
if (delta < .25) {
area.put(key, tp);
added = true;
break;
}
}
if (added)
break;
}
if (!added)
area.put(argb, tp);
testSet.add(tp);
}
// Compare to direct neighbour
for (int i = 0; i < 4; i++) {
int xx = (i == 0 ? -1 : i == 1 ? 1 : 0);
int yy = (i == 2 ? -1 : i == 3 ? 1 : 0);
int u = ww + xx;
int v = hh + yy;
int neighbour = 0;
float delta = 1;
boolean notTransparent = false;
if (u >= 0 && u < w && v >= 0 && v < h) {
neighbour = bufferedImage.getRGB(u, v);
notTransparent = ((neighbour >> 24) & 255) > 0;
if (notTransparent) {
float neighbourIntesity = ((neighbour >> 16 & 255) + (neighbour >> 8 & 255) + (neighbour & 255)) / 765f;
float intesityDelta = Math.max(0, Math.min(1, Math.abs(intesity - neighbourIntesity)));
float rDelta = Math.max(0, Math.min(1, Math.abs(r - (neighbour >> 16 & 255) / 255f)));
float gDelta = Math.max(0, Math.min(1, Math.abs(g - (neighbour >> 8 & 255) / 255f)));
float bDelta = Math.max(0, Math.min(1, Math.abs(b - (neighbour & 255) / 255f)));
delta = Math.max(intesityDelta, Math.max(rDelta, Math.max(gDelta, bDelta)));
delta = delta < .25 ? 0 : delta > .4 ? 1 : delta;
}
}
if (delta > 0) {
Pair<TexturePoint, TexturePoint> l = Pair.of(new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 0), hh + (i == 2 ? 0 : i == 3 ? 1 : 0), w), new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 1), hh + (i == 2 ? 0 : i == 3 ? 1 : 1), w));
temp_lines.add(l);
}
}
}
}
lines.addAll(temp_lines);
}
ArrayList<Integer> lumiSort = new ArrayList<>(area.keySet());
Collections.sort(lumiSort, (rgb1, rgb2) -> Double.compare(getLuminance(rgb1), getLuminance(rgb2)));
HashMultimap<ShadeStyle, Point> complete_areaMap = HashMultimap.create();
int lineNumber = 2;
int lineStyle = 0;
for (Integer i : lumiSort) {
complete_areaMap.putAll(new ShadeStyle(lineNumber, lineStyle), area.get(i));
++lineStyle;
lineStyle %= 3;
if (lineStyle == 0)
lineNumber += 1;
}
Set<Pair<Point, Point>> complete_lines = new HashSet<>();
for (Pair<TexturePoint, TexturePoint> line : lines) {
TexturePoint p1 = line.getKey();
TexturePoint p2 = line.getValue();
complete_lines.add(Pair.of(new Point((int) (p1.x / (float) p1.scale * wMax), (int) (p1.y / (float) p1.scale * wMax)), new Point((int) (p2.x / (float) p2.scale * wMax), (int) (p2.y / (float) p2.scale * wMax))));
}
return new BlueprintLines(wMax, complete_lines, complete_areaMap);
}
Aggregations