Skip to content

Commit

Permalink
Fixed some item model keys on 1.12.2 and below
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
LOOHP committed Jan 6, 2025
1 parent 0d5cd10 commit f34f773
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.loohp.interactivechatdiscordsrvaddon.graphics;

import com.loohp.interactivechat.InteractiveChat;
import com.loohp.interactivechat.libs.net.kyori.adventure.key.Key;
import com.loohp.interactivechat.objectholders.ICMaterial;
import com.loohp.interactivechatdiscordsrvaddon.InteractiveChatDiscordSrvAddon;
Expand All @@ -43,13 +44,19 @@

public class BannerGraphics {

@SuppressWarnings("deprecation")
public static BannerAssetResult generateBannerAssets(ItemStack item) {
BufferedImage baseImage = InteractiveChatDiscordSrvAddon.plugin.getResourceManager().getTextureManager().getTexture(ResourceRegistry.ENTITY_TEXTURE_LOCATION + "banner_base").getTexture(64, 64);
BufferedImage patternsImage = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);

ICMaterial icMaterial = ICMaterial.from(item);
String colorName = icMaterial.name().replace("_BANNER", "");
Color baseColor = new Color(DyeColor.valueOf(colorName.toUpperCase()).getColor().asRGB());
Color baseColor;
if (InteractiveChat.version.isLegacy()) {
baseColor = new Color(DyeColor.getByDyeData(item.getData().getData()).getColor().asRGB());
} else {
ICMaterial icMaterial = ICMaterial.from(item);
String colorName = icMaterial.name().replace("_BANNER", "");
baseColor = new Color(DyeColor.valueOf(colorName.toUpperCase()).getColor().asRGB());
}

BufferedImage baseTint = new BufferedImage(42, 41, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = baseTint.createGraphics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.loohp.interactivechat.utils.InventoryUtils;
import com.loohp.interactivechat.utils.ItemStackUtils;
import com.loohp.interactivechat.utils.LanguageUtils;
import com.loohp.interactivechat.utils.MCVersion;
import com.loohp.interactivechat.utils.PlaceholderParser;
import com.loohp.interactivechatdiscordsrvaddon.InteractiveChatDiscordSrvAddon;
import com.loohp.interactivechatdiscordsrvaddon.debug.Debug;
Expand Down Expand Up @@ -415,7 +416,7 @@ public static Inventory getBlockInventory(ItemStack item) {
BlockState bsm = ((BlockStateMeta) item.getItemMeta()).getBlockState();
if (bsm instanceof InventoryHolder) {
Inventory container = ((InventoryHolder) bsm).getInventory();
if (!container.isEmpty()) {
if (!isInventoryEmpty(container)) {
inv = Bukkit.createInventory(ICInventoryHolder.INSTANCE, InventoryUtils.toMultipleOf9(container.getSize()));
for (int j = 0; j < container.getSize(); j++) {
if (container.getItem(j) != null) {
Expand All @@ -430,6 +431,14 @@ public static Inventory getBlockInventory(ItemStack item) {
return inv;
}

private static boolean isInventoryEmpty(Inventory inventory) {
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16_2)) {
return inventory.isEmpty();
} else {
return Arrays.stream(inventory.getContents()).noneMatch(i -> i != null && !i.getType().equals(Material.AIR));
}
}

private static BiConsumer<GenericComponentInteractionCreateEvent, List<DiscordMessageContent>> getBookHandler(UUID interactionUuid, Color color, List<Supplier<BufferedImage>> imageSuppliers, byte[][] cachedImages) {
Map<String, AtomicInteger> currentPages = new ConcurrentHashMap<>();
List<SelectOption> selectOptions = IntStream.range(1, cachedImages.length + 1).mapToObj(i -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.loohp.interactivechat.objectholders.ICMaterial;
import com.loohp.interactivechat.utils.ChatColorUtils;
import com.loohp.interactivechat.utils.MCVersion;
import com.loohp.interactivechatdiscordsrvaddon.InteractiveChatDiscordSrvAddon;
import com.loohp.interactivechatdiscordsrvaddon.debug.Debug;
import com.loohp.interactivechatdiscordsrvaddon.graphics.ImageUtils;
import com.loohp.interactivechatdiscordsrvaddon.registry.ResourceRegistry;
import com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelFace.ModelFaceSide;
Expand All @@ -37,6 +39,7 @@
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -212,6 +215,7 @@ public class ModelUtils {
LEGACY_MODEL_NAME.put("RED_DYE", "dye_red");
LEGACY_MODEL_NAME.put("SALMON_SPAWN_EGG", "spawn_egg");
LEGACY_MODEL_NAME.put("SHEEP_SPAWN_EGG", "spawn_egg");
LEGACY_MODEL_NAME.put("SHORT_GRASS", "tall_grass");
LEGACY_MODEL_NAME.put("SHULKER_SPAWN_EGG", "spawn_egg");
LEGACY_MODEL_NAME.put("OAK_SIGN", "sign");
LEGACY_MODEL_NAME.put("SILVERFISH_SPAWN_EGG", "spawn_egg");
Expand All @@ -231,6 +235,7 @@ public class ModelUtils {
LEGACY_MODEL_NAME.put("SUGAR_CANE", "reeds");
LEGACY_MODEL_NAME.put("TERRACOTTA", "hardened_clay");
LEGACY_MODEL_NAME.put("TOTEM_OF_UNDYING", "totem");
LEGACY_MODEL_NAME.put("TROPICAL_FISH", "clownfish");
LEGACY_MODEL_NAME.put("TROPICAL_FISH_SPAWN_EGG", "spawn_egg");
LEGACY_MODEL_NAME.put("TURTLE_SPAWN_EGG", "spawn_egg");
LEGACY_MODEL_NAME.put("VEX_SPAWN_EGG", "spawn_egg");
Expand Down Expand Up @@ -265,9 +270,26 @@ public static String getNamespace(ICMaterial icMaterial) {
return material.getKey().getNamespace();
}

@SuppressWarnings("RedundantIfStatement")
private static boolean shouldUseLegacyModelName(ICMaterial icMaterial) {
if (!InteractiveChat.version.isLegacy()) {
return false;
}
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_11) && icMaterial.isOneOf(Collections.singletonList("CONTAINS:shulker_box"))) {
return false;
}
return true;
}

public static String getItemModelKey(ICMaterial icMaterial) {
if (InteractiveChat.version.isLegacy()) {
if (InteractiveChatDiscordSrvAddon.debug) {
Debug.debug("Item Model Key: " + icMaterial.parseXMaterial().name() + " | " + icMaterial.parseMaterial().name());
}
if (shouldUseLegacyModelName(icMaterial)) {
String legacyKey = LEGACY_MODEL_NAME.get(icMaterial.name());
if (InteractiveChatDiscordSrvAddon.debug) {
Debug.debug("Item Model Legacy Key: " + legacyKey);
}
if (legacyKey != null) {
return legacyKey.toLowerCase();
}
Expand Down

0 comments on commit f34f773

Please sign in to comment.