9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

feat: add item model id for item serializer

This commit is contained in:
LoJoSho
2025-03-24 15:40:45 -05:00
parent a50faee7fc
commit 75c3d4b19a
3 changed files with 25 additions and 2 deletions

View File

@@ -78,7 +78,6 @@ allprojects {
// Included externally
compileOnly("com.mojang:authlib:3.13.56")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:26.0.1")
compileOnly("io.th0rgal:oraxen:1.182.0")
compileOnly("com.nexomc:nexo:1.0.0")

View File

@@ -16,3 +16,7 @@ tasks {
filteringCharset = Charsets.UTF_8.name()
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
}

View File

@@ -2,6 +2,9 @@ package me.lojosho.hibiscuscommons.config.serializer;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandler;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.*;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.*;
@@ -35,6 +38,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
private static final String GLOWING = "glowing";
private static final String LORE = "lore";
private static final String MODEL_DATA = "model-data";
private static final String MODEL_ID = "model-id";
private static final String NBT_TAGS = "nbt-tag";
private static final String ENCHANTS = "enchants";
private static final String ITEM_FLAGS = "item-flags";
@@ -58,6 +62,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
final ConfigurationNode glowingNode = source.node(GLOWING);
final ConfigurationNode loreNode = source.node(LORE);
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
final ConfigurationNode modelIdNode = source.node(MODEL_ID);
final ConfigurationNode nbtNode = source.node(NBT_TAGS);
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
@@ -87,7 +92,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
if (!glowingNode.virtual()) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
itemMeta.addEnchant(Enchantment.UNBREAKING, 1, true);
}
if (!loreNode.virtual()) {
if (HibiscusCommonsPlugin.isOnPaper())
@@ -98,6 +103,21 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
}
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
if (NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_4) && !modelIdNode.virtual()) {
String itemModelId = modelIdNode.getString("");
String stringKey = HibiscusCommonsPlugin.getInstance().getName();
if (itemModelId.contains(":")) {
String[] split = itemModelId.split(":");
itemModelId = split[1];
stringKey = split[0];
}
if (!itemModelId.isEmpty()) {
NamespacedKey key = new NamespacedKey(stringKey, itemModelId);
itemMeta.setItemModel(key);
} else {
MessagesUtil.sendDebugMessages("Could not find item model id for " + stringKey + " in " + itemModelId);
}
}
if (!nbtNode.virtual()) {
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {