use of com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class ModelManager method loadDirectory.
@Override
protected void loadDirectory(String namespace, ResourcePackFile root) {
if (!root.exists() || !root.isDirectory()) {
throw new IllegalArgumentException(root.getAbsolutePath() + " is not a directory.");
}
JSONParser parser = new JSONParser();
Map<String, BlockModel> models = new HashMap<>();
Collection<ResourcePackFile> files = root.listFilesRecursively(new String[] { "json" });
for (ResourcePackFile file : files) {
try {
String key = namespace + ":" + file.getRelativePathFrom(root);
key = key.substring(0, key.lastIndexOf("."));
InputStreamReader reader = new InputStreamReader(new BOMInputStream(file.getInputStream()), StandardCharsets.UTF_8);
JSONObject rootJson = (JSONObject) parser.parse(reader);
reader.close();
String parent = (String) rootJson.getOrDefault("parent", null);
boolean ambientocclusion = (boolean) rootJson.getOrDefault("ambientocclusion", true);
ModelGUILight guiLight = rootJson.containsKey("gui_light") ? ModelGUILight.fromKey((String) rootJson.get("gui_light")) : null;
Map<ModelDisplayPosition, ModelDisplay> display = new EnumMap<>(ModelDisplayPosition.class);
JSONObject displayJson = (JSONObject) rootJson.get("display");
if (displayJson != null) {
for (Object obj : displayJson.keySet()) {
String displayKey = obj.toString();
JSONArray rotationArray = (JSONArray) ((JSONObject) displayJson.get(displayKey)).get("rotation");
JSONArray translationArray = (JSONArray) ((JSONObject) displayJson.get(displayKey)).get("translation");
JSONArray scaleArray = (JSONArray) ((JSONObject) displayJson.get(displayKey)).get("scale");
Coordinates3D rotation;
if (rotationArray == null) {
rotation = new Coordinates3D(0, 0, 0);
} else {
rotation = new Coordinates3D(((Number) rotationArray.get(0)).doubleValue(), ((Number) rotationArray.get(1)).doubleValue(), ((Number) rotationArray.get(2)).doubleValue());
}
Coordinates3D translation;
if (translationArray == null) {
translation = new Coordinates3D(0, 0, 0);
} else {
translation = new Coordinates3D(((Number) translationArray.get(0)).doubleValue(), ((Number) translationArray.get(1)).doubleValue(), ((Number) translationArray.get(2)).doubleValue());
}
Coordinates3D scale;
if (scaleArray == null) {
scale = new Coordinates3D(1, 1, 1);
} else {
scale = new Coordinates3D(((Number) scaleArray.get(0)).doubleValue(), ((Number) scaleArray.get(1)).doubleValue(), ((Number) scaleArray.get(2)).doubleValue());
}
ModelDisplayPosition displayPos = ModelDisplayPosition.fromKey(displayKey);
display.put(displayPos, new ModelDisplay(displayPos, rotation, translation, scale));
}
}
Map<String, String> texture = new HashMap<>();
JSONObject textureJson = (JSONObject) rootJson.get("textures");
if (textureJson != null) {
for (Object obj : textureJson.keySet()) {
String textureKey = obj.toString();
texture.put(textureKey, textureJson.get(textureKey).toString());
}
}
List<ModelElement> elements = new ArrayList<>();
JSONArray elementsArray = (JSONArray) rootJson.get("elements");
if (elementsArray != null) {
for (Object obj : elementsArray) {
JSONObject elementJson = (JSONObject) obj;
JSONArray fromArray = (JSONArray) elementJson.get("from");
JSONArray toArray = (JSONArray) elementJson.get("to");
Coordinates3D from = new Coordinates3D(((Number) fromArray.get(0)).doubleValue(), ((Number) fromArray.get(1)).doubleValue(), ((Number) fromArray.get(2)).doubleValue());
Coordinates3D to = new Coordinates3D(((Number) toArray.get(0)).doubleValue(), ((Number) toArray.get(1)).doubleValue(), ((Number) toArray.get(2)).doubleValue());
ModelElementRotation rotation;
JSONObject rotationJson = (JSONObject) elementJson.get("rotation");
if (rotationJson == null) {
rotation = null;
} else {
Coordinates3D origin;
JSONArray originArray = (JSONArray) rotationJson.get("origin");
if (originArray == null) {
origin = new Coordinates3D(0, 0, 0);
} else {
origin = new Coordinates3D(((Number) originArray.get(0)).doubleValue(), ((Number) originArray.get(1)).doubleValue(), ((Number) originArray.get(2)).doubleValue());
}
ModelAxis axis = ModelAxis.valueOf(rotationJson.get("axis").toString().toUpperCase());
double angle = ((Number) rotationJson.get("angle")).doubleValue();
boolean rescale = (boolean) rotationJson.getOrDefault("rescale", false);
rotation = new ModelElementRotation(origin, axis, angle, rescale);
}
boolean shade = (boolean) elementJson.getOrDefault("shade", true);
Map<ModelFaceSide, ModelFace> face = new EnumMap<>(ModelFaceSide.class);
JSONObject facesJson = (JSONObject) elementJson.get("faces");
if (facesJson != null) {
for (Object obj1 : facesJson.keySet()) {
String faceKey = obj1.toString();
ModelFaceSide side = ModelFaceSide.fromKey(faceKey);
JSONObject faceJson = (JSONObject) facesJson.get(faceKey);
TextureUV uv;
JSONArray uvArray = (JSONArray) faceJson.get("uv");
if (uvArray == null) {
uv = null;
} else {
uv = new TextureUV(((Number) uvArray.get(0)).doubleValue(), ((Number) uvArray.get(1)).doubleValue(), ((Number) uvArray.get(2)).doubleValue(), ((Number) uvArray.get(3)).doubleValue());
}
String faceTexture = (String) faceJson.get("texture");
Object cullfaceObj = faceJson.get("cullface");
ModelFaceSide cullface = null;
if (cullfaceObj != null && cullfaceObj instanceof String) {
cullface = ModelFaceSide.fromKey((String) cullfaceObj);
}
if (cullface == null) {
cullface = side;
}
int faceRotation = ((Number) faceJson.getOrDefault("rotation", 0)).intValue();
int faceTintindex = ((Number) faceJson.getOrDefault("tintindex", -1)).intValue();
face.put(side, new ModelFace(side, uv, faceTexture, cullface, faceRotation, faceTintindex));
}
}
elements.add(new ModelElement(from, to, rotation, shade, face));
}
}
List<ModelOverride> overrides = new ArrayList<>();
JSONArray overridesArray = (JSONArray) rootJson.get("overrides");
if (overridesArray != null) {
for (Object obj : overridesArray) {
JSONObject overrideJson = (JSONObject) obj;
JSONObject predicateJson = (JSONObject) overrideJson.get("predicate");
Map<ModelOverrideType, Float> predicates = new EnumMap<>(ModelOverrideType.class);
for (Object obj1 : predicateJson.keySet()) {
String predicateTypeKey = obj1.toString();
ModelOverrideType type = ModelOverrideType.fromKey(predicateTypeKey);
Object value = predicateJson.get(predicateTypeKey);
predicates.put(type, ((Number) value).floatValue());
}
String model = (String) overrideJson.get("model");
overrides.add(new ModelOverride(predicates, model));
}
}
Collections.reverse(overrides);
models.put(key, new BlockModel(this, parent, ambientocclusion, guiLight, display, texture, elements, overrides));
} catch (Exception e) {
new ResourceLoadingException("Unable to load block model " + file.getAbsolutePath(), e).printStackTrace();
}
}
this.models.putAll(models);
}
use of com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class BlockModelRenderer method render.
public void render() {
try {
if (!lock.tryLock(0, TimeUnit.MILLISECONDS)) {
return;
}
} catch (InterruptedException e) {
}
renderModelButton.setEnabled(false);
reloadResourcesButton.setEnabled(false);
spinnerThreads.setEnabled(false);
String key = textFieldResourceKey.getText();
if (!key.contains(":")) {
key = "minecraft:" + key;
textFieldResourceKey.setText(key);
}
String finalKey = key;
keyHistory.removeIf(each -> each.equalsIgnoreCase(finalKey));
keyHistory.add(0, key);
historyIndex = 0;
currentHistoryKey = null;
int lastSlash = key.lastIndexOf("/");
String trimmedKey = key.substring(lastSlash < 0 ? (key.lastIndexOf(":") + 1) : lastSlash + 1);
Map<String, TextureResource> providedTextures = new HashMap<>();
Map<ModelOverrideType, Float> predicates = new EnumMap<>(ModelOverrideType.class);
SpawnEggTintData tintData = TintUtils.getSpawnEggTint(trimmedKey);
if (tintData != null) {
BufferedImage baseImage = resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "spawn_egg").getTexture();
BufferedImage overlayImage = resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "spawn_egg_overlay").getTexture(baseImage.getWidth(), baseImage.getHeight());
BufferedImage colorBase = ImageUtils.changeColorTo(ImageUtils.copyImage(baseImage), tintData.getBase());
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(overlayImage), tintData.getOverlay());
baseImage = ImageUtils.multiply(baseImage, colorBase);
overlayImage = ImageUtils.multiply(overlayImage, colorOverlay);
providedTextures.put(ResourceRegistry.SPAWN_EGG_PLACEHOLDER, new GeneratedTextureResource(baseImage));
providedTextures.put(ResourceRegistry.SPAWN_EGG_OVERLAY_PLACEHOLDER, new GeneratedTextureResource(overlayImage));
}
TintIndexData tintIndexData = TintUtils.getTintData(trimmedKey);
for (Entry<ModelOverrideType, JSpinner> entry : overrideSettings.entrySet()) {
float value = ((Number) entry.getValue().getValue()).floatValue();
if (value != 0F) {
predicates.put(entry.getKey(), value);
}
}
for (ValueTrios<Supplier<String>, JButton, JFileChooser> data : providedTextureSettings.values()) {
String texturePlaceholder = data.getFirst().get();
File file = data.getThird().getSelectedFile();
if (file != null && file.getName().endsWith(".png")) {
try {
BufferedImage image;
if (texturePlaceholder.equals(ResourceRegistry.SKIN_TEXTURE_PLACEHOLDER) || texturePlaceholder.equals(ResourceRegistry.SKIN_FULL_TEXTURE_PLACEHOLDER)) {
image = ModelUtils.convertToModernSkinTexture(ImageIO.read(file));
} else {
image = ImageIO.read(file);
}
providedTextures.put(texturePlaceholder, new GeneratedTextureResource(image));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
modelRenderer.reloadPoolSize();
long start = System.currentTimeMillis();
try {
RenderResult result = modelRenderer.render((int) spinnerWidth.getValue(), (int) spinnerHeight.getValue(), (int) spinnerWidth.getValue(), (int) spinnerHeight.getValue(), resourceManager, false, key, ModelDisplayPosition.GUI, predicates, providedTextures, tintIndexData, enchantedCheckBox.isSelected(), altPosBox.isSelected());
long end = System.currentTimeMillis();
if (result.isSuccessful()) {
renderedImage = result.getImage();
imagePanel.repaint();
renderTimesLabel.setText((end - start) + "ms");
lastRenderedKey = key;
} else {
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, GUIMain.createLabel("Render Rejected:\n" + result.getRejectedReason(), 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
}
} catch (Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, GUIMain.createLabel("An error occurred!\n" + sw, 13, Color.RED), title, JOptionPane.ERROR_MESSAGE);
}
renderModelButton.setEnabled(true);
reloadResourcesButton.setEnabled(true);
spinnerThreads.setEnabled(true);
lock.unlock();
}
use of com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType 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;
}
use of com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType 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;
}
use of com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class ItemRenderUtils method processItemForRendering.
public static ItemStackProcessResult processItemForRendering(OfflineICPlayer player, ItemStack item) throws IOException {
boolean requiresEnchantmentGlint = false;
XMaterial xMaterial = XMaterialUtils.matchXMaterial(item);
String directLocation = null;
if (xMaterial.equals(XMaterial.DEBUG_STICK)) {
requiresEnchantmentGlint = true;
} else if (xMaterial.equals(XMaterial.ENCHANTED_GOLDEN_APPLE)) {
requiresEnchantmentGlint = true;
} else if (xMaterial.equals(XMaterial.WRITTEN_BOOK)) {
requiresEnchantmentGlint = true;
} else if (xMaterial.equals(XMaterial.ENCHANTED_BOOK)) {
requiresEnchantmentGlint = true;
} else if (item.getEnchantments().size() > 0) {
requiresEnchantmentGlint = true;
}
TintIndexData tintIndexData = TintUtils.getTintData(xMaterial);
Map<ModelOverrideType, Float> predicates = new EnumMap<>(ModelOverrideType.class);
Map<String, TextureResource> providedTextures = new HashMap<>();
if (NBTEditor.contains(item, "CustomModelData")) {
int customModelData = NBTEditor.getInt(item, "CustomModelData");
predicates.put(ModelOverrideType.CUSTOM_MODEL_DATA, (float) customModelData);
}
if (xMaterial.equals(XMaterial.CHEST) || xMaterial.equals(XMaterial.TRAPPED_CHEST)) {
LocalDate time = LocalDate.now();
if (time.getMonth().equals(Month.DECEMBER) && (time.getDayOfMonth() == 24 || time.getDayOfMonth() == 25 || time.getDayOfMonth() == 26)) {
directLocation = ResourceRegistry.BUILTIN_ENTITY_MODEL_LOCATION + "christmas_chest";
}
} else if (xMaterial.isOneOf(Arrays.asList("CONTAINS:banner"))) {
BannerAssetResult bannerAsset = BannerGraphics.generateBannerAssets(item);
providedTextures.put(ResourceRegistry.BANNER_BASE_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(bannerAsset.getBase()));
providedTextures.put(ResourceRegistry.BANNER_PATTERNS_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(bannerAsset.getPatterns()));
} else if (xMaterial.equals(XMaterial.SHIELD)) {
BannerAssetResult shieldAsset = BannerGraphics.generateShieldAssets(item);
providedTextures.put(ResourceRegistry.SHIELD_BASE_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(shieldAsset.getBase()));
providedTextures.put(ResourceRegistry.SHIELD_PATTERNS_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(shieldAsset.getPatterns()));
} else if (xMaterial.equals(XMaterial.PLAYER_HEAD)) {
BufferedImage skinImage = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "steve").getTexture();
try {
String base64 = SkinUtils.getSkinValue(item.getItemMeta());
if (base64 != null) {
JSONObject json = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(base64)));
String value = (String) ((JSONObject) ((JSONObject) json.get("textures")).get("SKIN")).get("url");
skinImage = ImageUtils.downloadImage(value);
}
} catch (ParseException e) {
e.printStackTrace();
}
providedTextures.put(ResourceRegistry.SKIN_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(ModelUtils.convertToModernSkinTexture(skinImage)));
} else if (xMaterial.equals(XMaterial.ELYTRA)) {
int durability = item.getType().getMaxDurability() - (InteractiveChat.version.isLegacy() ? item.getDurability() : ((Damageable) item.getItemMeta()).getDamage());
if (durability <= 1) {
predicates.put(ModelOverrideType.BROKEN, 1F);
}
} else if (xMaterial.equals(XMaterial.CROSSBOW)) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
List<ItemStack> charged = meta.getChargedProjectiles();
if (charged != null && !charged.isEmpty()) {
predicates.put(ModelOverrideType.CHARGED, 1F);
ItemStack charge = charged.get(0);
XMaterial chargeType = XMaterialUtils.matchXMaterial(charge);
if (chargeType.equals(XMaterial.FIREWORK_ROCKET)) {
predicates.put(ModelOverrideType.FIREWORK, 1F);
}
}
} else if (xMaterial.equals(XMaterial.CLOCK)) {
ICPlayer onlinePlayer = player.getPlayer();
long time = ((onlinePlayer != null && onlinePlayer.isLocal() ? ((ICPlayer) player).getLocalPlayer().getPlayerTime() : Bukkit.getWorlds().get(0).getTime()) % 24000) - 6000;
if (time < 0) {
time += 24000;
}
double timePhase = (double) time / 24000;
predicates.put(ModelOverrideType.TIME, (float) (timePhase - 0.0078125));
} else if (xMaterial.equals(XMaterial.COMPASS)) {
double angle;
ICPlayer icplayer = player.getPlayer();
if (icplayer != null && icplayer.isLocal()) {
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16)) {
CompassMeta meta = (CompassMeta) item.getItemMeta();
Location target;
if (meta.hasLodestone()) {
Location lodestone = meta.getLodestone();
target = new Location(lodestone.getWorld(), lodestone.getBlockX() + 0.5, lodestone.getBlockY(), lodestone.getBlockZ() + 0.5, lodestone.getYaw(), lodestone.getPitch());
requiresEnchantmentGlint = true;
} else if (icplayer.getLocalPlayer().getWorld().getEnvironment().equals(Environment.NORMAL)) {
Location spawn = icplayer.getLocalPlayer().getWorld().getSpawnLocation();
target = new Location(spawn.getWorld(), spawn.getBlockX() + 0.5, spawn.getBlockY(), spawn.getBlockZ() + 0.5, spawn.getYaw(), spawn.getPitch());
} else {
target = null;
}
if (target != null && target.getWorld().equals(icplayer.getLocalPlayer().getWorld())) {
Location playerLocation = icplayer.getLocalPlayer().getEyeLocation();
playerLocation.setPitch(0);
Vector looking = playerLocation.getDirection();
Vector pointing = target.toVector().subtract(playerLocation.toVector());
pointing.setY(0);
double degree = VectorUtils.getBearing(looking, pointing);
if (degree < 0) {
degree += 360;
}
angle = degree / 360;
} else {
angle = RANDOM.nextDouble();
}
} else {
if (icplayer.getLocalPlayer().getWorld().getEnvironment().equals(Environment.NORMAL)) {
Location spawn = icplayer.getLocalPlayer().getWorld().getSpawnLocation();
Location target = new Location(spawn.getWorld(), spawn.getBlockX() + 0.5, spawn.getBlockY(), spawn.getBlockZ() + 0.5, spawn.getYaw(), spawn.getPitch());
Location playerLocation = icplayer.getLocalPlayer().getEyeLocation();
playerLocation.setPitch(0);
Vector looking = playerLocation.getDirection();
Vector pointing = target.toVector().subtract(playerLocation.toVector());
pointing.setY(0);
double degree = VectorUtils.getBearing(looking, pointing);
if (degree < 0) {
degree += 360;
}
angle = degree / 360;
} else {
angle = RANDOM.nextDouble();
}
}
} else {
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16)) {
CompassMeta meta = (CompassMeta) item.getItemMeta();
if (meta.hasLodestone()) {
requiresEnchantmentGlint = true;
}
}
angle = 0;
}
predicates.put(ModelOverrideType.ANGLE, (float) (angle - 0.015625));
} else if (xMaterial.equals(XMaterial.LIGHT)) {
int level = 15;
Object blockStateObj = item.getItemMeta().serialize().get("BlockStateTag");
if (blockStateObj != null && blockStateObj instanceof Map) {
Object levelObj = ((Map<?, Object>) blockStateObj).get("level");
if (levelObj != null) {
try {
level = Integer.parseInt(levelObj.toString().replace("i", ""));
} catch (NumberFormatException e) {
}
}
}
predicates.put(ModelOverrideType.LEVEL, (float) level / 16F);
} else if (item.getItemMeta() instanceof LeatherArmorMeta) {
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
Color color = new Color(meta.getColor().asRGB());
if (xMaterial.equals(XMaterial.LEATHER_HORSE_ARMOR)) {
BufferedImage itemImage = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + xMaterial.name().toLowerCase()).getTexture(32, 32);
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(itemImage), color);
itemImage = ImageUtils.multiply(itemImage, colorOverlay);
providedTextures.put(ResourceRegistry.LEATHER_HORSE_ARMOR_PLACEHOLDER, new GeneratedTextureResource(itemImage));
} else {
BufferedImage itemImage = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + xMaterial.name().toLowerCase()).getTexture(32, 32);
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(itemImage), color);
itemImage = ImageUtils.multiply(itemImage, colorOverlay);
if (xMaterial.name().contains("HELMET")) {
providedTextures.put(ResourceRegistry.LEATHER_HELMET_PLACEHOLDER, new GeneratedTextureResource(itemImage));
} else if (xMaterial.name().contains("CHESTPLATE")) {
providedTextures.put(ResourceRegistry.LEATHER_CHESTPLATE_PLACEHOLDER, new GeneratedTextureResource(itemImage));
} else if (xMaterial.name().contains("LEGGINGS")) {
providedTextures.put(ResourceRegistry.LEATHER_LEGGINGS_PLACEHOLDER, new GeneratedTextureResource(itemImage));
} else if (xMaterial.name().contains("BOOTS")) {
providedTextures.put(ResourceRegistry.LEATHER_BOOTS_PLACEHOLDER, new GeneratedTextureResource(itemImage));
}
}
} else if (item.getItemMeta() instanceof PotionMeta) {
if (xMaterial.equals(XMaterial.TIPPED_ARROW)) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
PotionType potiontype = InteractiveChat.version.isOld() ? Potion.fromItemStack(item).getType() : meta.getBasePotionData().getType();
BufferedImage tippedArrowHead = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "tipped_arrow_head").getTexture(32, 32);
int color;
try {
if (meta.hasColor()) {
color = meta.getColor().asRGB();
} else {
color = PotionUtils.getPotionBaseColor(potiontype);
}
} catch (Throwable e) {
color = PotionUtils.getPotionBaseColor(PotionType.WATER);
}
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(tippedArrowHead), color);
tippedArrowHead = ImageUtils.multiply(tippedArrowHead, colorOverlay);
providedTextures.put(ResourceRegistry.TIPPED_ARROW_HEAD_PLACEHOLDER, new GeneratedTextureResource(tippedArrowHead));
} else {
PotionMeta meta = (PotionMeta) item.getItemMeta();
PotionType potiontype = InteractiveChat.version.isOld() ? Potion.fromItemStack(item).getType() : meta.getBasePotionData().getType();
BufferedImage potionOverlay = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "potion_overlay").getTexture(32, 32);
int color;
try {
if (meta.hasColor()) {
color = meta.getColor().asRGB();
} else {
color = PotionUtils.getPotionBaseColor(potiontype);
}
} catch (Throwable e) {
color = PotionUtils.getPotionBaseColor(PotionType.WATER);
}
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(potionOverlay), color);
potionOverlay = ImageUtils.multiply(potionOverlay, colorOverlay);
providedTextures.put(ResourceRegistry.POTION_OVERLAY_PLACEHOLDER, new GeneratedTextureResource(potionOverlay));
if (potiontype != null) {
if (!(potiontype.name().equals("WATER") || potiontype.name().equals("AWKWARD") || potiontype.name().equals("MUNDANE") || potiontype.name().equals("THICK") || potiontype.name().equals("UNCRAFTABLE"))) {
requiresEnchantmentGlint = true;
}
}
}
} else if (xMaterial.isOneOf(Arrays.asList("CONTAINS:spawn_egg"))) {
SpawnEggTintData tintData = TintUtils.getSpawnEggTint(xMaterial);
if (tintData != null) {
BufferedImage baseImage = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "spawn_egg").getTexture();
BufferedImage overlayImage = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ITEM_TEXTURE_LOCATION + "spawn_egg_overlay").getTexture(baseImage.getWidth(), baseImage.getHeight());
BufferedImage colorBase = ImageUtils.changeColorTo(ImageUtils.copyImage(baseImage), tintData.getBase());
BufferedImage colorOverlay = ImageUtils.changeColorTo(ImageUtils.copyImage(overlayImage), tintData.getOverlay());
baseImage = ImageUtils.multiply(baseImage, colorBase);
overlayImage = ImageUtils.multiply(overlayImage, colorOverlay);
providedTextures.put(ResourceRegistry.SPAWN_EGG_PLACEHOLDER, new GeneratedTextureResource(baseImage));
providedTextures.put(ResourceRegistry.SPAWN_EGG_OVERLAY_PLACEHOLDER, new GeneratedTextureResource(overlayImage));
}
} else if (InteractiveChat.version.isLegacy() && xMaterial.isOneOf(Arrays.asList("CONTAINS:bed"))) {
String colorName = xMaterial.name().replace("_BED", "").toLowerCase();
BufferedImage bedTexture = InteractiveChatDiscordSrvAddon.plugin.resourceManager.getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "bed/" + colorName).getTexture();
providedTextures.put(ResourceRegistry.LEGACY_BED_TEXTURE_PLACEHOLDER, new GeneratedTextureResource(bedTexture));
}
return new ItemStackProcessResult(requiresEnchantmentGlint, predicates, providedTextures, tintIndexData, directLocation);
}
Aggregations