Search in sources :

Example 1 with IResource

use of net.minecraft.resources.IResource in project Mekanism by mekanism.

the class GuiElementHolder method updateBackgroundColor.

public static void updateBackgroundColor() {
    // get it from the texture
    try {
        IResource resource = Minecraft.getInstance().getResourceManager().getResource(HOLDER);
        BufferedImage img = ImageIO.read(resource.getInputStream());
        int rgb = img.getRGB(HOLDER_SIZE + 1, HOLDER_SIZE + 1);
        if (rgb >> 24 == 0) {
            // Don't allow fully transparent colors, fallback to default color.
            // Mark as null for now so that it can default to the proper color
            rgb = 0xFF787878;
            Mekanism.logger.warn("Unable to retrieve background color for element holder.");
        }
        BACKGROUND_COLOR = rgb;
    } catch (Exception e) {
        Mekanism.logger.error("Failed to retrieve background color for element holder", e);
    }
}
Also used : IResource(net.minecraft.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

Example 2 with IResource

use of net.minecraft.resources.IResource in project Mekanism by mekanism.

the class ColorAtlas method loadColorAtlas.

private static void loadColorAtlas(ResourceLocation rl, int count, List<Color> ret) throws IOException {
    IResource resource = Minecraft.getInstance().getResourceManager().getResource(rl);
    BufferedImage img = ImageIO.read(resource.getInputStream());
    for (int i = 0; i < count; i++) {
        int rgb = img.getRGB(i % ATLAS_SIZE, i / ATLAS_SIZE);
        if (rgb >> 24 == 0) {
            // Don't allow fully transparent colors, fallback to default color.
            // Mark as null for now so that it can default to the proper color
            ret.add(null);
            Mekanism.logger.warn("Unable to retrieve color marker: '{}' for atlas: '{}'. This is likely due to an out of date resource pack.", count, rl);
        } else {
            ret.add(Color.argb(rgb));
        }
    }
}
Also used : IResource(net.minecraft.resources.IResource) BufferedImage(java.awt.image.BufferedImage)

Example 3 with IResource

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

the class JigsawFileManager method loadListNBT.

@SuppressWarnings("deprecation")
private static ListNBT loadListNBT(ServerWorld world, ResourceLocation location) {
    IResourceManager resourceManager = getResourceManager(world);
    ResourceLocation resourcePath = new ResourceLocation(location.getNamespace(), "structures/" + location.getPath() + ".mcmeta");
    try (IResource resource = resourceManager.getResource(resourcePath)) {
        InputStream inputStream = resource.getInputStream();
        String jsonString = IOUtils.toString(inputStream);
        CompoundNBT fileNBT = new JsonToNBT(new StringReader(jsonString)).readStruct();
        ListNBT list = fileNBT.getList("structures", 10);
        return list;
    } catch (FileNotFoundException e) {
        return null;
    } catch (Throwable throwable) {
        Industria.LOGGER.error("Couldn't load Jigsaw-Structure-List {}: {}", location, throwable.toString());
        throwable.printStackTrace();
        return null;
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) InputStream(java.io.InputStream) JsonToNBT(net.minecraft.nbt.JsonToNBT) ResourceLocation(net.minecraft.util.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) FileNotFoundException(java.io.FileNotFoundException) IResourceManager(net.minecraft.resources.IResourceManager) IResource(net.minecraft.resources.IResource)

Example 4 with IResource

use of net.minecraft.resources.IResource 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);
    }
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) GlowingMetadataSection(team.cqr.cqrepoured.client.resources.data.GlowingMetadataSection) TextureMetadataSection(net.minecraft.client.resources.data.TextureMetadataSection) TextureMetadataSectionSerializer(net.minecraft.client.resources.data.TextureMetadataSectionSerializer) GlowingMetadataSectionSerializer(team.cqr.cqrepoured.client.resources.data.GlowingMetadataSectionSerializer) Texture(net.minecraft.client.renderer.texture.Texture) IResource(net.minecraft.resources.IResource) Tuple(net.minecraft.util.Tuple)

Example 5 with IResource

use of net.minecraft.resources.IResource in project minecolonies by ldtteam.

the class DatagenLootTableManager method get.

@NotNull
@Override
public LootTable get(@NotNull final ResourceLocation location) {
    final LootTable table = this.tables.get(location);
    if (table != null)
        return table;
    try {
        final IResource resource = existingFileHelper.getResource(getPreparedPath(location), ResourcePackType.SERVER_DATA);
        try (final InputStream inputstream = resource.getInputStream();
            final Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8))) {
            final JsonObject jsonobject = JSONUtils.fromJson(GSON, reader, JsonObject.class);
            final LootTable loottable = ForgeHooks.loadLootTable(GSON, location, jsonobject, false, this);
            if (loottable != null) {
                this.tables.put(location, loottable);
                return loottable;
            }
        }
    } catch (final Throwable e) {
        e.printStackTrace();
    }
    return LootTable.EMPTY;
}
Also used : LootTable(net.minecraft.loot.LootTable) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JsonObject(com.google.gson.JsonObject) IResource(net.minecraft.resources.IResource) NotNull(org.jetbrains.annotations.NotNull)

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