use of net.minecraft.client.renderer.texture.PngSizeInfo in project BuildCraft by BuildCraft.
the class SpriteFluidFrozen method load.
@Override
public boolean load(IResourceManager manager, ResourceLocation location, Function<ResourceLocation, TextureAtlasSprite> textureGetter) {
location = SpriteUtil.transformLocation(srcLocation);
TextureAtlasSprite src = Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(srcLocation.toString());
if (src == null) {
BCLog.logger.warn("[lib.fluid] Failed to create a frozen sprite of " + srcLocation.toString() + " as the source sprite wasn't able to be loaded!");
return true;
}
if (src.getFrameCount() <= 0) {
if (src.hasCustomLoader(manager, location)) {
src.load(manager, location, textureGetter);
} else {
try {
PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(manager.getResource(location));
try (IResource resource = manager.getResource(location)) {
src.loadSprite(pngsizeinfo, resource.getMetadata("animation") != null);
src.loadSpriteFrames(resource, Minecraft.getMinecraft().gameSettings.mipmapLevels + 1);
}
} catch (IOException io) {
io.printStackTrace();
}
}
}
if (src.getFrameCount() > 0) {
int widthOld = src.getIconWidth();
int heightOld = src.getIconHeight();
width = widthOld * 2;
height = heightOld * 2;
int[][] srcData = src.getFrameTextureData(0);
data = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
for (int m = 0; m < data.length; m++) {
data[m] = new int[width * height / (m + 1) / (m + 1)];
}
int[] relData = srcData[0];
if (relData.length < (width * height / 4)) {
Arrays.fill(data[0], 0xFF_FF_FF_00);
} else {
for (int x = 0; x < width; x++) {
int fx = (x % widthOld) * heightOld;
for (int y = 0; y < height; y++) {
int fy = y % heightOld;
data[0][x * height + y] = relData[fx + fy];
}
}
}
} else {
// Urm... idk
BCLog.logger.warn("[lib.fluid] Failed to create a frozen sprite of " + src.getIconName() + " as the source sprite didn't have any frames!");
return true;
}
return false;
}
use of net.minecraft.client.renderer.texture.PngSizeInfo in project BuildCraft by BuildCraft.
the class AtlasSpriteSwappable method loadSprite.
public static TextureAtlasSprite loadSprite(IResourceManager manager, String name, ResourceLocation location, boolean careIfMissing) {
// Load the initial variant
TextureAtlasSprite sprite = makeAtlasSprite(new ResourceLocation(name));
try {
// Copied almost directly from TextureMap.
PngSizeInfo pngsizeinfo = PngSizeInfo.makeFromResource(manager.getResource(location));
try (IResource iresource = manager.getResource(location)) {
boolean flag = iresource.getMetadata("animation") != null;
sprite.loadSprite(pngsizeinfo, flag);
sprite.loadSpriteFrames(iresource, Minecraft.getMinecraft().gameSettings.mipmapLevels + 1);
return sprite;
}
} catch (IOException io) {
if (careIfMissing) {
// Do the same as forge - track the missing texture for later rather than printing out the error.
FMLClientHandler.instance().trackMissingTexture(location);
}
return null;
}
}
use of net.minecraft.client.renderer.texture.PngSizeInfo 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);
}
Aggregations