use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.
the class IconMenuInventory method createItemStack.
protected ItemStack createItemStack(IconMenuItem icon) {
// TODO Check if this works properly
ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount()));
if (is == null) {
is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE));
}
if (is.getTag() == null) {
is.setTag(new CompoundTag());
}
if (icon.getBukkitMeta() != null) {
try {
applyToItemMethod.invoke(icon.getBukkitMeta(), is.getTag());
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
// add enchantment glowing
if (icon.isGlowing()) {
TagCompound enchTag = new TagCompound();
enchTag.put("id", new TagString("minecraft:feather_falling"));
enchTag.put("lvl", new TagShort(1));
TagList enchList = new TagList();
enchList.addTag(enchTag);
is.getTag().put("Enchantments", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
} else {
is.getTag().remove("Enchantments");
}
// hide item attributes like attack damage
is.getTag().putInt("HideFlags", 63);
// Prepare display tag
CompoundTag display;
if (is.getTag().contains("display")) {
display = is.getTag().getCompound("display");
} else {
display = new CompoundTag();
is.getTag().put("display", display);
}
// set Title
if (!icon.getTitle().equals("")) {
display.putString("Name", "{\"text\":\"" + icon.getTitle() + "\"}");
}
if (icon.getLore().size() > 0) {
// set Lore
ListTag loreTag = new ListTag();
display.put("Lore", loreTag);
for (String loreLine : icon.getLore()) {
Component cm = CraftChatMessage.fromStringOrNull(loreLine);
loreTag.add(StringTag.valueOf(Component.Serializer.toJson(cm)));
}
}
if (icon.hasMeta()) {
TagCompound tag = new TagCompound();
icon.getMeta().applyTo(tag);
CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag);
for (String key : vanillaTag.getAllKeys()) {
is.getTag().put(key, vanillaTag.get(key));
}
}
if (icon.getTags() != null) {
CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
for (String key : vanillaTag.getAllKeys()) {
is.getTag().put(key, vanillaTag.get(key));
}
}
return is;
}
use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.
the class ItemStackComparator method compareTagData.
public static boolean compareTagData(ItemStack i1, ItemStack i2) {
if (i1 == null || i2 == null) {
return false;
}
if (i1.hasItemMeta() && i2.hasItemMeta()) {
CompoundTag tag1 = CraftItemStack.asNMSCopy(i1).getTag();
CompoundTag tag2 = CraftItemStack.asNMSCopy(i2).getTag();
if (tag1 != null) {
if (tag1.equals(tag2)) {
return true;
} else {
i1 = CraftItemStack.asBukkitCopy(CraftItemStack.asNMSCopy(i1));
tag1 = CraftItemStack.asNMSCopy(i1).getTag();
return tag1.equals(tag2);
}
}
return false;
}
return i1.hasItemMeta() == i2.hasItemMeta();
}
use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method itemStackToCompound.
public static TagCompound itemStackToCompound(ItemStack itemStack) {
CompoundTag tagCompound = new CompoundTag();
itemStack.save(tagCompound);
return (TagCompound) vanillaCompoundToCompound(tagCompound);
}
use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.
the class ItemStackComparator method compareTagData.
public static boolean compareTagData(ItemStack i1, ItemStack i2) {
if (i1 == null || i2 == null) {
return false;
}
if (i1.hasItemMeta() && i2.hasItemMeta()) {
CompoundTag tag1 = CraftItemStack.asNMSCopy(i1).getTag();
CompoundTag tag2 = CraftItemStack.asNMSCopy(i2).getTag();
if (tag1 != null) {
if (tag1.equals(tag2)) {
return true;
} else {
i1 = CraftItemStack.asBukkitCopy(CraftItemStack.asNMSCopy(i1));
tag1 = CraftItemStack.asNMSCopy(i1).getTag();
return tag1.equals(tag2);
}
}
return false;
}
return i1.hasItemMeta() == i2.hasItemMeta();
}
use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class ForgeChunkManager method readForgeForcedChunks.
/**
* Reads the forge forced chunks from the NBT compound. Format is List{modid, List{ChunkPos, List{BlockPos}, List{UUID}}}
*
* @apiNote Internal
*/
public static void readForgeForcedChunks(CompoundTag nbt, TicketTracker<BlockPos> blockForcedChunks, TicketTracker<UUID> entityForcedChunks) {
ListTag forcedChunks = nbt.getList("ForgeForced", Tag.TAG_COMPOUND);
for (int i = 0; i < forcedChunks.size(); i++) {
CompoundTag forcedEntry = forcedChunks.getCompound(i);
String modId = forcedEntry.getString("Mod");
if (ModList.get().isLoaded(modId)) {
ListTag modForced = forcedEntry.getList("ModForced", Tag.TAG_COMPOUND);
for (int j = 0; j < modForced.size(); j++) {
CompoundTag modEntry = modForced.getCompound(j);
long chunkPos = modEntry.getLong("Chunk");
readBlockForcedChunks(modId, chunkPos, modEntry, "Blocks", blockForcedChunks.chunks);
readBlockForcedChunks(modId, chunkPos, modEntry, "TickingBlocks", blockForcedChunks.tickingChunks);
readEntityForcedChunks(modId, chunkPos, modEntry, "Entities", entityForcedChunks.chunks);
readEntityForcedChunks(modId, chunkPos, modEntry, "TickingEntities", entityForcedChunks.tickingChunks);
}
} else {
LOGGER.warn("Found chunk loading data for mod {} which is currently not available or active - it will be removed from the world save.", modId);
}
}
}
Aggregations