Search in sources :

Example 11 with TextureResource

use of com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class MinecraftFontRenderer method getRawEnchantedImage.

public BufferedImage getRawEnchantedImage(BufferedImage source) {
    TextureResource resource = resourceManager.getTextureManager().getTexture(ResourceRegistry.MISC_TEXTURE_LOCATION + "enchanted_item_glint");
    BufferedImage tintOriginal = resource.getTexture();
    if (resource.hasTextureMeta()) {
        TextureMeta meta = resource.getTextureMeta();
        if (meta.hasProperties()) {
            TextureProperties properties = meta.getProperties();
            if (properties.isBlur()) {
                tintOriginal = ImageUtils.applyGaussianBlur(tintOriginal);
            }
        }
        if (meta.hasAnimation()) {
            TextureAnimation animation = meta.getAnimation();
            if (animation.hasWidth() && animation.hasHeight()) {
                tintOriginal = ImageUtils.copyAndGetSubImage(tintOriginal, 0, 0, animation.getWidth(), animation.getHeight());
            } else {
                tintOriginal = ImageUtils.copyAndGetSubImage(tintOriginal, 0, 0, tintOriginal.getWidth(), tintOriginal.getWidth());
            }
        }
    }
    BufferedImage tintImage = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g3 = tintImage.createGraphics();
    g3.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g3.drawImage(tintOriginal, 0, 0, tintImage.getWidth() * 4, tintImage.getHeight() * 4, null);
    g3.dispose();
    return tintImage;
}
Also used : TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) TextureProperties(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties) TextureMeta(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta) TextureAnimation(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 12 with TextureResource

use of com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class ModelRenderer method render.

public RenderResult render(int width, int height, int internalWidth, int internalHeight, ResourceManager manager, boolean post1_8, String modelKey, ModelDisplayPosition displayPosition, Map<ModelOverrideType, Float> predicate, Map<String, TextureResource> providedTextures, TintIndexData tintIndexData, boolean enchanted, boolean usePlayerModelPosition) {
    String cacheKey = cacheKey(width, height, manager.getUuid(), modelKey, displayPosition, predicate, cacheKeyProvidedTextures(providedTextures), enchanted);
    Cache<?> cachedRender = Cache.getCache(cacheKey);
    if (cachedRender != null) {
        RenderResult cachedResult = (RenderResult) cachedRender.getObject();
        if (cachedResult.isSuccessful()) {
            return cachedResult;
        }
    }
    String rejectedReason = null;
    BlockModel blockModel = manager.getModelManager().resolveBlockModel(modelKey, post1_8, predicate);
    if (blockModel == null) {
        return new RenderResult(MODEL_NOT_FOUND, null);
    }
    BufferedImage image = new BufferedImage(internalWidth, internalHeight, BufferedImage.TYPE_INT_ARGB);
    if (blockModel.getRawParent() == null || !blockModel.getRawParent().contains("/")) {
        renderBlockModel(generateStandardRenderModel(blockModel, manager, providedTextures, tintIndexData, enchanted, false), image, blockModel.getDisplay(displayPosition), blockModel.getGUILight(), usePlayerModelPosition);
    } else if (blockModel.getRawParent().equals(ModelManager.ITEM_BASE)) {
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        for (int i = 0; blockModel.getTextures().containsKey(ModelManager.ITEM_BASE_LAYER + i); i++) {
            String resourceLocation = blockModel.getTextures().get(ModelManager.ITEM_BASE_LAYER + i);
            if (!resourceLocation.contains(":")) {
                resourceLocation = ResourceRegistry.DEFAULT_NAMESPACE + ":" + resourceLocation;
            }
            TextureResource resource = providedTextures.get(resourceLocation);
            if (resource == null) {
                resource = manager.getTextureManager().getTexture(resourceLocation);
            }
            BufferedImage texture = resource.getTexture();
            if (resource.hasTextureMeta()) {
                TextureMeta meta = resource.getTextureMeta();
                if (meta.hasProperties()) {
                    TextureProperties properties = meta.getProperties();
                    if (properties.isBlur()) {
                        texture = ImageUtils.applyGaussianBlur(texture);
                    }
                }
                if (meta.hasAnimation()) {
                    TextureAnimation animation = meta.getAnimation();
                    if (animation.hasWidth() && animation.hasHeight()) {
                        texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, animation.getWidth(), animation.getHeight());
                    } else {
                        texture = ImageUtils.copyAndGetSubImage(texture, 0, 0, texture.getWidth(), texture.getWidth());
                    }
                }
            }
            if (resourceLocation.equals(ResourceRegistry.MAP_MARKINGS_LOCATION)) {
                ImageUtils.xor(image, ImageUtils.resizeImageAbs(texture, image.getWidth(), image.getHeight()), 200);
            } else {
                g.drawImage(texture, 0, 0, image.getWidth(), image.getHeight(), null);
            }
        }
        g.dispose();
        image = tintIndexData.applyTint(image, 0);
        if (enchanted) {
            image = enchantmentGlintProvider.apply(image);
        }
    } else {
        rejectedReason = blockModel.getRawParent();
    }
    RenderResult result;
    if (rejectedReason == null) {
        result = new RenderResult(ImageUtils.resizeImageQuality(image, width, height), blockModel);
    } else {
        result = new RenderResult(rejectedReason == null ? "null" : rejectedReason, blockModel);
    }
    Cache.putCache(cacheKey, result, cacheTimeoutSupplier.getAsLong());
    return result;
}
Also used : TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) TextureProperties(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties) TextureMeta(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta) TextureAnimation(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation) BlockModel(com.loohp.interactivechatdiscordsrvaddon.resources.models.BlockModel) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

TextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource)12 BufferedImage (java.awt.image.BufferedImage)12 GeneratedTextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource)7 Graphics2D (java.awt.Graphics2D)7 TextureAnimation (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureAnimation)6 TextureMeta (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureMeta)6 TextureProperties (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureProperties)6 ModelOverrideType (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType)4 TintIndexData (com.loohp.interactivechatdiscordsrvaddon.utils.TintUtils.TintIndexData)4 XMaterial (com.loohp.interactivechat.libs.com.cryptomorin.xseries.XMaterial)3 RenderResult (com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.RenderResult)3 BlockModel (com.loohp.interactivechatdiscordsrvaddon.resources.models.BlockModel)3 Color (java.awt.Color)3 HashMap (java.util.HashMap)3 Model (com.loohp.blockmodelrenderer.render.Model)2 NamedTextColor (com.loohp.interactivechat.libs.net.kyori.adventure.text.format.NamedTextColor)2 TextColor (com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor)2 JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)2 JSONParser (com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser)2 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)2