Search in sources :

Example 6 with SoundRewriter

use of com.viaversion.viabackwards.api.rewriters.SoundRewriter 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 7 with SoundRewriter

use of com.viaversion.viabackwards.api.rewriters.SoundRewriter 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 8 with SoundRewriter

use of com.viaversion.viabackwards.api.rewriters.SoundRewriter 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

SoundRewriter (com.viaversion.viabackwards.api.rewriters.SoundRewriter)8 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)7 Type (com.viaversion.viaversion.api.type.Type)5 TagRewriter (com.viaversion.viaversion.rewriter.TagRewriter)5 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)4 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)4 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)4 RegistryType (com.viaversion.viaversion.api.minecraft.RegistryType)4 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)4 EntityRewriter (com.viaversion.viaversion.api.rewriter.EntityRewriter)4 EntityTrackerBase (com.viaversion.viaversion.data.entity.EntityTrackerBase)4 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)4 BackwardsMappings (com.viaversion.viabackwards.api.data.BackwardsMappings)3 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)2 JsonElement (com.viaversion.viaversion.libs.gson.JsonElement)2 ClientboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14)2 ServerboundPackets1_14 (com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14)2 ClientboundPackets1_15 (com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15)2 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)2 ServerboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2)2