Search in sources :

Example 1 with Protocol1_16_1To1_16_2

use of com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2 in project ViaBackwards by ViaVersion.

the class Protocol1_16_1To1_16_2 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_16_2To1_16_1.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_16_2.BOSSBAR);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_16_2.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_16_2.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_16_2.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_16_2.TITLE);
    translatableRewriter.registerOpenWindow(ClientboundPackets1_16_2.OPEN_WINDOW);
    translatableRewriter.registerPing();
    new CommandRewriter1_16_2(this).registerDeclareCommands(ClientboundPackets1_16_2.DECLARE_COMMANDS);
    (blockItemPackets = new BlockItemPackets1_16_2(this)).register();
    entityRewriter.register();
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_16_2.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_16_2.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_16_2.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_16_2.STOP_SOUND);
    registerClientbound(ClientboundPackets1_16_2.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                JsonElement message = wrapper.passthrough(Type.COMPONENT);
                translatableRewriter.processText(message);
                byte position = wrapper.passthrough(Type.BYTE);
                if (position == 2) {
                    // https://bugs.mojang.com/browse/MC-119145
                    wrapper.clearPacket();
                    wrapper.setId(ClientboundPackets1_16.TITLE.ordinal());
                    wrapper.write(Type.VAR_INT, 2);
                    wrapper.write(Type.COMPONENT, message);
                }
            });
        }
    });
    // Recipe book data has been split into 2 separate packets
    registerServerbound(ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.read(Type.VAR_INT);
                    if (type == 0) {
                        // Shown, change to its own packet
                        // Recipe
                        wrapper.passthrough(Type.STRING);
                        wrapper.setId(ServerboundPackets1_16_2.SEEN_RECIPE.ordinal());
                    } else {
                        wrapper.cancel();
                        // Settings
                        for (int i = 0; i < 3; i++) {
                            sendSeenRecipePacket(i, wrapper);
                        }
                    }
                }

                private void sendSeenRecipePacket(int recipeType, PacketWrapper wrapper) throws Exception {
                    boolean open = wrapper.read(Type.BOOLEAN);
                    boolean filter = wrapper.read(Type.BOOLEAN);
                    PacketWrapper newPacket = wrapper.create(ServerboundPackets1_16_2.RECIPE_BOOK_DATA);
                    newPacket.write(Type.VAR_INT, recipeType);
                    newPacket.write(Type.BOOLEAN, open);
                    newPacket.write(Type.BOOLEAN, filter);
                    newPacket.sendToServer(Protocol1_16_1To1_16_2.class);
                }
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_16_2.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_16_2.STATISTICS);
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) Protocol1_16_2To1_16_1(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) Entity1_16_2Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types) ClientboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) 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) ServerboundPackets1_16_2(com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) BlockItemPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) CommandRewriter1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandRewriter1_16_2) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) EntityPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2) CommandRewriter1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandRewriter1_16_2) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) BlockItemPackets1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter)

Example 2 with Protocol1_16_1To1_16_2

use of com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2 in project ViaBackwards by ViaVersion.

the class ViaBackwardsPlatform method init.

/**
 * Initialize ViaBackwards.
 */
default void init(File dataFolder) {
    ViaBackwardsConfig config = new ViaBackwardsConfig(new File(dataFolder, "config.yml"));
    config.reloadConfig();
    ViaBackwards.init(this, config);
    if (isOutdated())
        return;
    Via.getManager().getSubPlatforms().add(IMPL_VERSION);
    getLogger().info("Loading translations...");
    TranslatableRewriter.loadTranslatables();
    ProtocolManager protocolManager = Via.getManager().getProtocolManager();
    protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10);
    protocolManager.registerProtocol(new Protocol1_10To1_11(), ProtocolVersion.v1_10, ProtocolVersion.v1_11);
    protocolManager.registerProtocol(new Protocol1_11To1_11_1(), ProtocolVersion.v1_11, ProtocolVersion.v1_11_1);
    protocolManager.registerProtocol(new Protocol1_11_1To1_12(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_12);
    protocolManager.registerProtocol(new Protocol1_12To1_12_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_12_1);
    protocolManager.registerProtocol(new Protocol1_12_1To1_12_2(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12_2);
    protocolManager.registerProtocol(new Protocol1_12_2To1_13(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_13);
    protocolManager.registerProtocol(new Protocol1_13To1_13_1(), ProtocolVersion.v1_13, ProtocolVersion.v1_13_1);
    protocolManager.registerProtocol(new Protocol1_13_1To1_13_2(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13_2);
    protocolManager.registerProtocol(new Protocol1_13_2To1_14(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_14);
    protocolManager.registerProtocol(new Protocol1_14To1_14_1(), ProtocolVersion.v1_14, ProtocolVersion.v1_14_1);
    protocolManager.registerProtocol(new Protocol1_14_1To1_14_2(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14_2);
    protocolManager.registerProtocol(new Protocol1_14_2To1_14_3(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_3);
    protocolManager.registerProtocol(new Protocol1_14_3To1_14_4(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_4);
    protocolManager.registerProtocol(new Protocol1_14_4To1_15(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_15);
    protocolManager.registerProtocol(new Protocol1_15To1_15_1(), ProtocolVersion.v1_15, ProtocolVersion.v1_15_1);
    protocolManager.registerProtocol(new Protocol1_15_1To1_15_2(), ProtocolVersion.v1_15_1, ProtocolVersion.v1_15_2);
    protocolManager.registerProtocol(new Protocol1_15_2To1_16(), ProtocolVersion.v1_15_2, ProtocolVersion.v1_16);
    protocolManager.registerProtocol(new Protocol1_16To1_16_1(), ProtocolVersion.v1_16, ProtocolVersion.v1_16_1);
    protocolManager.registerProtocol(new Protocol1_16_1To1_16_2(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16_2);
    protocolManager.registerProtocol(new Protocol1_16_2To1_16_3(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_3);
    protocolManager.registerProtocol(new Protocol1_16_3To1_16_4(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_4);
    protocolManager.registerProtocol(new Protocol1_16_4To1_17(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_17);
    protocolManager.registerProtocol(new Protocol1_17To1_17_1(), ProtocolVersion.v1_17, ProtocolVersion.v1_17_1);
    protocolManager.registerProtocol(new Protocol1_17_1To1_18(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_18);
    protocolManager.registerProtocol(new Protocol1_18To1_18_2(), ProtocolVersion.v1_18, ProtocolVersion.v1_18_2);
}
Also used : Protocol1_16_3To1_16_4(com.viaversion.viabackwards.protocol.protocol1_16_3to1_16_4.Protocol1_16_3To1_16_4) Protocol1_11To1_11_1(com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1) Protocol1_14_4To1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15) Protocol1_12To1_12_1(com.viaversion.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1) Protocol1_14_3To1_14_4(com.viaversion.viabackwards.protocol.protocol1_14_3to1_14_4.Protocol1_14_3To1_14_4) Protocol1_16_1To1_16_2(com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2) Protocol1_13To1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1) Protocol1_14_2To1_14_3(com.viaversion.viabackwards.protocol.protocol1_14_2to1_14_3.Protocol1_14_2To1_14_3) Protocol1_15_2To1_16(com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16) Protocol1_11_1To1_12(com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12) Protocol1_14_1To1_14_2(com.viaversion.viabackwards.protocol.protocol1_14_1to1_14_2.Protocol1_14_1To1_14_2) Protocol1_17To1_17_1(com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.Protocol1_17To1_17_1) Protocol1_16To1_16_1(com.viaversion.viabackwards.protocol.protocol1_16to1_16_1.Protocol1_16To1_16_1) Protocol1_14To1_14_1(com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1) ViaBackwardsConfig(com.viaversion.viabackwards.ViaBackwardsConfig) Protocol1_15To1_15_1(com.viaversion.viabackwards.protocol.protocol1_15to1_15_1.Protocol1_15To1_15_1) Protocol1_16_4To1_17(com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17) Protocol1_12_1To1_12_2(com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2) Protocol1_15_1To1_15_2(com.viaversion.viabackwards.protocol.protocol1_15_1to1_15_2.Protocol1_15_1To1_15_2) Protocol1_17_1To1_18(com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18) Protocol1_10To1_11(com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11) Protocol1_9_4To1_10(com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10) Protocol1_12_2To1_13(com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13) Protocol1_18To1_18_2(com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.Protocol1_18To1_18_2) Protocol1_13_1To1_13_2(com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2) ProtocolManager(com.viaversion.viaversion.api.protocol.ProtocolManager) File(java.io.File) Protocol1_13_2To1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14) Protocol1_16_2To1_16_3(com.viaversion.viabackwards.protocol.protocol1_16_2to1_16_3.Protocol1_16_2To1_16_3)

Aggregations

ViaBackwardsConfig (com.viaversion.viabackwards.ViaBackwardsConfig)1 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)1 BackwardsMappings (com.viaversion.viabackwards.api.data.BackwardsMappings)1 SoundRewriter (com.viaversion.viabackwards.api.rewriters.SoundRewriter)1 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)1 Protocol1_10To1_11 (com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11)1 Protocol1_11_1To1_12 (com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12)1 Protocol1_11To1_11_1 (com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1)1 Protocol1_12_1To1_12_2 (com.viaversion.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2)1 Protocol1_12_2To1_13 (com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13)1 Protocol1_12To1_12_1 (com.viaversion.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1)1 Protocol1_13_1To1_13_2 (com.viaversion.viabackwards.protocol.protocol1_13_1to1_13_2.Protocol1_13_1To1_13_2)1 Protocol1_13_2To1_14 (com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14)1 Protocol1_13To1_13_1 (com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1)1 Protocol1_14_1To1_14_2 (com.viaversion.viabackwards.protocol.protocol1_14_1to1_14_2.Protocol1_14_1To1_14_2)1 Protocol1_14_2To1_14_3 (com.viaversion.viabackwards.protocol.protocol1_14_2to1_14_3.Protocol1_14_2To1_14_3)1 Protocol1_14_3To1_14_4 (com.viaversion.viabackwards.protocol.protocol1_14_3to1_14_4.Protocol1_14_3To1_14_4)1 Protocol1_14_4To1_15 (com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15)1 Protocol1_14To1_14_1 (com.viaversion.viabackwards.protocol.protocol1_14to1_14_1.Protocol1_14To1_14_1)1 Protocol1_15_1To1_15_2 (com.viaversion.viabackwards.protocol.protocol1_15_1to1_15_2.Protocol1_15_1To1_15_2)1