use of net.minecraft.client.renderer.texture.NativeImage in project ChocolateQuestRepoured by TeamChocoQuest.
the class AutoGlowingTexture method load.
@Override
public void load(IResourceManager resourceManager) throws IOException {
this.releaseId();
try (IResource iresource = resourceManager.getResource(this.originalTexture)) {
// Needed to get the GL-texture id
Texture ito = Minecraft.getInstance().textureManager.getTexture(iresource.getLocation());
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
NativeImage glowingBI = new NativeImage(bufferedimage.getWidth(), bufferedimage.getHeight(), false);
boolean flag = false;
boolean flag1 = false;
// if (iresource.hasMetadata()) {
try {
// DONE: Fix this for the CTS!! Cts for whatever reason tries to load png as mcmeta file...
TextureMetadataSection texturemetadatasection = iresource.getMetadata(new TextureMetadataSectionSerializer());
if (texturemetadatasection != null) {
flag = texturemetadatasection.isBlur();
flag1 = texturemetadatasection.isClamp();
}
GlowingMetadataSection glowInformation = iresource.getMetadata(new GlowingMetadataSectionSerializer());
if (glowInformation != null) {
for (Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> area : glowInformation.getGlowingSections()) {
for (int ix = area.getA().getA(); ix < area.getB().getA(); ix++) {
for (int iy = area.getA().getB(); iy < area.getB().getB(); iy++) {
glowingBI.setPixelRGBA(ix, iy, bufferedimage.getPixelRGBA(ix, iy));
// Remove it from the original
bufferedimage.setPixelRGBA(ix, iy, 0);
}
}
}
}
/*
* String name = this.texture.getPath().replace("/", "-");
* File outputFile = new File(CQRMain.CQ_CONFIG_FOLDER, name);
* ImageIO.write(glowingBI, "png", outputFile);
*/
} catch (RuntimeException runtimeexception) {
LOGGER.warn("Failed reading metadata of: {}", this.originalTexture, runtimeexception);
}
// }
TextureUtil.uploadTextureImageAllocate(this.getId(), glowingBI, flag, flag1);
// Also upload the changes to the original texture...
TextureUtil.uploadTextureImage(ito.getId(), bufferedimage);
}
}
use of net.minecraft.client.renderer.texture.NativeImage in project RGBBlocks by PlatinPython.
the class RGBBlocksPack method generateImage.
public Optional<Pair<NativeImage, Optional<Callable<InputStream>>>> generateImage(ResourceLocation modLocation, ResourceLocation vanillaLocation, IResourceManager manager) {
ResourceLocation parentFile = makeTextureID(vanillaLocation);
try (InputStream inputStream = manager.getResource(parentFile).getInputStream()) {
NativeImage image = NativeImage.read(inputStream);
NativeImage transformedImage = this.transformImage(image);
ResourceLocation metadata = getMetadataLocation(parentFile);
Optional<Callable<InputStream>> metadataLookup = Optional.empty();
if (manager.hasResource(metadata)) {
BufferedReader bufferedReader = null;
JsonObject metadataJson = null;
try (InputStream metadataStream = manager.getResource(metadata).getInputStream()) {
bufferedReader = new BufferedReader(new InputStreamReader(metadataStream, StandardCharsets.UTF_8));
metadataJson = JSONUtils.parse(bufferedReader);
} finally {
IOUtils.closeQuietly(bufferedReader);
}
if (metadataJson != null) {
JsonObject metaDataJsonForLambda = metadataJson;
metadataLookup = Optional.of(() -> new ByteArrayInputStream(metaDataJsonForLambda.toString().getBytes()));
}
}
return Optional.of(Pair.of(transformedImage, metadataLookup));
} catch (IOException e) {
e.printStackTrace();
return Optional.empty();
}
}
use of net.minecraft.client.renderer.texture.NativeImage in project ChocolateQuestRepoured by TeamChocoQuest.
the class InvisibilityTexture method load.
@Override
public void load(IResourceManager resourceManager) throws IOException {
this.releaseId();
try (IResource iresource = resourceManager.getResource(this.originalTextureLocation)) {
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
// CQR Start
PERLIN.setup(RANDOM.nextLong(), 4.0F);
for (int x = 0; x < bufferedimage.getWidth(); x++) {
for (int y = 0; y < bufferedimage.getHeight(); y++) {
int argb = bufferedimage.getPixelRGBA(x, y);
if ((argb >>> 24) <= 2) {
continue;
}
float f = PERLIN.getNoiseAt(x, y);
bufferedimage.setPixelRGBA(x, y, ((int) (f * 255.0F) << 24) | (argb & 0x00FFFFFF));
}
}
// CQR End
boolean flag = false;
boolean flag1 = false;
// if (iresource.hasMetadata()) {
try {
TextureMetadataSection texturemetadatasection = iresource.getMetadata(TextureMetadataSection.SERIALIZER);
if (texturemetadatasection != null) {
flag = texturemetadatasection.isBlur();
flag1 = texturemetadatasection.isClamp();
}
} catch (RuntimeException runtimeexception) {
LOGGER.warn("Failed reading metadata of: {}", this.originalTextureLocation, runtimeexception);
}
// }
TextureUtil.uploadTextureImageAllocate(this.getId(), bufferedimage, flag, flag1);
}
}
use of net.minecraft.client.renderer.texture.NativeImage in project ChocolateQuestRepoured by TeamChocoQuest.
the class CubemapTexture method load.
private void load(IResourceManager resourceManager, ResourceLocation location, int target) throws IOException {
try (IResource iresource = resourceManager.getResource(location)) {
NativeImage bufferedimage = NativeImage.read(TextureUtil.readResource(iresource.getInputStream()));
int w = bufferedimage.getWidth();
int h = bufferedimage.getHeight();
IntBuffer data = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
data.put(bufferedimage.getRGB(0, 0, w, h, new int[w * h], 0, w));
data.flip();
GL11.glTexImage2D(target, 0, GL11.GL_RGBA8, w, h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, data);
}
}
use of net.minecraft.client.renderer.texture.NativeImage in project iChunUtil by iChun.
the class Project method getNativeImageResourceLocation.
@OnlyIn(Dist.CLIENT)
public ResourceLocation getNativeImageResourceLocation() {
if (textureBytes != null) {
if (nativeImageTexture == null) {
try (NativeImage image = NativeImage.read(new ByteArrayInputStream(textureBytes))) {
nativeImageTexture = new NativeImageTexture(image);
Minecraft.getInstance().getTextureManager().loadTexture(nativeImageTexture.getResourceLocation(), nativeImageTexture);
} catch (IOException e) {
iChunUtil.LOGGER.error("Failed to read NativeImage for project: " + name);
e.printStackTrace();
}
}
return nativeImageTexture.getResourceLocation();
}
return null;
}
Aggregations