Search in sources :

Example 1 with InventoryQuickMoveProvider

use of com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider in project ViaVersion by ViaVersion.

the class InventoryPackets method registerPackets.

@Override
public void registerPackets() {
    registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
    registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
    registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM);
    // Plugin message Packet -> Trading
    protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Channel
            map(Type.STRING);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
                        // Passthrough Window ID
                        wrapper.passthrough(Type.INT);
                        int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                        for (int i = 0; i < size; i++) {
                            // Input Item
                            handleItemToClient(wrapper.passthrough(Type.ITEM));
                            // Output Item
                            handleItemToClient(wrapper.passthrough(Type.ITEM));
                            // Has second item
                            boolean secondItem = wrapper.passthrough(Type.BOOLEAN);
                            if (secondItem) {
                                // Second Item
                                handleItemToClient(wrapper.passthrough(Type.ITEM));
                            }
                            // Trade disabled
                            wrapper.passthrough(Type.BOOLEAN);
                            // Number of tools uses
                            wrapper.passthrough(Type.INT);
                            // Maximum number of trade uses
                            wrapper.passthrough(Type.INT);
                        }
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_12.CLICK_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Slot
            map(Type.SHORT);
            // 2 - Button
            map(Type.BYTE);
            // 3 - Action number
            map(Type.SHORT);
            // 4 - Mode
            map(Type.VAR_INT);
            // 5 - Clicked Item
            map(Type.ITEM);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item item = wrapper.get(Type.ITEM, 0);
                    if (!Via.getConfig().is1_12QuickMoveActionFix()) {
                        handleItemToServer(item);
                        return;
                    }
                    byte button = wrapper.get(Type.BYTE, 0);
                    int mode = wrapper.get(Type.VAR_INT, 0);
                    // QUICK_MOVE PATCH (Shift + (click/double click))
                    if (mode == 1 && button == 0 && item == null) {
                        short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
                        short slotId = wrapper.get(Type.SHORT, 0);
                        short actionId = wrapper.get(Type.SHORT, 1);
                        InventoryQuickMoveProvider provider = Via.getManager().getProviders().get(InventoryQuickMoveProvider.class);
                        boolean succeed = provider.registerQuickMoveAction(windowId, slotId, actionId, wrapper.user());
                        if (succeed) {
                            wrapper.cancel();
                        }
                    // otherwise just pass through so the server sends the PacketPlayOutTransaction packet.
                    } else {
                        handleItemToServer(item);
                    }
                }
            });
        }
    });
    // Creative Inventory Action
    registerCreativeInvAction(ServerboundPackets1_12.CREATIVE_INVENTORY_ACTION, Type.ITEM);
}
Also used : Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryQuickMoveProvider(com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider)

Aggregations

Item (com.viaversion.viaversion.api.minecraft.item.Item)1 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)1 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)1 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)1 InventoryQuickMoveProvider (com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider)1