@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; }
@SuppressWarnings("unchecked") public <T extends NBT> NBTList<T> getTagListOfType(String key, NBTType<T> type) { NBTList<? extends NBT> list = getTagOfType(key, NBTType.LIST); if ((list != null) && (list.getTagsType() == type)) { return (NBTList<T>) list; } return null; }
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; }
@Test public void testEq() { Assertions.assertEquals(new NBTByte((byte) 5), new NBTByte((byte) 5)); Assertions.assertEquals(new NBTShort((short) 5), new NBTShort((short) 5)); Assertions.assertEquals(new NBTInt(5), new NBTInt(5)); Assertions.assertEquals(new NBTLong(5), new NBTLong(5)); Assertions.assertEquals(new NBTFloat(5), new NBTFloat(5)); Assertions.assertEquals(new NBTDouble(5), new NBTDouble(5)); Assertions.assertEquals(new NBTString("5"), new NBTString("5")); }
@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; }
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; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testList() { NBTList<NBTInt> list = new NBTList<>(NBTType.INT); list.addTag(new NBTInt(30)); list.addTag(new NBTInt(30)); Assertions.assertTrue(list.getTagsType() == NBTType.INT); Assertions.assertTrue(list.size() == 2); Assertions.assertThrows(IllegalArgumentException.class, () -> ((NBTList) list).addTag(new NBTShort((short) 0))); }
@Override public TileEntity apply(Position position) { NBTCompound tag = new NBTCompound(); tag.setTag("color", new NBTInt(color)); return new TileEntity(TileEntityType.BED, position, tag); }
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; }
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; }
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; }
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())); }
@SuppressWarnings("unchecked") public NBTList<NBTNumber> getNumberTagList(String key) { NBTList<? extends NBT> list = getTagOfType(key, NBTType.LIST); if ((list != null) && NBTNumber.class.isAssignableFrom(list.getTagsType().getNBTTagClass())) { return (NBTList<NBTNumber>) list; } return null; }
@Override public NetworkItemStack remap(ProtocolVersion version, String locale, NetworkItemStack itemstack) { NBTNumber map; if ((itemstack.getNBT() != null) && ((map = itemstack.getNBT().getNumberTag("map")) != null)) { itemstack.setLegacyData(map.getAsInt()); } return itemstack; }
public static String getValueOrDefault(NBTString tag, String defaultVal) { return tag != null ? tag.getValue() : defaultVal; }
public static String getValueOrNull(NBTString tag) { return getValueOrDefault(tag, null); }
@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) { NBTNumber damage; if ((itemstack.getNBT() != null) && ((damage = itemstack.getNBT().getNumberTag("Damage")) != null)) { itemstack.setLegacyData(damage.getAsInt()); } 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; }