Java Code Examples for com.github.steveice10.opennbt.tag.builtin.CompoundTag#contains()
The following examples show how to use
com.github.steveice10.opennbt.tag.builtin.CompoundTag#contains() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BannerBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); int bannerColor = BlockStateValues.getBannerColor(blockState); if (bannerColor != -1) { tags.add(new IntTag("Base", 15 - bannerColor)); } if (tag.contains("Patterns")) { ListTag patterns = tag.get("Patterns"); tags.add(BannerTranslator.convertBannerPattern(patterns)); } if (tag.contains("CustomName")) { tags.add(new StringTag("CustomName", (String) tag.get("CustomName").getValue())); } return tags; }
Example 2
Source File: BookPagesTranslator.java From Geyser with MIT License | 6 votes |
@Override public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("pages")) { return; } List<Tag> pages = new ArrayList<>(); ListTag pagesTag = itemTag.get("pages"); for (Tag tag : pagesTag.getValue()) { if (!(tag instanceof StringTag)) continue; StringTag textTag = (StringTag) tag; CompoundTag pageTag = new CompoundTag(""); pageTag.put(new StringTag("photoname", "")); pageTag.put(new StringTag("text", MessageUtils.getBedrockMessageLenient(textTag.getValue()))); pages.add(pageTag); } itemTag.remove("pages"); itemTag.put(new ListTag("pages", pages)); }
Example 3
Source File: BookPagesTranslator.java From Geyser with MIT License | 6 votes |
@Override public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("pages")) { return; } List<Tag> pages = new ArrayList<>(); ListTag pagesTag = itemTag.get("pages"); for (Tag tag : pagesTag.getValue()) { if (!(tag instanceof CompoundTag)) continue; CompoundTag pageTag = (CompoundTag) tag; StringTag textTag = pageTag.get("text"); pages.add(new StringTag(MessageUtils.getJavaMessage(textTag.getValue()))); } itemTag.remove("pages"); itemTag.put(new ListTag("pages", pages)); }
Example 4
Source File: BasicItemTranslator.java From Geyser with MIT License | 6 votes |
@Override public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("display")) { return; } CompoundTag displayTag = itemTag.get("display"); if (displayTag.contains("Name")) { StringTag nameTag = displayTag.get("Name"); displayTag.put(new StringTag("Name", toJavaMessage(nameTag))); } if (displayTag.contains("Lore")) { ListTag loreTag = displayTag.get("Lore"); List<Tag> lore = new ArrayList<>(); for (Tag tag : loreTag.getValue()) { if (!(tag instanceof StringTag)) return; lore.add(new StringTag("", "§r" + toJavaMessage((StringTag) tag))); } displayTag.put(new ListTag("Lore", lore)); } }
Example 5
Source File: BannerTranslator.java From Geyser with MIT License | 6 votes |
@Override public ItemData translateToBedrock(ItemStack itemStack, ItemEntry itemEntry) { if (itemStack.getNbt() == null) return super.translateToBedrock(itemStack, itemEntry); ItemData itemData = super.translateToBedrock(itemStack, itemEntry); CompoundTag blockEntityTag = itemStack.getNbt().get("BlockEntityTag"); if (blockEntityTag.contains("Patterns")) { ListTag patterns = blockEntityTag.get("Patterns"); CompoundTagBuilder builder = itemData.getTag().toBuilder(); builder.tag(convertBannerPattern(patterns)); itemData = ItemData.of(itemData.getId(), itemData.getDamage(), itemData.getCount(), builder.buildRootTag()); } return itemData; }
Example 6
Source File: SkullHandler.java From ViaVersion with MIT License | 6 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); return -1; } int id = storage.get(position).getOriginal(); if (id >= SKULL_WALL_START && id <= SKULL_END) { Tag skullType = tag.get("SkullType"); if (skullType != null) { id += ((Number) tag.get("SkullType").getValue()).intValue() * 20; } if (tag.contains("Rot")) { id += ((Number) tag.get("Rot").getValue()).intValue(); } } else { Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); return -1; } return id; }
Example 7
Source File: EnchantedBookTranslator.java From Geyser with MIT License | 5 votes |
@Override public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("StoredEnchantments")) { return; } Tag enchTag = itemTag.get("StoredEnchantments"); if (enchTag instanceof ListTag) { enchTag = new ListTag("Enchantments", ((ListTag) enchTag).getValue()); itemTag.remove("StoredEnchantments"); itemTag.put(enchTag); } }
Example 8
Source File: EnchantedBookTranslator.java From Geyser with MIT License | 5 votes |
@Override public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("Enchantments")) { return; } Tag enchTag = itemTag.get("Enchantments"); if (enchTag instanceof ListTag) { enchTag = new ListTag("StoredEnchantments", ((ListTag) enchTag).getValue()); itemTag.remove("Enchantments"); itemTag.put(enchTag); } }
Example 9
Source File: LeatherArmorTranslator.java From Geyser with MIT License | 5 votes |
@Override public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) { if (!itemTag.contains("display")) { return; } CompoundTag displayTag = itemTag.get("display"); if (displayTag.contains("color")) { IntTag color = displayTag.get("color"); if (color != null) { itemTag.put(new IntTag("customColor", color.getValue())); displayTag.remove("color"); } } }
Example 10
Source File: BlockEntity.java From ViaVersion with MIT License | 5 votes |
public static void handle(List<CompoundTag> tags, UserConnection connection) { for (CompoundTag tag : tags) { try { if (!tag.contains("id")) throw new Exception("NBT tag not handled because the id key is missing"); String id = (String) tag.get("id").getValue(); if (!types.containsKey(id)) throw new Exception("Not handled id: " + id); int newId = types.get(id); if (newId == -1) continue; int x = (int) tag.get("x").getValue(); int y = (int) tag.get("y").getValue(); int z = (int) tag.get("z").getValue(); Position pos = new Position(x, (short) y, z); updateBlockEntity(pos, (short) newId, tag, connection); } catch (Exception e) { if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag); } } } }
Example 11
Source File: FlowerPotHandler.java From ViaVersion with MIT License | 5 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { Object item = tag.contains("Item") ? tag.get("Item").getValue() : null; Object data = tag.contains("Data") ? tag.get("Data").getValue() : null; // Convert item to String without namespace or to Byte if (item instanceof String) { item = ((String) item).replace("minecraft:", ""); } else if (item instanceof Number) { item = ((Number) item).byteValue(); } else { item = (byte) 0; } // Convert data to Byte if (data instanceof Number) { data = ((Number) data).byteValue(); } else { data = (byte) 0; } Integer flower = flowers.get(new Pair<>(item, (byte) data)); if (flower != null) return flower; flower = flowers.get(new Pair<>(item, (byte) 0)); if (flower != null) return flower; return 5265; // Fallback to empty pot }
Example 12
Source File: SpawnerHandler.java From ViaVersion with MIT License | 5 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) { CompoundTag data = tag.get("SpawnData"); if (data.contains("id") && data.get("id") instanceof StringTag) { StringTag s = data.get("id"); s.setValue(EntityNameRewriter.rewrite(s.getValue())); } } // Always return -1 because the block is still the same id return -1; }
Example 13
Source File: ItemRewriter_1_11_TO_1_10.java From ChatItem with GNU General Public License v3.0 | 5 votes |
private static boolean hasEntityTag(Item item) { if (item != null && item.getId().equals("minecraft:spawn_egg")) { // Monster Egg CompoundTag tag = item.getTag(); if (tag != null && tag.contains("EntityTag") && tag.get("EntityTag") instanceof CompoundTag) { if (((CompoundTag) tag.get("EntityTag")).get("id") instanceof StringTag) { return true; } } } return false; }