Java Code Examples for com.github.steveice10.opennbt.tag.builtin.CompoundTag

The following examples show how to use com.github.steveice10.opennbt.tag.builtin.CompoundTag. These examples are extracted from open source projects. 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 Project: ViaVersion   Author: ViaVersion   File: BedHandler.java    License: MIT License 6 votes vote down vote up
@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 bed color update packet, but there is no bed! O_o " + tag);
        return -1;
    }

    //                                              RED_BED + FIRST_BED
    int blockId = storage.get(position).getOriginal() - 972 + 748;

    Tag color = tag.get("color");
    if (color != null) {
        blockId += (((Number) color.getValue()).intValue() * 16);
    }

    return blockId;
}
 
Example #2
Source Project: ViaVersion   Author: ViaVersion   File: InventoryPackets.java    License: MIT License 6 votes vote down vote up
public static void toClient(Item item) {
    if (item == null) return;

    if (item.getIdentifier() == 771 && item.getTag() != null) {
        CompoundTag tag = item.getTag();
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof StringTag) {
                UUID id = UUID.fromString((String) idTag.getValue());
                ownerCompundTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(id)));
            }
        }
    }

    item.setIdentifier(getNewItemId(item.getIdentifier()));
}
 
Example #3
Source Project: ViaVersion   Author: ViaVersion   File: CommandBlockStorage.java    License: MIT License 6 votes vote down vote up
public Optional<CompoundTag> getCommandBlock(Position position) {
    Pair<Integer, Integer> chunkCoords = getChunkCoords(position);

    Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkCoords);
    if (blocks == null)
        return Optional.empty();

    CompoundTag tag = blocks.get(position);
    if (tag == null)
        return Optional.empty();

    tag = tag.clone();
    tag.put(new ByteTag("powered", (byte) 0));
    tag.put(new ByteTag("auto", (byte) 0));
    tag.put(new ByteTag("conditionMet", (byte) 0));
    return Optional.of(tag);
}
 
Example #4
Source Project: Geyser   Author: GeyserMC   File: SignBlockEntityTranslator.java    License: MIT License 6 votes vote down vote up
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
    List<Tag<?>> tags = new ArrayList<>();

    StringBuilder signText = new StringBuilder();
    for(int i = 0; i < 4; i++) {
        int currentLine = i+1;
        String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), "");
        signLine = MessageUtils.getBedrockMessage(Message.fromString(signLine));

        //Java allows up to 16+ characters on certain symbols. 
        if(signLine.length() >= 15 && (signLine.contains("-") || signLine.contains("="))) {
            signLine = signLine.substring(0, 14);
        }

        signText.append(signLine);
        signText.append("\n");
    }

    tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(signText.toString()))));
    return tags;
}
 
Example #5
Source Project: Geyser   Author: GeyserMC   File: CrossbowTranslator.java    License: MIT License 6 votes vote down vote up
@Override
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
    if (itemTag.get("ChargedProjectiles") != null) {
        ListTag chargedProjectiles = itemTag.get("ChargedProjectiles");
        if (!chargedProjectiles.getValue().isEmpty()) {
            CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);

            CompoundTag newProjectile = new CompoundTag("chargedItem");
            newProjectile.put(new ByteTag("Count", (byte) projectile.get("Count").getValue()));
            newProjectile.put(new StringTag("Name", (String) projectile.get("id").getValue()));

            // Not sure what this is for
            newProjectile.put(new ByteTag("Damage", (byte) 0));

            itemTag.put(newProjectile);
        }
    }
}
 
Example #6
Source Project: Geyser   Author: GeyserMC   File: BookPagesTranslator.java    License: MIT License 6 votes vote down vote up
@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 #7
Source Project: Geyser   Author: GeyserMC   File: BasicItemTranslator.java    License: MIT License 6 votes vote down vote up
@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 #8
Source Project: ViaVersion   Author: ViaVersion   File: ItemRewriter.java    License: MIT License 6 votes vote down vote up
public static void rewriteBookToServer(Item item) {
    int id = item.getIdentifier();
    if (id != 387) {
        return;
    }
    CompoundTag tag = item.getTag();
    ListTag pages = tag.get("pages");
    if (pages == null) { // is this even possible?
        return;
    }
    for (int i = 0; i < pages.size(); i++) {
        Tag pageTag = pages.get(i);
        if (!(pageTag instanceof StringTag)) {
            continue;
        }
        StringTag stag = (StringTag) pageTag;
        String value = stag.getValue();
        if (value.replaceAll(" ", "").isEmpty()) {
            value = "\"" + fixBookSpaceChars(value) + "\"";
        } else {
            value = fixBookSpaceChars(value);
        }
        stag.setValue(value);
    }
}
 
Example #9
Source Project: Geyser   Author: GeyserMC   File: BannerTranslator.java    License: MIT License 6 votes vote down vote up
@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 #10
Source Project: Geyser   Author: GeyserMC   File: AnvilInventoryTranslator.java    License: MIT License 6 votes vote down vote up
@Override
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
    if (slot >= 0 && slot <= 2) {
        ItemStack item = inventory.getItem(slot);
        if (item != null) {
            String rename;
            CompoundTag tag = item.getNbt();
            if (tag != null) {
                CompoundTag displayTag = tag.get("display");
                if (displayTag != null) {
                    String itemName = displayTag.get("Name").getValue().toString();
                    Message message = Message.fromString(itemName);
                    rename = message.getText();
                } else {
                    rename = "";
                }
            } else {
                rename = "";
            }
            ClientRenameItemPacket renameItemPacket = new ClientRenameItemPacket(rename);
            session.sendDownstreamPacket(renameItemPacket);
        }
    }
    super.updateSlot(session, inventory, slot);
}
 
Example #11
Source Project: ViaVersion   Author: ViaVersion   File: InventoryPackets.java    License: MIT License 6 votes vote down vote up
public static void toClient(Item item) {
    if (item == null) return;
    item.setIdentifier(getNewItemId(item.getIdentifier()));

    CompoundTag tag;
    if ((tag = item.getTag()) != null) {
        // Display Lore now uses JSON
        Tag displayTag = tag.get("display");
        if (displayTag instanceof CompoundTag) {
            CompoundTag display = (CompoundTag) displayTag;
            Tag loreTag = display.get("Lore");
            if (loreTag instanceof ListTag) {
                ListTag lore = (ListTag) loreTag;
                display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore)));
                for (Tag loreEntry : lore) {
                    if (loreEntry instanceof StringTag) {
                        ((StringTag) loreEntry).setValue(ChatRewriter.legacyTextToJson(((StringTag) loreEntry).getValue()).toString());
                    }
                }
            }
        }
    }
}
 
Example #12
Source Project: ViaVersion   Author: ViaVersion   File: EntityPackets.java    License: MIT License 6 votes vote down vote up
private static CompoundTag createEndEntry() {
    CompoundTag tag = new CompoundTag("");
    tag.put(new ByteTag("piglin_safe", (byte) 0));
    tag.put(new ByteTag("natural", (byte) 0));
    tag.put(new FloatTag("ambient_light", 0));
    tag.put(new StringTag("infiniburn", "minecraft:infiniburn_end"));
    tag.put(new ByteTag("respawn_anchor_works", (byte) 0));
    tag.put(new ByteTag("has_skylight", (byte) 0));
    tag.put(new ByteTag("bed_works", (byte) 0));
    tag.put(new LongTag("fixed_time", 6000));
    tag.put(new ByteTag("has_raids", (byte) 1));
    tag.put(new StringTag("name", "minecraft:the_end"));
    tag.put(new IntTag("logical_height", 256));
    tag.put(new ByteTag("shrunk", (byte) 0));
    tag.put(new ByteTag("ultrawarm", (byte) 0));
    tag.put(new ByteTag("has_ceiling", (byte) 0));
    return tag;
}
 
Example #13
Source Project: ViaVersion   Author: ViaVersion   File: BlockEntityProvider.java    License: MIT License 6 votes vote down vote up
/**
 * Transforms the BlockEntities to blocks!
 *
 * @param user       UserConnection instance
 * @param position   Block Position - WARNING: Position is null when called from a chunk
 * @param tag        BlockEntity NBT
 * @param sendUpdate send a block change update
 * @return new block id
 * @throws Exception Gotta throw that exception
 */
public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception {
    Tag idTag = tag.get("id");
    if (idTag == null) return -1;

    String id = (String) idTag.getValue();
    BlockEntityHandler handler = handlers.get(id);
    if (handler == null) {
        if (Via.getManager().isDebug()) {
            Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
        }
        return -1;
    }

    int newBlock = handler.transform(user, tag);

    if (sendUpdate && newBlock != -1) {
        sendBlockChange(user, position, newBlock);
    }

    return newBlock;
}
 
Example #14
Source Project: ViaVersion   Author: ViaVersion   File: InventoryPackets.java    License: MIT License 6 votes vote down vote up
public static void toServer(Item item) {
    if (item == null) return;

    item.setIdentifier(getOldItemId(item.getIdentifier()));

    if (item.getIdentifier() == 771 && item.getTag() != null) {
        CompoundTag tag = item.getTag();
        Tag ownerTag = tag.get("SkullOwner");
        if (ownerTag instanceof CompoundTag) {
            CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
            Tag idTag = ownerCompundTag.get("Id");
            if (idTag instanceof IntArrayTag) {
                UUID id = UUIDIntArrayType.uuidFromIntArray((int[]) idTag.getValue());
                ownerCompundTag.put(new StringTag("Id", id.toString()));
            }
        }
    }
}
 
Example #15
Source Project: Geyser   Author: GeyserMC   File: ShulkerBoxBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
    List<Tag<?>> tags = new ArrayList<>();

    byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
    // Just in case...
    if (direction == -1) direction = 1;
    tags.add(new ByteTag("facing", direction));

    return tags;
}
 
Example #16
Source Project: Geyser   Author: GeyserMC   File: DoubleChestBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
    List<Tag<?>> tags = new ArrayList<>();
    if (blockState != null && BlockStateValues.getDoubleChestValues().containsKey(blockState.getId())) {
        DoubleChestValue chestValues = BlockStateValues.getDoubleChestValues().get(blockState.getId());
        if (chestValues != null) {
            int x = (int) tag.getValue().get("x").getValue();
            int z = (int) tag.getValue().get("z").getValue();
            // Calculate the position of the other chest based on the Java block state
            if (chestValues.isFacingEast) {
                if (chestValues.isDirectionPositive) {
                    // East
                    z = z + (chestValues.isLeft ? 1 : -1);
                } else {
                    // West
                    z = z + (chestValues.isLeft ? -1 : 1);
                }
            } else {
                if (chestValues.isDirectionPositive) {
                    // South
                    x = x + (chestValues.isLeft ? -1 : 1);
                } else {
                    // North
                    x = x + (chestValues.isLeft ? 1 : -1);
                }
            }
            tags.add(new IntTag("pairx", x));
            tags.add(new IntTag("pairz", z));
            if (!chestValues.isLeft) {
                tags.add(new ByteTag("pairlead", (byte) 1));
            }
        }
    }
    return tags;
}
 
Example #17
Source Project: Geyser   Author: GeyserMC   File: BedBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
    List<Tag<?>> tags = new ArrayList<>();
    byte bedcolor = BlockStateValues.getBedColor(blockState);
    // Just in case...
    if (bedcolor == -1) bedcolor = 0;
    tags.add(new ByteTag("color", bedcolor));
    return tags;
}
 
Example #18
Source Project: Geyser   Author: GeyserMC   File: BlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
protected CompoundTag getConstantJavaTag(String javaId, int x, int y, int z) {
    CompoundTag tag = new CompoundTag("");
    tag.put(new IntTag("x", x));
    tag.put(new IntTag("y", y));
    tag.put(new IntTag("z", z));
    tag.put(new StringTag("id", javaId));
    return tag;
}
 
Example #19
Source Project: Geyser   Author: GeyserMC   File: BlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
protected com.nukkitx.nbt.tag.CompoundTag getConstantBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
            .intTag("x", x)
            .intTag("y", y)
            .intTag("z", z)
            .stringTag("id", bedrockId);
    return tagBuilder.buildRootTag();
}
 
Example #20
Source Project: ViaVersion   Author: ViaVersion   File: BlockEntity.java    License: MIT License 5 votes vote down vote up
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 #21
Source Project: Geyser   Author: GeyserMC   File: EndGatewayBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    List<IntTag> tagsList = new ArrayList<>();
    tagsList.add(new IntTag("", 0));
    tagsList.add(new IntTag("", 0));
    tagsList.add(new IntTag("", 0));
    tagBuilder.listTag("ExitPortal", IntTag.class, tagsList);
    return tagBuilder.buildRootTag();
}
 
Example #22
Source Project: ViaVersion   Author: ViaVersion   File: Chunk1_14Type.java    License: MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
    Type.NBT.write(output, chunk.getHeightMap());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set

            buf.writeShort(section.getNonAirBlocksCount());
            Types1_13.CHUNK_SECTION.write(buf, section);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :)
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example #23
Source Project: Geyser   Author: GeyserMC   File: SpawnerBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.byteTag("isMovable", (byte) 1)
            .stringTag("id", "MobSpawner");

    return tagBuilder.buildRootTag();
}
 
Example #24
Source Project: ViaVersion   Author: ViaVersion   File: SpawnerHandler.java    License: MIT License 5 votes vote down vote up
@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 #25
Source Project: Geyser   Author: GeyserMC   File: CampfireBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) {
    List<Tag<?>> tags = new ArrayList<>();
    ListTag items = tag.get("Items");
    int i = 1;
    for (com.github.steveice10.opennbt.tag.builtin.Tag itemTag : items.getValue()) {
        tags.add(getItem((CompoundTag) itemTag).toBuilder().build("Item" + i));
        i++;
    }
    return tags;
}
 
Example #26
Source Project: Geyser   Author: GeyserMC   File: CampfireBlockEntityTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public com.nukkitx.nbt.tag.CompoundTag getDefaultBedrockTag(String bedrockId, int x, int y, int z) {
    CompoundTagBuilder tagBuilder = getConstantBedrockTag(bedrockId, x, y, z).toBuilder();
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item1", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item2", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item3", new HashMap<>()));
    tagBuilder.tag(new com.nukkitx.nbt.tag.CompoundTag("Item4", new HashMap<>()));
    return tagBuilder.buildRootTag();
}
 
Example #27
Source Project: ViaVersion   Author: ViaVersion   File: Chunk1_13Type.java    License: MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_13.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);

        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int value : chunk.getBiomeData()) {
            output.writeInt(value);
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example #28
Source Project: Geyser   Author: GeyserMC   File: CrossbowTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
    if (itemTag.get("chargedItem") != null) {
        CompoundTag chargedItem = itemTag.get("chargedItem");

        CompoundTag newProjectile = new CompoundTag("");
        newProjectile.put(new ByteTag("Count", (byte) chargedItem.get("Count").getValue()));
        newProjectile.put(new StringTag("id", (String) chargedItem.get("Name").getValue()));

        ListTag chargedProjectiles = new ListTag("ChargedProjectiles");
        chargedProjectiles.add(newProjectile);

        itemTag.put(chargedProjectiles);
    }
}
 
Example #29
Source Project: Geyser   Author: GeyserMC   File: EnchantedBookTranslator.java    License: MIT License 5 votes vote down vote up
@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 #30
Source Project: Geyser   Author: GeyserMC   File: MapItemTranslator.java    License: MIT License 5 votes vote down vote up
@Override
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
    IntTag mapId = itemTag.get("map");

    if (mapId != null) {
        itemTag.put(new StringTag("map_uuid", mapId.getValue().toString()));
        itemTag.put(new IntTag("map_name_index", mapId.getValue()));
        itemTag.put(new ByteTag("map_display_players", (byte) 1));
        itemTag.remove("map");
    }
}