@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTCompound displayTag = tag.getTagOfType(CommonNBT.DISPLAY, NBTType.COMPOUND); if (displayTag != null) { NBTString displayNameTag = displayTag.getTagOfType(CommonNBT.DISPLAY_NAME, NBTType.STRING); if (displayNameTag != null) { displayTag.setTag(CommonNBT.DISPLAY_NAME, new NBTString(ChatAPI.fromJSON(displayNameTag.getValue()).toLegacyText(locale))); } } return tag; }
public static String getValueOrNull(NBTString tag) { return getValueOrDefault(tag, null); }
@Override public void accept(TileEntity tile) { tile.getNBT().setTag("id", new NBTString(name)); }
@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; }
public static String getValueOrDefault(NBTString tag, String defaultVal) { return tag != null ? tag.getValue() : defaultVal; }
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; }
@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; }
public TileEntity(NBTCompound fullNbt) { this.type = TileEntityType.getByRegistryId(fullNbt.getTagOfType("id", NBTType.STRING).getValue()); this.position = new Position(fullNbt.getNumberTag("x").getAsInt(), fullNbt.getNumberTag("y").getAsInt(), fullNbt.getNumberTag("z").getAsInt()); this.nbt = fullNbt; }
protected NBTList<NBTCompound> remapEnchantList(NBTList<NBTCompound> oldList) { NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { Enchantment ench = Enchantment.getByKey(NamespacedKeyUtils.fromString(NBTString.getValueOrNull(enchData.getTagOfType("id", NBTType.STRING)))); if (ench != null) { enchData.setTag("id", new NBTShort(LegacyEnchantmentId.getId(ench))); newList.addTag(enchData); } } return newList; }
@Override public NBTCompound remapTag(ProtocolVersion version, String locale, NetworkItemStack itemstack, NBTCompound tag) { NBTCompound displayTag = tag.getTagOfType(CommonNBT.DISPLAY, NBTType.COMPOUND); if (displayTag != null) { NBTString displayNameTag = displayTag.getTagOfType(CommonNBT.DISPLAY_NAME, NBTType.STRING); if (displayNameTag != null) { displayTag.setTag(CommonNBT.DISPLAY_NAME, new NBTString(ChatAPI.toJSON(new TextComponent(displayNameTag.getValue())))); } } return tag; }
public static NBTCompound serialize(GameProfile gameProfile) { NBTCompound tag = new NBTCompound(); if (!StringUtils.isEmpty(gameProfile.getName())) { tag.setTag(NAME_KEY, new NBTString(gameProfile.getName())); } if (gameProfile.getUUID() != null) { tag.setTag(UUID_KEY, new NBTString(gameProfile.getUUID().toString())); } if (!gameProfile.getProperties().isEmpty()) { NBTCompound propertiesTag = new NBTCompound(); for (Entry<String, Set<ProfileProperty>> entry : gameProfile.getProperties().entrySet()) { NBTList<NBTCompound> propertiesListTag = new NBTList<>(NBTType.COMPOUND); for (ProfileProperty property : entry.getValue()) { NBTCompound propertyTag = new NBTCompound(); propertyTag.setTag(PROPERTY_VALUE_KEY, new NBTString(property.getValue())); if (property.hasSignature()) { propertyTag.setTag(PROPERTY_SIGNATURE_KEY, new NBTString(property.getSignature())); } propertiesListTag.addTag(propertyTag); } propertiesTag.setTag(entry.getKey(), propertiesListTag); } tag.setTag(PROPERTIES_KEY, propertiesTag); } return tag; }
public static String[] getSignLines(NBTCompound tag) { String[] lines = new String[4]; for (int i = 0; i < lines.length; i++) { lines[i] = NBTString.getValueOrDefault(tag.getTagOfType("Text" + (i + 1), NBTType.STRING), ""); } return lines; }
@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 void remap(NBTCompound tag, String tagname, String newtagname) { NBTCompound gameprofileTag = tag.getTagOfType(tagname, NBTType.COMPOUND); if (gameprofileTag != null) { GameProfile gameprofile = GameProfileSerializer.deserialize(gameprofileTag); if (gameprofile.getName() != null) { tag.setTag(newtagname, new NBTString(gameprofile.getName())); } else { tag.removeTag(tagname); } } }
protected NBTList<NBTCompound> filterEnchantList(ProtocolVersion version, NBTList<NBTCompound> oldList) { if (oldList == null) { return null; } GenericSkippingTable<String> enchSkip = GenericIdSkipper.ENCHANT.getTable(version); NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { if (!enchSkip.shouldSkip(NBTString.getValueOrDefault(enchData.getTagOfType("id", NBTType.STRING), ""))) { newList.addTag(enchData); } } return newList; }
registerType(NBTType.FLOAT, 5, stream -> new NBTFloat(stream.readFloat()), (stream, tag) -> stream.writeFloat(tag.getAsFloat())); registerType(NBTType.DOUBLE, 6, stream -> new NBTDouble(stream.readDouble()), (stream, tag) -> stream.writeDouble(tag.getAsDouble())); registerType(NBTType.STRING, 8, stream -> new NBTString(stream.readUTF()), (stream, tag) -> stream.writeUTF(tag.getValue())); registerType( NBTType.BYTE_ARRAY, 7,
protected NBTList<NBTCompound> remapEnchantList(NBTList<NBTCompound> oldList) { NBTList<NBTCompound> newList = new NBTList<>(NBTType.COMPOUND); for (NBTCompound enchData : oldList.getTags()) { NBTNumber enchId = enchData.getNumberTag("id"); if (enchId != null) { Enchantment ench = LegacyEnchantmentId.getById(enchId.getAsInt()); if (ench != null) { enchData.setTag("id", new NBTString(ench.getKey().toString())); newList.addTag(enchData); } } } return newList; }
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(); } }
public TileEntity(TileEntityType type, Position position, NBTCompound nbt) { this.type = type; this.position = position; this.nbt = nbt; this.nbt.setTag("id", new NBTString(type.getRegistryId())); this.nbt.setTag("x", new NBTInt(position.getX())); this.nbt.setTag("y", new NBTInt(position.getY())); this.nbt.setTag("z", new NBTInt(position.getZ())); }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { int data = itemstack.getLegacyData(); String name = LegacyPotionId.fromLegacyId(data); if (!StringUtils.isEmpty(name)) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { tag = new NBTCompound(); itemstack.setNBT(tag); } tag.setTag("Potion", new NBTString(name)); itemstack.setTypeId(ItemMaterialLookup.getRuntimeId(LegacyPotionId.isThrowable(data) ? Material.SPLASH_POTION : Material.POTION)); } return itemstack; }