@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { tag.setTag(CommonNBT.MODERN_ENCHANTMENTS, filterEnchantList(version, tag.getTagListOfType(CommonNBT.MODERN_ENCHANTMENTS, NBTType.COMPOUND))); tag.setTag(CommonNBT.BOOK_ENCHANTMENTS, filterEnchantList(version, tag.getTagListOfType(CommonNBT.BOOK_ENCHANTMENTS, NBTType.COMPOUND))); return tag; }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTList<NBTCompound> enchTag = tag.getTagListOfType(CommonNBT.LEGACY_ENCHANTMENTS, NBTType.COMPOUND); if (enchTag != null) { tag.removeTag(CommonNBT.LEGACY_ENCHANTMENTS); tag.setTag(CommonNBT.MODERN_ENCHANTMENTS, remapEnchantList(enchTag)); } NBTList<NBTCompound> bookEnch = tag.getTagListOfType(CommonNBT.BOOK_ENCHANTMENTS, NBTType.COMPOUND); if (bookEnch != null) { tag.setTag(CommonNBT.BOOK_ENCHANTMENTS, remapEnchantList(bookEnch)); } return tag; }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTList<NBTCompound> enchTag = tag.getTagListOfType(CommonNBT.MODERN_ENCHANTMENTS, NBTType.COMPOUND); if (enchTag != null) { tag.removeTag(CommonNBT.MODERN_ENCHANTMENTS); tag.setTag(CommonNBT.LEGACY_ENCHANTMENTS, remapEnchantList(enchTag)); } NBTList<NBTCompound> bookEnch = tag.getTagListOfType(CommonNBT.BOOK_ENCHANTMENTS, NBTType.COMPOUND); if (bookEnch != null) { tag.setTag(CommonNBT.BOOK_ENCHANTMENTS, remapEnchantList(bookEnch)); } return tag; }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { if (tag.getTagListOfType("pages", NBTType.STRING) == null) { NBTList<NBTString> pages = new NBTList<>(NBTType.STRING); pages.addTag(new NBTString("")); tag.setTag("pages", pages); } return tag; }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTList<NBTString> pages = tag.getTagListOfType("pages", NBTType.STRING); if (pages != null) { NBTList<NBTString> newPages = new NBTList<>(NBTType.STRING); for (NBTString page : pages.getTags()) { newPages.addTag(new NBTString(ChatAPI.fromJSON(page.getValue()).toLegacyText(locale))); } tag.setTag("pages", newPages); } return tag; }
public static GameProfile deserialize(NBTCompound tag) { String name = NBTString.getValueOrNull(tag.getTagOfType(NAME_KEY, NBTType.STRING)); UUID uuid = null; try { uuid = UUID.fromString(NBTString.getValueOrNull(tag.getTagOfType(UUID_KEY, NBTType.STRING))); } catch (Throwable t) { } if (StringUtils.isEmpty(name) && (uuid == null)) { return null; } GameProfile gameProfile = new GameProfile(uuid, name); NBTCompound propertiesTag = tag.getTagOfType(PROPERTIES_KEY, NBTType.COMPOUND); if (propertiesTag != null) { for (String propertyName : propertiesTag.getTagNames()) { NBTList<NBTCompound> propertiesListTag = propertiesTag.getTagListOfType(propertyName, NBTType.COMPOUND); if (propertiesListTag != null) { for (NBTCompound propertyTag : propertiesListTag.getTags()) { gameProfile.addProperty(new ProfileProperty( propertyName, NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_VALUE_KEY, NBTType.STRING)), NBTString.getValueOrNull(propertyTag.getTagOfType(PROPERTY_SIGNATURE_KEY, NBTType.STRING)) )); } } } } return gameProfile; }
NBTList<NBTString> loreNBT = displayNBT.getTagListOfType(CommonNBT.DISPLAY_LORE, NBTType.STRING); if (loreNBT == null) { loreNBT = new NBTList<>(NBTType.STRING);
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { return itemstack; } String potion = NBTString.getValueOrNull(tag.getTagOfType("Potion", NBTType.STRING)); NBTList<NBTCompound> customPotionEffects = tag.getTagListOfType("CustomPotionEffects", NBTType.COMPOUND); if ((customPotionEffects != null) && (customPotionEffects.size() >= 1)) { potion = PotionData.getNameById(customPotionEffects.getTag(0).getNumberTag("Id").getAsInt()); } if (potion != null) { itemstack.setLegacyData(LegacyPotionId.toLegacyId(potion, isThrowablePotion)); String basicTypeName = LegacyPotionId.getBasicTypeName(potion); if (basicTypeName != null) { NBTCompound display = CommonNBT.getOrCreateDisplayTag(tag); display.setTag(CommonNBT.DISPLAY_NAME, new NBTString(ChatAPI.toJSON(new TextComponent(TranslationAPI.translate(locale, basicTypeName))))); } } return itemstack; }
protected RecyclableCollection<ServerBoundPacketData> transformBookSign() { ProtocolVersion version = connection.getVersion(); String locale = connection.getCache().getAttributesCache().getLocale(); NetworkItemStack book = ItemStackSerializer.readItemStack(data, version, locale); if (!book.isNull()) { book.setTypeId(ItemMaterialLookup.getRuntimeId(Material.WRITABLE_BOOK)); if (connection.getVersion() == ProtocolVersion.MINECRAFT_1_8) { NBTCompound rootTag = book.getNBT(); if (rootTag != null) { NBTList<NBTString> pages = rootTag.getTagListOfType("pages", NBTType.STRING); if (pages != null) { NBTList<NBTString> newPages = new NBTList<>(NBTType.STRING); for (NBTString page : pages.getTags()) { newPages.addTag(new NBTString(ChatAPI.fromJSON(page.getValue()).toLegacyText(locale))); } rootTag.setTag("pages", newPages); book.setNBT(rootTag); } } } return RecyclableSingletonList.create(MiddleEditBook.create(book, true, UsedHand.MAIN)); } else { return RecyclableEmptyList.get(); } }
@Test public void testCompound() { String testtagname = "test"; NBTCompound compound = new NBTCompound(); compound.setTag(testtagname, new NBTShort((short) 20)); String testlisttagname = "testlist"; NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); compound.setTag(testlisttagname, list); Assertions.assertNotNull(compound.getTag(testtagname)); Assertions.assertNotNull(compound.getTagOfType(testtagname, NBTType.SHORT)); Assertions.assertNull(compound.getTagOfType(testtagname, NBTType.INT)); Assertions.assertNotNull(compound.getNumberTag(testtagname)); Assertions.assertNotNull(compound.getTag(testlisttagname)); Assertions.assertNotNull(compound.getTagOfType(testlisttagname, NBTType.LIST)); Assertions.assertNull(compound.getTagOfType(testlisttagname, NBTType.DOUBLE)); Assertions.assertNotNull(compound.getTagListOfType(testlisttagname, NBTType.INT)); Assertions.assertNull(compound.getTagListOfType(testlisttagname, NBTType.SHORT)); Assertions.assertNotNull(compound.getNumberTagList(testlisttagname)); }