Search in sources :

Example 6 with RecipeRewriter1_16

use of com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16 in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetCooldown(ClientboundPackets1_17_1.COOLDOWN);
    registerWindowItems1_17_1(ClientboundPackets1_17_1.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, Type.FLAT_VAR_INT_ITEM);
    registerTradeList(ClientboundPackets1_17_1.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
    registerSetSlot1_17_1(ClientboundPackets1_17_1.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
    registerAdvancements(ClientboundPackets1_17_1.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
    registerEntityEquipmentArray(ClientboundPackets1_17_1.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
    protocol.registerClientbound(ClientboundPackets1_17_1.EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Effect id
            map(Type.INT);
            // Location
            map(Type.POSITION1_14);
            // Data
            map(Type.INT);
            handler(wrapper -> {
                int id = wrapper.get(Type.INT, 0);
                int data = wrapper.get(Type.INT, 1);
                if (id == 1010) {
                    // Play record
                    wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_17_1.SPAWN_PARTICLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Particle id
            map(Type.INT);
            // Override limiter
            map(Type.BOOLEAN);
            // X
            map(Type.DOUBLE);
            // Y
            map(Type.DOUBLE);
            // Z
            map(Type.DOUBLE);
            // Offset X
            map(Type.FLOAT);
            // Offset Y
            map(Type.FLOAT);
            // Offset Z
            map(Type.FLOAT);
            // Max speed
            map(Type.FLOAT);
            // Particle Count
            map(Type.INT);
            handler(wrapper -> {
                int id = wrapper.get(Type.INT, 0);
                if (id == 2) {
                    // Barrier
                    // Block marker
                    wrapper.set(Type.INT, 0, 3);
                    wrapper.write(Type.VAR_INT, 7754);
                    return;
                } else if (id == 3) {
                    // Light block
                    wrapper.write(Type.VAR_INT, 7786);
                    return;
                }
                ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
                if (mappings.isBlockParticle(id)) {
                    int data = wrapper.passthrough(Type.VAR_INT);
                    wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
                } else if (mappings.isItemParticle(id)) {
                    handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
                }
                int newId = protocol.getMappingData().getNewParticleId(id);
                if (newId != id) {
                    wrapper.set(Type.INT, 0, newId);
                }
            });
        }
    });
    new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_17_1.DECLARE_RECIPES);
    registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
    registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ItemRewriter(com.viaversion.viaversion.rewriter.ItemRewriter) Type(com.viaversion.viaversion.api.type.Type) ParticleMappings(com.viaversion.viaversion.api.data.ParticleMappings) ClientboundPackets1_17_1(com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1) ServerboundPackets1_17(com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) Protocol1_18To1_17_1(com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1) RecipeRewriter1_16(com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ParticleMappings(com.viaversion.viaversion.api.data.ParticleMappings)

Aggregations

PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)6 Type (com.viaversion.viaversion.api.type.Type)6 RecipeRewriter1_16 (com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16)6 ServerboundPackets1_17 (com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17)4 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)3 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)3 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)3 ClientboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2)3 ServerboundPackets1_16_2 (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2)3 ItemRewriter (com.viaversion.viaversion.rewriter.ItemRewriter)3 ItemRewriter (com.viaversion.viabackwards.api.rewriters.ItemRewriter)2 ParticleMappings (com.viaversion.viaversion.api.data.ParticleMappings)2 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)2 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)2 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)2 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)2 Chunk1_16_2Type (com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type)2 ClientboundPackets1_17_1 (com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1)2 ClientboundPackets1_17 (com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17)2