public static NBTCompound getOrCreateDisplayTag(NBTCompound rootTag) { NBTCompound display = rootTag.getTagOfType(DISPLAY, NBTType.COMPOUND); if (display == null) { display = new NBTCompound(); rootTag.setTag(DISPLAY, display); } return display; }
@Override public TileEntity apply(Position position) { NBTCompound tag = new NBTCompound(); tag.setTag("color", new NBTInt(color)); return new TileEntity(TileEntityType.BED, position, tag); }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { tag = new NBTCompound(); itemstack.setNBT(tag); } tag.setTag("Damage", new NBTInt(itemstack.getLegacyData())); return itemstack; }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { itemstack.setTypeId(ItemMaterialLookup.getRuntimeId(Material.PLAYER_HEAD)); NBTCompound wrapper = new NBTCompound(); wrapper.setTag("SkullOwner", createTag()); itemstack.setNBT(wrapper); return itemstack; }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTCompound tag = itemstack.getNBT(); if (tag == null) { tag = new NBTCompound(); itemstack.setNBT(tag); } tag.setTag("map", new NBTInt(itemstack.getLegacyData())); return itemstack; }
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; }
NBTType.COMPOUND, 10, stream -> { NBTCompound compound = new NBTCompound(); NBTType<?> valueType = null; while ((valueType = readTagType(stream)) != NBTType.END) {
@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; }
NBTCompound nbt = itemstack.getNBT(); if (nbt == null) { nbt = new NBTCompound();
@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)); }