use of net.minecraft.client.resources.IResource 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.resources.IResource 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.resources.IResource in project BuildCraft by BuildCraft.
the class MetadataLoader method getData.
/**
* @param samePack If true, then only the data
* @return
*/
@Nullable
public static DataMetadataSection getData(ResourceLocation location, boolean samePack) {
IResourceManager resManager = Minecraft.getMinecraft().getResourceManager();
register();
try {
List<IResource> resources = resManager.getAllResources(location);
DataMetadataSection section = null;
for (IResource resource : resources) {
section = resource.getMetadata(DataMetadataSection.SECTION_NAME);
if (section != null || samePack) {
break;
}
}
for (IResource res : resources) {
try {
res.close();
} catch (IOException io) {
io.printStackTrace();
}
}
return section;
} catch (FileNotFoundException fnfe) {
// That's fine
return null;
} catch (IOException e) {
// That's not fine
e.printStackTrace();
return null;
}
}
use of net.minecraft.client.resources.IResource in project RebornCore by TechReborn.
the class InputStreamTexture method loadTexture.
public void loadTexture(IResourceManager resourceManager) throws IOException {
this.deleteGlTexture();
if (image == null) {
IResource iresource = null;
try {
iresource = new IResource() {
@Override
public ResourceLocation getResourceLocation() {
return new ResourceLocation("reborncore:loaded/" + name);
}
@Override
public InputStream getInputStream() {
return textureLocation;
}
@Override
public boolean hasMetadata() {
return false;
}
@Override
public <T extends IMetadataSection> T getMetadata(String sectionName) {
return null;
}
@Override
public String getResourcePackName() {
return "reborncore";
}
@Override
public void close() throws IOException {
}
};
image = TextureUtil.readBufferedImage(iresource.getInputStream());
} finally {
IOUtils.closeQuietly(iresource);
}
}
TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), image, false, false);
}
use of net.minecraft.client.resources.IResource in project RebornCore by TechReborn.
the class FileSystemTexture method loadTexture.
public void loadTexture(IResourceManager resourceManager) throws IOException {
this.deleteGlTexture();
if (image == null) {
IResource iresource = null;
try {
iresource = new IResource() {
FileInputStream stream;
@Override
public ResourceLocation getResourceLocation() {
return new ResourceLocation("reborncore:loaded/" + textureLocation.getName());
}
@Override
public InputStream getInputStream() {
if (stream == null) {
try {
stream = new FileInputStream(textureLocation);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return stream;
}
@Override
public boolean hasMetadata() {
return false;
}
@Override
public <T extends IMetadataSection> T getMetadata(String sectionName) {
return null;
}
@Override
public String getResourcePackName() {
return "reborncore";
}
@Override
public void close() throws IOException {
if (stream != null) {
stream.close();
}
}
};
image = TextureUtil.readBufferedImage(iresource.getInputStream());
} finally {
IOUtils.closeQuietly(iresource);
}
}
TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), image, false, false);
}
Aggregations