Search in sources :

Example 6 with ListTag

use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.

the class PlayerPackets method register.

public static void register(Protocol protocol) {
    protocol.registerClientbound(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION, Type.POSITION1_14);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.QUERY_BLOCK_NBT, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                    protocol.getItemRewriter().handleItemToServer(item);
                    if (item == null)
                        return;
                    CompoundTag tag = item.tag();
                    if (tag == null)
                        return;
                    Tag pages = tag.get("pages");
                    // Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
                    if (pages == null) {
                        tag.put("pages", new ListTag(Collections.singletonList(new StringTag())));
                    }
                    // Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit
                    if (Via.getConfig().isTruncate1_14Books() && pages instanceof ListTag) {
                        ListTag listTag = (ListTag) pages;
                        if (listTag.size() > 50) {
                            listTag.setValue(listTag.getValue().subList(0, 50));
                        }
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.PLAYER_DIGGING, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Action
            map(Type.VAR_INT);
            // Position
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.RECIPE_BOOK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.get(Type.VAR_INT, 0);
                    if (type == 0) {
                        wrapper.passthrough(Type.STRING);
                    } else if (type == 1) {
                        // Crafting Recipe Book Open
                        wrapper.passthrough(Type.BOOLEAN);
                        // Crafting Recipe Filter Active
                        wrapper.passthrough(Type.BOOLEAN);
                        // Smelting Recipe Book Open
                        wrapper.passthrough(Type.BOOLEAN);
                        // Smelting Recipe Filter Active
                        wrapper.passthrough(Type.BOOLEAN);
                        // Unknown new booleans
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                        wrapper.read(Type.BOOLEAN);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_COMMAND_BLOCK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.UPDATE_SIGN, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14, Type.POSITION);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_14.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int hand = wrapper.read(Type.VAR_INT);
                    Position position = wrapper.read(Type.POSITION1_14);
                    int face = wrapper.read(Type.VAR_INT);
                    float x = wrapper.read(Type.FLOAT);
                    float y = wrapper.read(Type.FLOAT);
                    float z = wrapper.read(Type.FLOAT);
                    // new unknown boolean
                    wrapper.read(Type.BOOLEAN);
                    wrapper.write(Type.POSITION, position);
                    wrapper.write(Type.VAR_INT, face);
                    wrapper.write(Type.VAR_INT, hand);
                    wrapper.write(Type.FLOAT, x);
                    wrapper.write(Type.FLOAT, y);
                    wrapper.write(Type.FLOAT, z);
                }
            });
        }
    });
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Position(com.viaversion.viaversion.api.minecraft.Position) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 7 with ListTag

use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.

the class MappingData method loadExtras.

@Override
public void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
    try {
        dimensionRegistry = BinaryTagIO.readCompressedInputStream(MappingDataLoader.getResource("dimension-registry-1.16.2.nbt"));
    } catch (IOException e) {
        Via.getPlatform().getLogger().severe("Error loading dimension registry:");
        e.printStackTrace();
    }
    // Data of each dimension
    ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value");
    for (Tag dimension : dimensions) {
        CompoundTag dimensionCompound = (CompoundTag) dimension;
        // Copy with an empty name
        CompoundTag dimensionData = new CompoundTag(((CompoundTag) dimensionCompound.get("element")).getValue());
        dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData);
    }
}
Also used : IOException(java.io.IOException) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 8 with ListTag

use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.

the class InventoryPackets method newToOldAttributes.

public static void newToOldAttributes(Item item) {
    if (item.tag() == null)
        return;
    ListTag attributes = item.tag().get("AttributeModifiers");
    if (attributes == null)
        return;
    for (Tag tag : attributes) {
        CompoundTag attribute = (CompoundTag) tag;
        rewriteAttributeName(attribute, "AttributeName", true);
        rewriteAttributeName(attribute, "Name", true);
        IntArrayTag uuidTag = attribute.get("UUID");
        if (uuidTag != null && uuidTag.getValue().length == 4) {
            UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
            attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
            attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
        }
    }
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) UUID(java.util.UUID) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag)

Example 9 with ListTag

use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.

the class InventoryPackets method oldToNewAttributes.

public static void oldToNewAttributes(Item item) {
    if (item.tag() == null)
        return;
    ListTag attributes = item.tag().get("AttributeModifiers");
    if (attributes == null)
        return;
    for (Tag tag : attributes) {
        CompoundTag attribute = (CompoundTag) tag;
        rewriteAttributeName(attribute, "AttributeName", false);
        rewriteAttributeName(attribute, "Name", false);
        Tag leastTag = attribute.get("UUIDLeast");
        if (leastTag != null) {
            Tag mostTag = attribute.get("UUIDMost");
            int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((NumberTag) leastTag).asLong(), ((NumberTag) mostTag).asLong());
            attribute.put("UUID", new IntArrayTag(uuidIntArray));
        }
    }
}
Also used : IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 10 with ListTag

use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.

the class Protocol1_17_1To1_17 method registerPackets.

@Override
protected void registerPackets() {
    registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_17_1.REMOVE_ENTITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Aaaaand back to an array again!
                int entityId = wrapper.read(Type.VAR_INT);
                wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { entityId });
            });
        }
    });
    registerClientbound(ClientboundPackets1_17.SET_SLOT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Container id
            map(Type.UNSIGNED_BYTE);
            // Add arbitrary state id
            create(Type.VAR_INT, 0);
        }
    });
    registerClientbound(ClientboundPackets1_17.WINDOW_ITEMS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Container id
            map(Type.UNSIGNED_BYTE);
            // Add arbitrary state id
            create(Type.VAR_INT, 0);
            handler(wrapper -> {
                // Length encoded as var int now
                wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY));
                // Carried item - should work like this
                wrapper.write(Type.FLAT_VAR_INT_ITEM, null);
            });
        }
    });
    registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Container id
            map(Type.UNSIGNED_BYTE);
            // Remove state id
            read(Type.VAR_INT);
        }
    });
    registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                CompoundTag tag = new CompoundTag();
                // Magic value for writable books
                Item item = new DataItem(942, (byte) 1, (short) 0, tag);
                // Write the item, edit the tag down the line
                wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
                int slot = wrapper.read(Type.VAR_INT);
                // Save pages to tag
                int pages = wrapper.read(Type.VAR_INT);
                ListTag pagesTag = new ListTag(StringTag.class);
                for (int i = 0; i < pages; i++) {
                    String page = wrapper.read(PAGE_STRING_TYPE);
                    pagesTag.add(new StringTag(page));
                }
                // Legacy servers don't like an empty pages list
                if (pagesTag.size() == 0) {
                    pagesTag.add(new StringTag(""));
                }
                tag.put("pages", pagesTag);
                if (wrapper.read(Type.BOOLEAN)) {
                    // Save the title to tag
                    String title = wrapper.read(TITLE_STRING_TYPE);
                    tag.put("title", new StringTag(title));
                    // Even if unused, legacy servers check for the author tag
                    tag.put("author", new StringTag(wrapper.user().getProtocolInfo().getUsername()));
                    // Write signing
                    wrapper.write(Type.BOOLEAN, true);
                } else {
                    wrapper.write(Type.BOOLEAN, false);
                }
                // Write the slot
                wrapper.write(Type.VAR_INT, slot);
            });
        }
    });
}
Also used : StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17) Type(com.viaversion.viaversion.api.type.Type) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) StringType(com.viaversion.viaversion.api.type.types.StringType) Item(com.viaversion.viaversion.api.minecraft.item.Item) AbstractProtocol(com.viaversion.viaversion.api.protocol.AbstractProtocol) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Aggregations

CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)25 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)23 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)21 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)17 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)7 NumberTag (com.github.steveice10.opennbt.tag.builtin.NumberTag)7 ByteTag (com.github.steveice10.opennbt.tag.builtin.ByteTag)4 DoubleTag (com.github.steveice10.opennbt.tag.builtin.DoubleTag)4 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)4 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)4 ShortTag (com.github.steveice10.opennbt.tag.builtin.ShortTag)4 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)3 Type (com.viaversion.viaversion.api.type.Type)3 ArrayList (java.util.ArrayList)3 ByteArrayTag (com.github.steveice10.opennbt.tag.builtin.ByteArrayTag)2 FloatTag (com.github.steveice10.opennbt.tag.builtin.FloatTag)2 LongArrayTag (com.github.steveice10.opennbt.tag.builtin.LongArrayTag)2 NbtMap (com.nukkitx.nbt.NbtMap)2 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)2