Search in sources :

Example 1 with ItemStackProcessResult

use of com.loohp.interactivechatdiscordsrvaddon.utils.ItemRenderUtils.ItemStackProcessResult in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class ImageGeneration method getRawItemImage.

private static BufferedImage getRawItemImage(ItemStack item, OfflineICPlayer player) throws IOException {
    InteractiveChatDiscordSrvAddon.plugin.imageCounter.incrementAndGet();
    Debug.debug("ImageGeneration creating raw item stack image " + (item == null ? "null" : ItemNBTUtils.getNMSItemStackJson(item)));
    XMaterial xMaterial = XMaterialUtils.matchXMaterial(item);
    int amount = item.getAmount();
    String key = ModelUtils.getItemModelKey(xMaterial);
    ItemStackProcessResult processResult = ItemRenderUtils.processItemForRendering(player, item);
    boolean requiresEnchantmentGlint = processResult.requiresEnchantmentGlint();
    Map<ModelOverrideType, Float> predicates = processResult.getPredicates();
    Map<String, TextureResource> providedTextures = processResult.getProvidedTextures();
    TintIndexData tintIndexData = processResult.getTintIndexData();
    String directLocation = processResult.getDirectLocation();
    BufferedImage itemImage;
    RenderResult renderResult = InteractiveChatDiscordSrvAddon.plugin.modelRenderer.render(32, 32, resourceManager.get(), version.get().isOld(), directLocation == null ? ResourceRegistry.ITEM_MODEL_LOCATION + key : directLocation, ModelDisplayPosition.GUI, predicates, providedTextures, tintIndexData, requiresEnchantmentGlint);
    if (renderResult.isSuccessful()) {
        itemImage = renderResult.getImage();
    } else {
        Debug.debug("ImageGeneration creating missing Image for material " + xMaterial);
        itemImage = TextureManager.getMissingImage(32, 32);
    }
    if (item.getType().getMaxDurability() > 0) {
        int durability = item.getType().getMaxDurability() - (version.get().isLegacy() ? item.getDurability() : ((Damageable) item.getItemMeta()).getDamage());
        int maxDur = item.getType().getMaxDurability();
        double percentage = ((double) durability / (double) maxDur);
        if (percentage < 1) {
            int hue = (int) (125 * percentage);
            int length = (int) (26 * percentage);
            Color color = Color.getHSBColor((float) hue / 360, 1, 1);
            Graphics2D g4 = itemImage.createGraphics();
            g4.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
            g4.setColor(Color.BLACK);
            g4.fillPolygon(new int[] { 4, 30, 30, 4 }, new int[] { 26, 26, 30, 30 }, 4);
            g4.setColor(color);
            g4.fillPolygon(new int[] { 4, 4 + length, 4 + length, 4 }, new int[] { 26, 26, 28, 28 }, 4);
            g4.dispose();
        }
    }
    if (amount != 1) {
        BufferedImage newItemImage = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g4 = newItemImage.createGraphics();
        g4.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g4.drawImage(itemImage, 0, 0, null);
        Component component = Component.text(amount);
        if (amount <= 0) {
            component = component.color(NamedTextColor.RED);
        }
        newItemImage = ImageUtils.printComponentRightAligned(resourceManager.get(), newItemImage, component, InteractiveChatDiscordSrvAddon.plugin.language, version.get().isLegacyRGB(), 33, 17, 16, ITEM_AMOUNT_TEXT_DARKEN_FACTOR);
        g4.dispose();
        itemImage = newItemImage;
    }
    return itemImage;
}
Also used : TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) GeneratedTextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource) ItemStackProcessResult(com.loohp.interactivechatdiscordsrvaddon.utils.ItemRenderUtils.ItemStackProcessResult) Color(java.awt.Color) TextColor(com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor) NamedTextColor(com.loohp.interactivechat.libs.net.kyori.adventure.text.format.NamedTextColor) RenderResult(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.RenderResult) XMaterial(com.loohp.interactivechat.libs.com.cryptomorin.xseries.XMaterial) TintIndexData(com.loohp.interactivechatdiscordsrvaddon.utils.TintUtils.TintIndexData) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ModelOverrideType(com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType) Component(com.loohp.interactivechat.libs.net.kyori.adventure.text.Component)

Example 2 with ItemStackProcessResult

use of com.loohp.interactivechatdiscordsrvaddon.utils.ItemRenderUtils.ItemStackProcessResult in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class ImageGeneration method getFullBodyImage.

private static BufferedImage getFullBodyImage(OfflineICPlayer player, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) throws IOException {
    InteractiveChatDiscordSrvAddon.plugin.imageCounter.incrementAndGet();
    Debug.debug("ImageGeneration creating puppet image of " + player.getName());
    BufferedImage skin = null;
    boolean slim = false;
    BufferedImage cape;
    try {
        JSONObject json;
        ICPlayer icPlayer = player.getPlayer();
        if (icPlayer != null && icPlayer.isLocal()) {
            json = (JSONObject) new JSONParser().parse(SkinUtils.getSkinJsonFromProfile(((ICPlayer) player).getLocalPlayer()));
        } else {
            json = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(((JSONObject) ((JSONArray) HTTPRequestUtils.getJSONResponse(PLAYER_INFO_URL.replace("%s", player.getUniqueId().toString())).get("properties")).get(0)).get("value").toString())));
        }
        if (json == null) {
            cape = null;
        } else {
            try {
                if (((JSONObject) json.get("textures")).containsKey("CAPE")) {
                    String url = (String) ((JSONObject) ((JSONObject) json.get("textures")).get("CAPE")).get("url");
                    Cache<?> cache = Cache.getCache(player.getUniqueId().toString() + url + PLAYER_CAPE_CACHE_KEY);
                    if (cache == null) {
                        cape = ImageUtils.downloadImage(url);
                        Cache.putCache(player.getUniqueId().toString() + url + PLAYER_CAPE_CACHE_KEY, cape, InteractiveChatDiscordSrvAddon.plugin.cacheTimeout);
                    } else {
                        cape = (BufferedImage) cache.getObject();
                    }
                } else {
                    String url = OPTIFINE_CAPE_URL.replaceAll("%s", CustomStringUtils.escapeReplaceAllMetaCharacters(player.getName()));
                    Cache<?> cache = Cache.getCache(player.getUniqueId().toString() + url + PLAYER_CAPE_CACHE_KEY);
                    if (cache == null) {
                        try {
                            cape = ImageUtils.downloadImage(url);
                            Cache.putCache(player.getUniqueId().toString() + url + PLAYER_CAPE_CACHE_KEY, cape, InteractiveChatDiscordSrvAddon.plugin.cacheTimeout);
                        } catch (Throwable ignore) {
                            cape = null;
                        }
                    } else {
                        cape = (BufferedImage) cache.getObject();
                    }
                }
            } catch (Throwable e) {
                cape = null;
            }
            try {
                String value = (String) ((JSONObject) ((JSONObject) json.get("textures")).get("SKIN")).get("url");
                if (((JSONObject) ((JSONObject) json.get("textures")).get("SKIN")).containsKey("metadata")) {
                    slim = ((JSONObject) ((JSONObject) ((JSONObject) json.get("textures")).get("SKIN")).get("metadata")).get("model").toString().equals("slim");
                }
                Cache<?> cache = Cache.getCache(player.getUniqueId().toString() + value + PLAYER_SKIN_CACHE_KEY);
                if (cache == null) {
                    skin = ImageUtils.downloadImage(value);
                    Cache.putCache(player.getUniqueId().toString() + value + PLAYER_SKIN_CACHE_KEY, skin, InteractiveChatDiscordSrvAddon.plugin.cacheTimeout);
                } else {
                    skin = (BufferedImage) cache.getObject();
                }
                skin = ImageUtils.copyImage(skin);
            } catch (Throwable e1) {
            }
        }
    } catch (Exception e) {
        cape = null;
    }
    if (skin == null) {
        if (slim) {
            skin = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "alex").getTexture();
        } else {
            skin = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "steve").getTexture();
        }
    }
    BufferedImage elytraImage = null;
    BufferedImage image = new BufferedImage(556, 748, BufferedImage.TYPE_INT_ARGB);
    Map<String, TextureResource> providedTextures = new HashMap<>();
    Map<PlayerModelItemPosition, PlayerModelItem> modelItems = new HashMap<>();
    providedTextures.put(ResourceRegistry.SKIN_FULL_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(ModelUtils.convertToModernSkinTexture(skin)));
    if (ItemStackUtils.isWearable(leggings)) {
        XMaterial type = XMaterialUtils.matchXMaterial(leggings);
        BufferedImage leggingsImage = null;
        switch(type) {
            case LEATHER_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_2").getTexture();
                LeatherArmorMeta meta = (LeatherArmorMeta) leggings.getItemMeta();
                Color color = new Color(meta.getColor().asRGB());
                BufferedImage armorOverlay = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_2_overlay").getTexture();
                BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(leggingsImage), color);
                leggingsImage = ImageUtils.multiply(leggingsImage, colorOverlay);
                Graphics2D g2 = leggingsImage.createGraphics();
                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                g2.drawImage(armorOverlay, 0, 0, null);
                g2.dispose();
                break;
            case CHAINMAIL_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "chainmail_layer_2").getTexture();
                break;
            case GOLDEN_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "gold_layer_2").getTexture();
                break;
            case IRON_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "iron_layer_2").getTexture();
                break;
            case DIAMOND_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "diamond_layer_2").getTexture();
                break;
            case NETHERITE_LEGGINGS:
                leggingsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "netherite_layer_2").getTexture();
                break;
            default:
                break;
        }
        if (leggingsImage != null) {
            if (leggings.getEnchantments().size() > 0) {
                leggingsImage = getEnchantedImage(leggingsImage);
            }
            providedTextures.put(ResourceRegistry.LEGGINGS_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(leggingsImage));
        }
    }
    if (ItemStackUtils.isWearable(boots)) {
        XMaterial type = XMaterialUtils.matchXMaterial(boots);
        BufferedImage bootsImage = null;
        switch(type) {
            case LEATHER_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1").getTexture();
                LeatherArmorMeta meta = (LeatherArmorMeta) boots.getItemMeta();
                Color color = new Color(meta.getColor().asRGB());
                BufferedImage armorOverlay = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1_overlay").getTexture();
                BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(bootsImage), color);
                bootsImage = ImageUtils.multiply(bootsImage, colorOverlay);
                Graphics2D g2 = bootsImage.createGraphics();
                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                g2.drawImage(armorOverlay, 0, 0, null);
                g2.dispose();
                break;
            case CHAINMAIL_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "chainmail_layer_1").getTexture();
                break;
            case GOLDEN_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "gold_layer_1").getTexture();
                break;
            case IRON_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "iron_layer_1").getTexture();
                break;
            case DIAMOND_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "diamond_layer_1").getTexture();
                break;
            case NETHERITE_BOOTS:
                bootsImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "netherite_layer_1").getTexture();
                break;
            default:
                break;
        }
        if (bootsImage != null) {
            if (boots.getEnchantments().size() > 0) {
                bootsImage = getEnchantedImage(bootsImage);
            }
            providedTextures.put(ResourceRegistry.BOOTS_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(bootsImage));
        }
    }
    if (ItemStackUtils.isWearable(chestplate)) {
        XMaterial type = XMaterialUtils.matchXMaterial(chestplate);
        BufferedImage chestplateImage = null;
        boolean isArmor = true;
        switch(type) {
            case LEATHER_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1").getTexture();
                LeatherArmorMeta meta = (LeatherArmorMeta) chestplate.getItemMeta();
                Color color = new Color(meta.getColor().asRGB());
                BufferedImage armorOverlay = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1_overlay").getTexture();
                BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(chestplateImage), color);
                chestplateImage = ImageUtils.multiply(chestplateImage, colorOverlay);
                Graphics2D g2 = chestplateImage.createGraphics();
                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                g2.drawImage(armorOverlay, 0, 0, null);
                g2.dispose();
                break;
            case CHAINMAIL_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "chainmail_layer_1").getTexture();
                break;
            case GOLDEN_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "gold_layer_1").getTexture();
                break;
            case IRON_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "iron_layer_1").getTexture();
                break;
            case DIAMOND_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "diamond_layer_1").getTexture();
                break;
            case NETHERITE_CHESTPLATE:
                chestplateImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "netherite_layer_1").getTexture();
                break;
            case ELYTRA:
                isArmor = false;
                chestplateImage = new BufferedImage(150, 150, BufferedImage.TYPE_INT_ARGB);
                BufferedImage wing = cape == null ? resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "elytra").getTexture() : cape;
                if (wing.getWidth() % 64 != 0 || wing.getHeight() % 32 != 0) {
                    int w = 0;
                    int h = 0;
                    while (w < wing.getWidth()) {
                        w += 64;
                        h += 32;
                    }
                    BufferedImage resize = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g3 = resize.createGraphics();
                    g3.drawImage(wing, 0, 0, null);
                    g3.dispose();
                    wing = resize;
                }
                int scale = wing.getWidth() / 64;
                wing = ImageUtils.copyAndGetSubImage(wing, 34 * scale, 2 * scale, 12 * scale, 20 * scale);
                wing = ImageUtils.multiply(ImageUtils.resizeImage(wing, Math.pow(scale, -1) * 3.75), 0.7);
                BufferedImage leftWing = ImageUtils.rotateImageByDegrees(wing, 23.41);
                Graphics2D g3 = chestplateImage.createGraphics();
                g3.drawImage(leftWing, 0, 0, null);
                wing = ImageUtils.flipHorizontal(wing);
                BufferedImage rightWing = ImageUtils.rotateImageByDegrees(wing, 360.0 - 23.41);
                g3.drawImage(rightWing, 26, 0, null);
                g3.dispose();
                if (chestplate.getEnchantments().size() > 0) {
                    chestplateImage = getEnchantedImage(chestplateImage);
                }
                elytraImage = chestplateImage;
            default:
                break;
        }
        if (isArmor && chestplateImage != null) {
            if (chestplate.getEnchantments().size() > 0) {
                chestplateImage = getEnchantedImage(chestplateImage);
            }
            providedTextures.put(ResourceRegistry.CHESTPLATE_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(chestplateImage));
        }
    }
    if (helmet != null && !helmet.getType().equals(Material.AIR)) {
        XMaterial type = XMaterialUtils.matchXMaterial(helmet);
        BufferedImage helmetImage = null;
        boolean isArmor = true;
        switch(type) {
            case LEATHER_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1").getTexture();
                LeatherArmorMeta meta = (LeatherArmorMeta) helmet.getItemMeta();
                Color color = new Color(meta.getColor().asRGB());
                BufferedImage armorOverlay = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "leather_layer_1_overlay").getTexture();
                BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(helmetImage), color);
                helmetImage = ImageUtils.multiply(helmetImage, colorOverlay);
                Graphics2D g2 = helmetImage.createGraphics();
                g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                g2.drawImage(armorOverlay, 0, 0, null);
                g2.dispose();
                break;
            case CHAINMAIL_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "chainmail_layer_1").getTexture();
                break;
            case GOLDEN_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "gold_layer_1").getTexture();
                break;
            case IRON_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "iron_layer_1").getTexture();
                break;
            case DIAMOND_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "diamond_layer_1").getTexture();
                break;
            case NETHERITE_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "netherite_layer_1").getTexture();
                break;
            case TURTLE_HELMET:
                helmetImage = resourceManager.get().getTextureManager().getTexture(ResourceRegistry.ARMOR_TEXTURE_LOCATION + "turtle_layer_1").getTexture();
                break;
            default:
                isArmor = false;
                String key = ModelUtils.getItemModelKey(type);
                ItemStackProcessResult itemProcessResult = ItemRenderUtils.processItemForRendering(player, helmet);
                boolean enchanted = itemProcessResult.requiresEnchantmentGlint();
                Map<ModelOverrideType, Float> predicate = itemProcessResult.getPredicates();
                String modelKey = itemProcessResult.getDirectLocation() == null ? ResourceRegistry.ITEM_MODEL_LOCATION + key : itemProcessResult.getDirectLocation();
                Map<String, TextureResource> itemProvidedTextures = itemProcessResult.getProvidedTextures();
                TintIndexData tintIndexData = itemProcessResult.getTintIndexData();
                modelItems.put(PlayerModelItemPosition.HELMET, new PlayerModelItem(PlayerModelItemPosition.HELMET, modelKey, predicate, enchanted, itemProvidedTextures, tintIndexData));
                break;
        }
        if (isArmor) {
            if (helmet.getEnchantments().size() > 0) {
                helmetImage = getEnchantedImage(helmetImage);
            }
            providedTextures.put(ResourceRegistry.HELMET_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(helmetImage));
        }
    }
    if (InteractiveChatDiscordSrvAddon.plugin.renderHandHeldItems) {
        ItemStack rightHand = player.isRightHanded() ? player.getMainHandItem() : player.getOffHandItem();
        if (rightHand != null) {
            String key = ModelUtils.getItemModelKey(XMaterialUtils.matchXMaterial(rightHand));
            ItemStackProcessResult itemProcessResult = ItemRenderUtils.processItemForRendering(player, rightHand);
            boolean enchanted = itemProcessResult.requiresEnchantmentGlint();
            Map<ModelOverrideType, Float> predicate = itemProcessResult.getPredicates();
            String modelKey = itemProcessResult.getDirectLocation() == null ? ResourceRegistry.ITEM_MODEL_LOCATION + key : itemProcessResult.getDirectLocation();
            Map<String, TextureResource> itemProvidedTextures = itemProcessResult.getProvidedTextures();
            TintIndexData tintIndexData = itemProcessResult.getTintIndexData();
            modelItems.put(PlayerModelItemPosition.RIGHT_HAND, new PlayerModelItem(PlayerModelItemPosition.RIGHT_HAND, modelKey, predicate, enchanted, itemProvidedTextures, tintIndexData));
        }
        ItemStack leftHand = player.isRightHanded() ? player.getOffHandItem() : player.getMainHandItem();
        if (leftHand != null) {
            String key = ModelUtils.getItemModelKey(XMaterialUtils.matchXMaterial(leftHand));
            ItemStackProcessResult itemProcessResult = ItemRenderUtils.processItemForRendering(player, leftHand);
            boolean enchanted = itemProcessResult.requiresEnchantmentGlint();
            Map<ModelOverrideType, Float> predicate = itemProcessResult.getPredicates();
            String modelKey = itemProcessResult.getDirectLocation() == null ? ResourceRegistry.ITEM_MODEL_LOCATION + key : itemProcessResult.getDirectLocation();
            Map<String, TextureResource> itemProvidedTextures = itemProcessResult.getProvidedTextures();
            TintIndexData tintIndexData = itemProcessResult.getTintIndexData();
            modelItems.put(PlayerModelItemPosition.LEFT_HAND, new PlayerModelItem(PlayerModelItemPosition.LEFT_HAND, modelKey, predicate, enchanted, itemProvidedTextures, tintIndexData));
        }
    }
    boolean upsideDown = ModelUtils.isRenderedUpsideDown(player.getName(), cape != null);
    RenderResult renderResult = InteractiveChatDiscordSrvAddon.plugin.modelRenderer.renderPlayer(image.getWidth(), image.getHeight(), resourceManager.get(), version.get().isOld(), slim, providedTextures, TintIndexData.EMPTY_INSTANCE, modelItems);
    Graphics2D g = image.createGraphics();
    BufferedImage resizedImage = ImageUtils.resizeImageAbs(renderResult.getImage(), 117, 159);
    if (upsideDown) {
        resizedImage = ImageUtils.rotateImageByDegrees(resizedImage, 180);
    }
    g.drawImage(resizedImage, -1, 12, null);
    g.dispose();
    if (elytraImage != null) {
        BufferedImage resizedElytraImage = ImageUtils.resizeImage(elytraImage, 0.9);
        if (upsideDown) {
            resizedElytraImage = ImageUtils.rotateImageByDegrees(resizedElytraImage, 180);
        }
        ImageUtils.drawTransparent(image, resizedElytraImage, 14, 75);
    }
    return image;
}
Also used : TextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource) GeneratedTextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) OfflineICPlayer(com.loohp.interactivechat.objectholders.OfflineICPlayer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemStackProcessResult(com.loohp.interactivechatdiscordsrvaddon.utils.ItemRenderUtils.ItemStackProcessResult) RenderResult(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.RenderResult) BufferedImage(java.awt.image.BufferedImage) PlayerModelItemPosition(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.PlayerModelItemPosition) PlayerModelItem(com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.PlayerModelItem) ModelOverrideType(com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType) Color(java.awt.Color) TextColor(com.loohp.interactivechat.libs.net.kyori.adventure.text.format.TextColor) NamedTextColor(com.loohp.interactivechat.libs.net.kyori.adventure.text.format.NamedTextColor) GeneratedTextureResource(com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource) XMaterial(com.loohp.interactivechat.libs.com.cryptomorin.xseries.XMaterial) IOException(java.io.IOException) TintIndexData(com.loohp.interactivechatdiscordsrvaddon.utils.TintUtils.TintIndexData) Graphics2D(java.awt.Graphics2D) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) JSONParser(com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

XMaterial (com.loohp.interactivechat.libs.com.cryptomorin.xseries.XMaterial)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 RenderResult (com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.RenderResult)2 ModelOverrideType (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType)2 GeneratedTextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.GeneratedTextureResource)2 TextureResource (com.loohp.interactivechatdiscordsrvaddon.resources.textures.TextureResource)2 ItemStackProcessResult (com.loohp.interactivechatdiscordsrvaddon.utils.ItemRenderUtils.ItemStackProcessResult)2 TintIndexData (com.loohp.interactivechatdiscordsrvaddon.utils.TintUtils.TintIndexData)2 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 Component (com.loohp.interactivechat.libs.net.kyori.adventure.text.Component)1 JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)1 JSONParser (com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser)1 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)1 OfflineICPlayer (com.loohp.interactivechat.objectholders.OfflineICPlayer)1 PlayerModelItem (com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.PlayerModelItem)1 PlayerModelItemPosition (com.loohp.interactivechatdiscordsrvaddon.resources.ModelRenderer.PlayerModelItemPosition)1 IOException (java.io.IOException)1