Search in sources :

Example 6 with IResource

use of net.minecraft.resources.IResource 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);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) IResource(net.minecraft.resources.IResource)

Example 7 with IResource

use of net.minecraft.resources.IResource in project ChocolateQuestRepoured by TeamChocoQuest.

the class ResourceSupplier method get.

@Override
public String get() {
    StringBuilder sb = new StringBuilder();
    try (IResource resource = Minecraft.getInstance().getResourceManager().getResource(this.file)) {
        try (Stream<String> stream = new BufferedReader(new InputStreamReader(resource.getInputStream())).lines()) {
            stream.forEach(s -> {
                sb.append(s);
                sb.append('\n');
            });
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sb.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IResource(net.minecraft.resources.IResource)

Example 8 with IResource

use of net.minecraft.resources.IResource 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);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) IntBuffer(java.nio.IntBuffer) IResource(net.minecraft.resources.IResource)

Example 9 with IResource

use of net.minecraft.resources.IResource in project MCMOD-Industria by M-Marvin.

the class JigsawFileManager method loadTemplate.

private static Template loadTemplate(ServerWorld world, ResourceLocation location) {
    IResourceManager resourceManager = getResourceManager(world);
    ResourceLocation resourcePath = new ResourceLocation(location.getNamespace(), "structures/" + location.getPath() + ".nbt");
    try (IResource resource = resourceManager.getResource(resourcePath)) {
        InputStream inputStream = resource.getInputStream();
        CompoundNBT fileNBT = CompressedStreamTools.readCompressed(inputStream);
        Template template = new Template();
        template.load(fileNBT);
        return template;
    } catch (FileNotFoundException e) {
        return null;
    } catch (Throwable throwable) {
        Industria.LOGGER.error("Couldn't load Structure {}: {}", location, throwable);
        return null;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) InputStream(java.io.InputStream) ResourceLocation(net.minecraft.util.ResourceLocation) FileNotFoundException(java.io.FileNotFoundException) IResourceManager(net.minecraft.resources.IResourceManager) IResource(net.minecraft.resources.IResource) Template(net.minecraft.world.gen.feature.template.Template)

Example 10 with IResource

use of net.minecraft.resources.IResource in project MCMOD-Industria by M-Marvin.

the class AnimatedTexture method load.

public void load(IResourceManager manager) throws IOException {
    SimpleTexture.TextureData simpletexture$texturedata = this.getTextureImage(manager);
    simpletexture$texturedata.throwIfError();
    TextureMetadataSection texturemetadatasection = simpletexture$texturedata.getTextureMetadata();
    boolean flag;
    boolean flag1;
    if (texturemetadatasection != null) {
        flag = texturemetadatasection.isBlur();
        flag1 = texturemetadatasection.isClamp();
    } else {
        flag = false;
        flag1 = false;
    }
    NativeImage nativeimage = simpletexture$texturedata.getImage();
    if (!RenderSystem.isOnRenderThreadOrInit()) {
        RenderSystem.recordRenderCall(() -> {
            this.loadImage(nativeimage, flag, flag1);
        });
    } else {
        this.loadImage(nativeimage, flag, flag1);
    }
    this.size = simpletexture$texturedata.getImage().getWidth();
    this.textureHeight = simpletexture$texturedata.getImage().getHeight();
    ResourceLocation metadataFile = new ResourceLocation(this.location.getNamespace(), this.location.getPath() + ".mcmeta");
    try {
        IResource metadataResource = manager.getResource(metadataFile);
        InputStreamReader inputStreamReader = new InputStreamReader(metadataResource.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuffer stringBuffer = new StringBuffer();
        String string;
        while ((string = bufferedReader.readLine()) != null) {
            stringBuffer.append(string);
        }
        CompoundNBT metadataNBT = JsonToNBT.parseTag(stringBuffer.toString());
        CompoundNBT animation = metadataNBT.getCompound("animation");
        this.frameTime = animation.getInt("frametime");
        if (animation.contains("frames")) {
            ListNBT arr = animation.getList("frames", 3);
            frames = new int[arr.size()];
            for (int i = 0; i < arr.size(); i++) {
                this.frames[i] = arr.getInt(i);
            }
        } else {
            int height = simpletexture$texturedata.getImage().getHeight();
            int frameCount = height / size;
            frames = new int[frameCount];
            for (int i = 0; i < frameCount; i++) {
                this.frames[i] = i;
            }
        }
    } catch (CommandSyntaxException | FileNotFoundException e) {
        this.frames = new int[] { 0 };
        this.frameTime = 1;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CompoundNBT(net.minecraft.nbt.CompoundNBT) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) FileNotFoundException(java.io.FileNotFoundException) SimpleTexture(net.minecraft.client.renderer.texture.SimpleTexture) ListNBT(net.minecraft.nbt.ListNBT) NativeImage(net.minecraft.client.renderer.texture.NativeImage) ResourceLocation(net.minecraft.util.ResourceLocation) BufferedReader(java.io.BufferedReader) IResource(net.minecraft.resources.IResource) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Aggregations

IResource (net.minecraft.resources.IResource)10 NativeImage (net.minecraft.client.renderer.texture.NativeImage)4 BufferedReader (java.io.BufferedReader)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 TextureMetadataSection (net.minecraft.client.resources.data.TextureMetadataSection)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 BufferedImage (java.awt.image.BufferedImage)2 ListNBT (net.minecraft.nbt.ListNBT)2 IResourceManager (net.minecraft.resources.IResourceManager)2 JsonObject (com.google.gson.JsonObject)1 StringReader (com.mojang.brigadier.StringReader)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 IntBuffer (java.nio.IntBuffer)1 SimpleTexture (net.minecraft.client.renderer.texture.SimpleTexture)1 Texture (net.minecraft.client.renderer.texture.Texture)1