Search in sources :

Example 1 with Protocol1_16To1_15_2

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2 in project ViaBackwards by ViaVersion.

the class Protocol1_15_2To1_16 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_16.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_16.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_16.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_16.TITLE);
    translatableRewriter.registerPing();
    new CommandRewriter1_16(this).registerDeclareCommands(ClientboundPackets1_16.DECLARE_COMMANDS);
    (blockItemPackets = new BlockItemPackets1_16(this)).register();
    entityRewriter.register();
    registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                String original = wrapper.passthrough(Type.STRING);
                JsonObject object = GsonUtil.getGson().fromJson(original, JsonObject.class);
                JsonElement description = object.get("description");
                if (description == null)
                    return;
                translatableRewriter.processText(description);
                wrapper.set(Type.STRING, 0, object.toString());
            });
        }
    });
    registerClientbound(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
            map(Type.BYTE);
            // Sender
            map(Type.UUID, Type.NOTHING);
        }
    });
    registerClientbound(ClientboundPackets1_16.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.VAR_INT);
            // Window Type
            map(Type.VAR_INT);
            handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
            handler(wrapper -> {
                int windowType = wrapper.get(Type.VAR_INT, 1);
                if (windowType == 20) {
                    // Smithing table
                    // Open anvil inventory
                    wrapper.set(Type.VAR_INT, 1, 7);
                } else if (windowType > 20) {
                    wrapper.set(Type.VAR_INT, 1, --windowType);
                }
            });
        }
    });
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND);
    // Login success
    registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Transform int array to plain string
                UUID uuid = wrapper.read(Type.UUID_INT_ARRAY);
                wrapper.write(Type.STRING, uuid.toString());
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
    registerServerbound(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // player id
                wrapper.passthrough(Type.VAR_INT);
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action == 0) {
                    wrapper.user().get(PlayerSneakStorage.class).setSneaking(true);
                } else if (action == 1) {
                    wrapper.user().get(PlayerSneakStorage.class).setSneaking(false);
                }
            });
        }
    });
    registerServerbound(ServerboundPackets1_14.INTERACT_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Entity Id
                wrapper.passthrough(Type.VAR_INT);
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action == 0 || action == 2) {
                    if (action == 2) {
                        // Location
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.passthrough(Type.FLOAT);
                    }
                    // Hand
                    wrapper.passthrough(Type.VAR_INT);
                }
                // New boolean: Whether the client is sneaking
                wrapper.write(Type.BOOLEAN, wrapper.user().get(PlayerSneakStorage.class).isSneaking());
            });
        }
    });
    registerServerbound(ServerboundPackets1_14.PLAYER_ABILITIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                byte flags = wrapper.read(Type.BYTE);
                // Only take the isFlying value (everything else has been removed and wasn't used anyways)
                flags &= 2;
                wrapper.write(Type.BYTE, flags);
                wrapper.read(Type.FLOAT);
                wrapper.read(Type.FLOAT);
            });
        }
    });
    cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
Also used : TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) WorldNameTracker(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker) TranslatableRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.chat.TranslatableRewriter1_16) GsonUtil(com.viaversion.viaversion.util.GsonUtil) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Entity1_16Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) BackwardsMappings(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings) PlayerSneakStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) CommandRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16) State(com.viaversion.viaversion.api.protocol.packet.State) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) UUID(java.util.UUID) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) EntityPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BlockItemPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) BlockItemPackets1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) CommandRewriter1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.CommandRewriter1_16) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PlayerSneakStorage(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) UUID(java.util.UUID)

Example 2 with Protocol1_16To1_15_2

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2 in project ViaVersion by ViaVersion.

the class EntityPackets method register.

public static void register(Protocol1_16To1_15_2 protocol) {
    MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class);
    // Spawn lightning -> Spawn entity
    protocol.registerClientbound(ClientboundPackets1_15.SPAWN_GLOBAL_ENTITY, ClientboundPackets1_16.SPAWN_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                int entityId = wrapper.passthrough(Type.VAR_INT);
                byte type = wrapper.read(Type.BYTE);
                if (type != 1) {
                    // Cancel if not lightning/invalid id
                    wrapper.cancel();
                    return;
                }
                wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(entityId, Entity1_16Types.LIGHTNING_BOLT);
                // uuid
                wrapper.write(Type.UUID, UUID.randomUUID());
                // entity type
                wrapper.write(Type.VAR_INT, Entity1_16Types.LIGHTNING_BOLT.getId());
                // x
                wrapper.passthrough(Type.DOUBLE);
                // y
                wrapper.passthrough(Type.DOUBLE);
                // z
                wrapper.passthrough(Type.DOUBLE);
                // yaw
                wrapper.write(Type.BYTE, (byte) 0);
                // pitch
                wrapper.write(Type.BYTE, (byte) 0);
                // data
                wrapper.write(Type.INT, 0);
                // velocity
                wrapper.write(Type.SHORT, (short) 0);
                // velocity
                wrapper.write(Type.SHORT, (short) 0);
                // velocity
                wrapper.write(Type.SHORT, (short) 0);
            });
        }
    });
    metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.SPAWN_ENTITY, Entity1_16Types.FALLING_BLOCK);
    metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_MOB);
    metadataRewriter.registerTracker(ClientboundPackets1_15.SPAWN_PLAYER, Entity1_16Types.PLAYER);
    metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.ENTITY_METADATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST);
    metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.DESTROY_ENTITIES);
    protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(DIMENSION_HANDLER);
            // Seed
            map(Type.LONG);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                // Previous gamemode, set to none
                wrapper.write(Type.BYTE, (byte) -1);
                String levelType = wrapper.read(Type.STRING);
                // debug
                wrapper.write(Type.BOOLEAN, false);
                wrapper.write(Type.BOOLEAN, levelType.equals("flat"));
                // keep all playerdata
                wrapper.write(Type.BOOLEAN, true);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Entity ID
            map(Type.INT);
            // Gamemode
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                // Previous gamemode, set to none
                wrapper.write(Type.BYTE, (byte) -1);
                // World list - only used for command completion
                wrapper.write(Type.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length));
                // Dimension registry
                wrapper.write(Type.NBT, DIMENSIONS_TAG.clone());
            });
            // Dimension
            handler(DIMENSION_HANDLER);
            // Seed
            map(Type.LONG);
            // Max players
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                wrapper.user().getEntityTracker(Protocol1_16To1_15_2.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.PLAYER);
                // level type
                final String type = wrapper.read(Type.STRING);
                // View distance
                wrapper.passthrough(Type.VAR_INT);
                // Reduced debug info
                wrapper.passthrough(Type.BOOLEAN);
                // Show death screen
                wrapper.passthrough(Type.BOOLEAN);
                // Debug
                wrapper.write(Type.BOOLEAN, false);
                wrapper.write(Type.BOOLEAN, type.equals("flat"));
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.passthrough(Type.VAR_INT);
                int size = wrapper.passthrough(Type.INT);
                int actualSize = size;
                for (int i = 0; i < size; i++) {
                    // Attributes have been renamed and are now namespaced identifiers
                    String key = wrapper.read(Type.STRING);
                    String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
                    if (attributeIdentifier == null) {
                        attributeIdentifier = "minecraft:" + key;
                        if (!com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) {
                            if (!Via.getConfig().isSuppressConversionWarnings()) {
                                Via.getPlatform().getLogger().warning("Invalid attribute: " + key);
                            }
                            actualSize--;
                            wrapper.read(Type.DOUBLE);
                            int modifierSize = wrapper.read(Type.VAR_INT);
                            for (int j = 0; j < modifierSize; j++) {
                                wrapper.read(Type.UUID);
                                wrapper.read(Type.DOUBLE);
                                wrapper.read(Type.BYTE);
                            }
                            continue;
                        }
                    }
                    wrapper.write(Type.STRING, attributeIdentifier);
                    wrapper.passthrough(Type.DOUBLE);
                    int modifierSize = wrapper.passthrough(Type.VAR_INT);
                    for (int j = 0; j < modifierSize; j++) {
                        wrapper.passthrough(Type.UUID);
                        wrapper.passthrough(Type.DOUBLE);
                        wrapper.passthrough(Type.BYTE);
                    }
                }
                if (size != actualSize) {
                    wrapper.set(Type.INT, 0, actualSize);
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                // Don't send an arm swing if the player has an inventory opened.
                if (inventoryTracker.getInventory() != -1) {
                    wrapper.cancel();
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ByteTag(com.github.steveice10.opennbt.tag.builtin.ByteTag) Arrays(java.util.Arrays) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) UUID(java.util.UUID) Via(com.viaversion.viaversion.api.Via) IntTag(com.github.steveice10.opennbt.tag.builtin.IntTag) Types1_14(com.viaversion.viaversion.api.type.types.version.Types1_14) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) Types1_16(com.viaversion.viaversion.api.type.types.version.Types1_16) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) WorldIdentifiers(com.viaversion.viaversion.api.minecraft.WorldIdentifiers) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) Entity1_16Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) MetadataRewriter1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2) FloatTag(com.github.steveice10.opennbt.tag.builtin.FloatTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) MetadataRewriter1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2)

Example 3 with Protocol1_16To1_15_2

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    // clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing
    PacketHandler cursorRemapper = wrapper -> {
        PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT);
        clearPacket.write(Type.UNSIGNED_BYTE, (short) -1);
        clearPacket.write(Type.SHORT, (short) -1);
        clearPacket.write(Type.FLAT_VAR_INT_ITEM, null);
        clearPacket.send(Protocol1_16To1_15_2.class);
    };
    protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.VAR_INT);
            // Window Type
            map(Type.VAR_INT);
            // Window Title
            map(Type.COMPONENT);
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                int windowId = wrapper.get(Type.VAR_INT, 0);
                int windowType = wrapper.get(Type.VAR_INT, 1);
                if (windowType >= 20) {
                    // smithing added with id 20
                    wrapper.set(Type.VAR_INT, 1, ++windowType);
                }
                inventoryTracker.setInventory((short) windowId);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(cursorRemapper);
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.WINDOW_PROPERTY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Window Id
            map(Type.UNSIGNED_BYTE);
            // Property
            map(Type.SHORT);
            // Value
            map(Type.SHORT);
            handler(wrapper -> {
                short property = wrapper.get(Type.SHORT, 0);
                if (property >= 4 && property <= 6) {
                    // Enchantment id
                    short enchantmentId = wrapper.get(Type.SHORT, 1);
                    if (enchantmentId >= 11) {
                        // soul_speed added with id 11
                        wrapper.set(Type.SHORT, 1, ++enchantmentId);
                    }
                }
            });
        }
    });
    registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
    registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
    registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            handler(wrapper -> {
                int slot = wrapper.read(Type.VAR_INT);
                wrapper.write(Type.BYTE, (byte) slot);
                handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
            });
        }
    });
    new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
    registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
    protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
                inventoryTracker.setInventory((short) -1);
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
        }
    });
    registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) ListTag(com.github.steveice10.opennbt.tag.builtin.ListTag) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) NumberTag(com.github.steveice10.opennbt.tag.builtin.NumberTag) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) UUID(java.util.UUID) Item(com.viaversion.viaversion.api.minecraft.item.Item) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) LongTag(com.github.steveice10.opennbt.tag.builtin.LongTag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) RecipeRewriter1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryTracker1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16)

Example 4 with Protocol1_16To1_15_2

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2 in project ViaVersion by ViaVersion.

the class WorldPackets method register.

public static void register(Protocol1_16To1_15_2 protocol) {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
    blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
    blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
    protocol.registerClientbound(ClientboundPackets1_15.UPDATE_LIGHT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // x
            map(Type.VAR_INT);
            // y
            map(Type.VAR_INT);
            // Take neighbour's light into account as well
            handler(wrapper -> wrapper.write(Type.BOOLEAN, true));
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Chunk chunk = wrapper.read(new Chunk1_15Type());
                wrapper.write(new Chunk1_16Type(), chunk);
                chunk.setIgnoreOldLightData(chunk.isFullChunk());
                for (int s = 0; s < chunk.getSections().length; s++) {
                    ChunkSection section = chunk.getSections()[s];
                    if (section == null)
                        continue;
                    for (int i = 0; i < section.getPaletteSize(); i++) {
                        int old = section.getPaletteEntry(i);
                        section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old));
                    }
                }
                CompoundTag heightMaps = chunk.getHeightMap();
                for (Tag heightMapTag : heightMaps.values()) {
                    LongArrayTag heightMap = (LongArrayTag) heightMapTag;
                    int[] heightMapData = new int[256];
                    CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
                    heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
                }
                if (chunk.getBlockEntities() == null)
                    return;
                for (CompoundTag blockEntity : chunk.getBlockEntities()) {
                    handleBlockEntity(blockEntity);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                Position position = wrapper.passthrough(Type.POSITION1_14);
                short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
                CompoundTag tag = wrapper.passthrough(Type.NBT);
                handleBlockEntity(tag);
            });
        }
    });
    blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
}
Also used : Position(com.viaversion.viaversion.api.minecraft.Position) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) UUID(java.util.UUID) UUIDIntArrayType(com.viaversion.viaversion.api.type.types.UUIDIntArrayType) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) CompactArrayUtil(com.viaversion.viaversion.util.CompactArrayUtil) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) Map(java.util.Map) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) LongArrayTag(com.github.steveice10.opennbt.tag.builtin.LongArrayTag) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) LongArrayTag(com.github.steveice10.opennbt.tag.builtin.LongArrayTag) Position(com.viaversion.viaversion.api.minecraft.Position) Chunk1_16Type(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Chunk1_15Type(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type) IntArrayTag(com.github.steveice10.opennbt.tag.builtin.IntArrayTag) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) Tag(com.github.steveice10.opennbt.tag.builtin.Tag) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) LongArrayTag(com.github.steveice10.opennbt.tag.builtin.LongArrayTag) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 5 with Protocol1_16To1_15_2

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2 in project ViaVersion by ViaVersion.

the class ProtocolManagerImpl method registerProtocols.

public void registerProtocols() {
    // Base Protocol
    registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
    registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getVersion()));
    registerBaseProtocol(new BaseProtocol1_16(), Range.atLeast(ProtocolVersion.v1_16.getVersion()));
    registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8);
    registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9.getVersion());
    registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2);
    registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_1);
    registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9_3.getVersion());
    registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
    registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_11, ProtocolVersion.v1_10);
    registerProtocol(new Protocol1_11_1To1_11(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_11);
    registerProtocol(new Protocol1_12To1_11_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_11_1);
    registerProtocol(new Protocol1_12_1To1_12(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12);
    registerProtocol(new Protocol1_12_2To1_12_1(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_12_1);
    registerProtocol(new Protocol1_13To1_12_2(), ProtocolVersion.v1_13, ProtocolVersion.v1_12_2);
    registerProtocol(new Protocol1_13_1To1_13(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13);
    registerProtocol(new Protocol1_13_2To1_13_1(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_13_1);
    registerProtocol(new Protocol1_14To1_13_2(), ProtocolVersion.v1_14, ProtocolVersion.v1_13_2);
    registerProtocol(new Protocol1_14_1To1_14(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14);
    registerProtocol(new Protocol1_14_2To1_14_1(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_1);
    registerProtocol(new Protocol1_14_3To1_14_2(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_2);
    registerProtocol(new Protocol1_14_4To1_14_3(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_14_3);
    registerProtocol(new Protocol1_15To1_14_4(), ProtocolVersion.v1_15, ProtocolVersion.v1_14_4);
    registerProtocol(new Protocol1_15_1To1_15(), ProtocolVersion.v1_15_1, ProtocolVersion.v1_15);
    registerProtocol(new Protocol1_15_2To1_15_1(), ProtocolVersion.v1_15_2, ProtocolVersion.v1_15_1);
    registerProtocol(new Protocol1_16To1_15_2(), ProtocolVersion.v1_16, ProtocolVersion.v1_15_2);
    registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16);
    registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1);
    registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_2);
    registerProtocol(new Protocol1_16_4To1_16_3(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_16_3);
    registerProtocol(new Protocol1_17To1_16_4(), ProtocolVersion.v1_17, ProtocolVersion.v1_16_4);
    registerProtocol(new Protocol1_17_1To1_17(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_17);
    registerProtocol(new Protocol1_18To1_17_1(), ProtocolVersion.v1_18, ProtocolVersion.v1_17_1);
    registerProtocol(new Protocol1_18_2To1_18(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_18);
}
Also used : Protocol1_14_4To1_14_3(com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.Protocol1_14_4To1_14_3) Protocol1_16_2To1_16_1(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1) Protocol1_16_3To1_16_2(com.viaversion.viaversion.protocols.protocol1_16_3to1_16_2.Protocol1_16_3To1_16_2) Protocol1_12To1_11_1(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1) Protocol1_11To1_10(com.viaversion.viaversion.protocols.protocol1_11to1_10.Protocol1_11To1_10) Protocol1_14_3To1_14_2(com.viaversion.viaversion.protocols.protocol1_14_3to1_14_2.Protocol1_14_3To1_14_2) Protocol1_11_1To1_11(com.viaversion.viaversion.protocols.protocol1_11_1to1_11.Protocol1_11_1To1_11) Protocol1_13To1_12_2(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2) Protocol1_16_4To1_16_3(com.viaversion.viaversion.protocols.protocol1_16_4to1_16_3.Protocol1_16_4To1_16_3) Protocol1_14_2To1_14_1(com.viaversion.viaversion.protocols.protocol1_14_2to1_14_1.Protocol1_14_2To1_14_1) Protocol1_12_1To1_12(com.viaversion.viaversion.protocols.protocol1_12_1to1_12.Protocol1_12_1To1_12) Protocol1_14_1To1_14(com.viaversion.viaversion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14) Protocol1_15_1To1_15(com.viaversion.viaversion.protocols.protocol1_15_1to1_15.Protocol1_15_1To1_15) Protocol1_16To1_15_2(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2) Protocol1_17To1_16_4(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4) Protocol1_16_1To1_16(com.viaversion.viaversion.protocols.protocol1_16_1to1_16.Protocol1_16_1To1_16) Protocol1_13_1To1_13(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13) Protocol1_14To1_13_2(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2) Protocol1_12_2To1_12_1(com.viaversion.viaversion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2To1_12_1) Protocol1_9_1To1_9(com.viaversion.viaversion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9) Protocol1_18_2To1_18(com.viaversion.viaversion.protocols.protocol1_18_2to1_18.Protocol1_18_2To1_18) BaseProtocol1_7(com.viaversion.viaversion.protocols.base.BaseProtocol1_7) Protocol1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4) Protocol1_9To1_9_1(com.viaversion.viaversion.protocols.protocol1_9to1_9_1.Protocol1_9To1_9_1) Protocol1_15_2To1_15_1(com.viaversion.viaversion.protocols.protocol1_15_2to1_15_1.Protocol1_15_2To1_15_1) Protocol1_10To1_9_3_4(com.viaversion.viaversion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4) Protocol1_13_2To1_13_1(com.viaversion.viaversion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1) Protocol1_17_1To1_17(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.Protocol1_17_1To1_17) Protocol1_18To1_17_1(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1) Protocol1_9_3To1_9_1_2(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3To1_9_1_2) BaseProtocol1_16(com.viaversion.viaversion.protocols.base.BaseProtocol1_16) Protocol1_9_1_2To1_9_3_4(com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Aggregations

Protocol1_16To1_15_2 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2)5 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 Type (com.viaversion.viaversion.api.type.Type)4 ClientboundPackets1_15 (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15)4 UUID (java.util.UUID)4 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)3 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)3 ClientboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16)3 ServerboundPackets1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16)3 IntArrayTag (com.github.steveice10.opennbt.tag.builtin.IntArrayTag)2 ListTag (com.github.steveice10.opennbt.tag.builtin.ListTag)2 LongTag (com.github.steveice10.opennbt.tag.builtin.LongTag)2 Tag (com.github.steveice10.opennbt.tag.builtin.Tag)2 Entity1_16Types (com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types)2 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)2 UUIDIntArrayType (com.viaversion.viaversion.api.type.types.UUIDIntArrayType)2 InventoryTracker1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16)2 ByteTag (com.github.steveice10.opennbt.tag.builtin.ByteTag)1 FloatTag (com.github.steveice10.opennbt.tag.builtin.FloatTag)1 IntTag (com.github.steveice10.opennbt.tag.builtin.IntTag)1