Search in sources :

Example 76 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class WorldPackets1_13_1 method register.

public static void register(Protocol protocol) {
    BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
    protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
                    for (ChunkSection section : chunk.getSections()) {
                        if (section != null) {
                            for (int i = 0; i < section.getPaletteSize(); i++) {
                                section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
                            }
                        }
                    }
                }
            });
        }
    });
    blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
    blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
    blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
    blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001);
}
Also used : BlockRewriter(com.viaversion.viaversion.rewriter.BlockRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Chunk1_13Type(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 77 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class Protocol1_14_3To1_14_4 method registerPackets.

@Override
protected void registerPackets() {
    // Acknowledge Player Digging - added in pre4
    registerClientbound(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING, ClientboundPackets1_14.BLOCK_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.POSITION1_14);
            map(Type.VAR_INT);
            handler(wrapper -> {
                int status = wrapper.read(Type.VAR_INT);
                boolean allGood = wrapper.read(Type.BOOLEAN);
                if (allGood && status == 0) {
                    wrapper.cancel();
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    wrapper.passthrough(Type.VAR_INT);
                    int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                    for (int i = 0; i < size; i++) {
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        if (wrapper.passthrough(Type.BOOLEAN)) {
                            wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        }
                        wrapper.passthrough(Type.BOOLEAN);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.FLOAT);
                        // demand value added in pre-5
                        wrapper.read(Type.INT);
                    }
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)

Example 78 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class Protocol1_14_4To1_15 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
    translatableRewriter.registerChatMessage(ClientboundPackets1_15.CHAT_MESSAGE);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_15.DISCONNECT);
    translatableRewriter.registerOpenWindow(ClientboundPackets1_15.OPEN_WINDOW);
    translatableRewriter.registerTabList(ClientboundPackets1_15.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_15.TITLE);
    translatableRewriter.registerPing();
    (blockItemPackets = new BlockItemPackets1_15(this)).register();
    entityRewriter.register();
    SoundRewriter soundRewriter = new SoundRewriter(this);
    soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
    soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
    soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND);
    soundRewriter.registerStopSound(ClientboundPackets1_15.STOP_SOUND);
    // Explosion - manually send an explosion sound
    registerClientbound(ClientboundPackets1_15.EXPLOSION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // x
            map(Type.FLOAT);
            // y
            map(Type.FLOAT);
            // z
            map(Type.FLOAT);
            handler(wrapper -> {
                PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_14.SOUND);
                // entity.generic.explode
                soundPacket.write(Type.VAR_INT, 243);
                // blocks category
                soundPacket.write(Type.VAR_INT, 4);
                // x
                soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 0)));
                // y
                soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 1)));
                // z
                soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 2)));
                // volume
                soundPacket.write(Type.FLOAT, 4F);
                // pitch - usually semi randomized by the server, but we don't really have to care about that
                soundPacket.write(Type.FLOAT, 1F);
                soundPacket.send(Protocol1_14_4To1_15.class);
            });
        }

        private int toEffectCoordinate(float coordinate) {
            return (int) (coordinate * 8);
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
    new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
}
Also used : BlockItemPackets1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPackets1_15) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) Entity1_15Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ServerboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ImmediateRespawn(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.data.ImmediateRespawn) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BlockItemPackets1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPackets1_15) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) Protocol1_15To1_14_4(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ClientboundPackets1_15(com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15) ClientboundPackets1_14(com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) EntityPackets1_15(com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets.EntityPackets1_15) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter)

Example 79 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class Protocol1_13_2To1_14 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::load);
    translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR);
    translatableRewriter.registerChatMessage(ClientboundPackets1_14.CHAT_MESSAGE);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_14.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_14.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_14.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_14.TITLE);
    translatableRewriter.registerPing();
    new CommandRewriter1_14(this).registerDeclareCommands(ClientboundPackets1_14.DECLARE_COMMANDS);
    blockItemPackets = new BlockItemPackets1_14(this);
    blockItemPackets.register();
    entityRewriter.register();
    new PlayerPackets1_14(this).register();
    new SoundPackets1_14(this).register();
    new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
    cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
    cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
    cancelClientbound(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING);
    registerClientbound(ClientboundPackets1_14.TAGS, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int blockTagsSize = wrapper.passthrough(Type.VAR_INT);
                    for (int i = 0; i < blockTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                        for (int j = 0; j < blockIds.length; j++) {
                            int id = blockIds[j];
                            // Ignore new blocktags
                            int blockId = getMappingData().getNewBlockId(id);
                            blockIds[j] = blockId;
                        }
                    }
                    int itemTagsSize = wrapper.passthrough(Type.VAR_INT);
                    for (int i = 0; i < itemTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                        for (int j = 0; j < itemIds.length; j++) {
                            int itemId = itemIds[j];
                            // Ignore new itemtags
                            int oldId = getMappingData().getItemMappings().get(itemId);
                            itemIds[j] = oldId;
                        }
                    }
                    // fluid tags
                    int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
                    for (int i = 0; i < fluidTagsSize; i++) {
                        wrapper.passthrough(Type.STRING);
                        wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                    }
                    // Eat entity tags
                    int entityTagsSize = wrapper.read(Type.VAR_INT);
                    for (int i = 0; i < entityTagsSize; i++) {
                        wrapper.read(Type.STRING);
                        wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_14.UPDATE_LIGHT, null, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int x = wrapper.read(Type.VAR_INT);
                    int z = wrapper.read(Type.VAR_INT);
                    int skyLightMask = wrapper.read(Type.VAR_INT);
                    int blockLightMask = wrapper.read(Type.VAR_INT);
                    int emptySkyLightMask = wrapper.read(Type.VAR_INT);
                    int emptyBlockLightMask = wrapper.read(Type.VAR_INT);
                    byte[][] skyLight = new byte[16][];
                    // we don't need void and +256 light
                    if (isSet(skyLightMask, 0)) {
                        wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                    }
                    for (int i = 0; i < 16; i++) {
                        if (isSet(skyLightMask, i + 1)) {
                            skyLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                        } else if (isSet(emptySkyLightMask, i + 1)) {
                            skyLight[i] = ChunkLightStorage.EMPTY_LIGHT;
                        }
                    }
                    if (isSet(skyLightMask, 17)) {
                        wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                    }
                    byte[][] blockLight = new byte[16][];
                    if (isSet(blockLightMask, 0)) {
                        wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                    }
                    for (int i = 0; i < 16; i++) {
                        if (isSet(blockLightMask, i + 1)) {
                            blockLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                        } else if (isSet(emptyBlockLightMask, i + 1)) {
                            blockLight[i] = ChunkLightStorage.EMPTY_LIGHT;
                        }
                    }
                    if (isSet(blockLightMask, 17)) {
                        wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
                    }
                    // TODO Soft memory leak: Don't store light if chunk is already loaded
                    wrapper.user().get(ChunkLightStorage.class).setStoredLight(skyLight, blockLight, x, z);
                    wrapper.cancel();
                }

                private boolean isSet(int mask, int i) {
                    return (mask & (1 << i)) != 0;
                }
            });
        }
    });
}
Also used : BlockItemPackets1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.BlockItemPackets1_14) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) CommandRewriter1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.data.CommandRewriter1_14) PlayerPackets1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.PlayerPackets1_14) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ChunkLightStorage(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage) SoundPackets1_14(com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.packets.SoundPackets1_14)

Example 80 with PacketRemapper

use of com.viaversion.viaversion.api.protocol.remapper.PacketRemapper in project ViaBackwards by ViaVersion.

the class Protocol1_9_4To1_10 method registerPackets.

protected void registerPackets() {
    entityPackets.register();
    blockItemPackets.register();
    SoundRewriter soundRewriter = new SoundRewriter(this);
    registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sound name
            map(Type.STRING);
            // 1 - Sound Category
            map(Type.VAR_INT);
            // 2 - x
            map(Type.INT);
            // 3 - y
            map(Type.INT);
            // 4 - z
            map(Type.INT);
            // 5 - Volume
            map(Type.FLOAT);
            // 6 - Pitch
            map(Type.FLOAT, TO_OLD_PITCH);
            handler(soundRewriter.getNamedSoundHandler());
        }
    });
    registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sound name
            map(Type.VAR_INT);
            // 1 - Sound Category
            map(Type.VAR_INT);
            // 2 - x
            map(Type.INT);
            // 3 - y
            map(Type.INT);
            // 4 - z
            map(Type.INT);
            // 5 - Volume
            map(Type.FLOAT);
            // 6 - Pitch
            map(Type.FLOAT, TO_OLD_PITCH);
            handler(soundRewriter.getSoundHandler());
        }
    });
    registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Hash
            map(Type.STRING, Type.NOTHING);
            // 1 - Result
            map(Type.VAR_INT);
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) SoundRewriter(com.viaversion.viabackwards.api.rewriters.SoundRewriter)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)109 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)78 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)65 Type (com.viaversion.viaversion.api.type.Type)64 Item (com.viaversion.viaversion.api.minecraft.item.Item)31 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)24 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)24 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)21 Via (com.viaversion.viaversion.api.Via)19 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)19 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)17 ArrayList (java.util.ArrayList)17 List (java.util.List)17 Metadata (com.viaversion.viaversion.api.minecraft.metadata.Metadata)16 Position (com.viaversion.viaversion.api.minecraft.Position)14 EntityType (com.viaversion.viaversion.api.minecraft.entities.EntityType)14 ClientboundPackets1_13 (com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13)14 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)13 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)13 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)13