Search in sources :

Example 1 with ServerboundPackets1_9

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9 in project ViaVersion by ViaVersion.

the class EntityPackets method register.

public static void register(Protocol1_9To1_8 protocol) {
    // Attach Entity Packet
    protocol.registerClientbound(ClientboundPackets1_8.ATTACH_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.INT);
            // 1 - Vehicle
            map(Type.INT);
            // Leash boolean is removed in new versions
            map(Type.BOOLEAN, new ValueTransformer<Boolean, Void>(Type.NOTHING) {

                @Override
                public Void transform(PacketWrapper wrapper, Boolean inputValue) throws Exception {
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (!inputValue) {
                        int passenger = wrapper.get(Type.INT, 0);
                        int vehicle = wrapper.get(Type.INT, 1);
                        // Don't send current packet
                        wrapper.cancel();
                        PacketWrapper passengerPacket = wrapper.create(ClientboundPackets1_9.SET_PASSENGERS);
                        if (vehicle == -1) {
                            if (!tracker.getVehicleMap().containsKey(passenger))
                                // Cancel
                                return null;
                            passengerPacket.write(Type.VAR_INT, tracker.getVehicleMap().remove(passenger));
                            passengerPacket.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] {});
                        } else {
                            passengerPacket.write(Type.VAR_INT, vehicle);
                            passengerPacket.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { passenger });
                            tracker.getVehicleMap().put(passenger, vehicle);
                        }
                        // Send the packet
                        passengerPacket.send(Protocol1_9To1_8.class);
                    }
                    return null;
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_TELEPORT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - X - Needs to be divide by 32
            map(Type.INT, SpawnPackets.toNewDouble);
            // 2 - Y - Needs to be divide by 32
            map(Type.INT, SpawnPackets.toNewDouble);
            // 3 - Z - Needs to be divide by 32
            map(Type.INT, SpawnPackets.toNewDouble);
            // 4 - Pitch
            map(Type.BYTE);
            // 5 - Yaw
            map(Type.BYTE);
            // 6 - On Ground
            map(Type.BOOLEAN);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    if (Via.getConfig().isHologramPatch()) {
                        EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        if (tracker.getKnownHolograms().contains(entityID)) {
                            Double newValue = wrapper.get(Type.DOUBLE, 1);
                            newValue += (Via.getConfig().getHologramYOffset());
                            wrapper.set(Type.DOUBLE, 1, newValue);
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION_AND_ROTATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - X
            map(Type.BYTE, toNewShort);
            // 2 - Y
            map(Type.BYTE, toNewShort);
            // 3 - Z
            map(Type.BYTE, toNewShort);
            // 4 - Yaw
            map(Type.BYTE);
            // 5 - Pitch
            map(Type.BYTE);
            // 6 - On Ground
            map(Type.BOOLEAN);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - X
            map(Type.BYTE, toNewShort);
            // 2 - Y
            map(Type.BYTE, toNewShort);
            // 3 - Z
            map(Type.BYTE, toNewShort);
            // 4 - On Ground
            map(Type.BOOLEAN);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EQUIPMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Slot ID
            map(Type.SHORT, new ValueTransformer<Short, Integer>(Type.VAR_INT) {

                @Override
                public Integer transform(PacketWrapper wrapper, Short slot) throws Exception {
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    int receiverId = wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId();
                    // (In 1.9+, every client treats the received the same: 0=hand, 1=offhand, 2-5=armor)
                    if (entityId == receiverId) {
                        return slot.intValue() + 2;
                    }
                    return slot > 0 ? slot.intValue() + 1 : slot.intValue();
                }
            });
            // 2 - Item
            map(Type.ITEM);
            // Item Rewriter
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item stack = wrapper.get(Type.ITEM, 0);
                    ItemRewriter.toClient(stack);
                }
            });
            // Blocking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    Item stack = wrapper.get(Type.ITEM, 0);
                    if (stack != null) {
                        if (Protocol1_9To1_8.isSword(stack.identifier())) {
                            entityTracker.getValidBlocking().add(entityID);
                            return;
                        }
                    }
                    entityTracker.getValidBlocking().remove(entityID);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_METADATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Metadata List
            map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityId = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (tracker.hasEntity(entityId)) {
                        protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
                    } else {
                        // Buffer
                        tracker.addMetadataToBuffer(entityId, metadataList);
                        wrapper.cancel();
                    }
                }
            });
            // Handler for meta data
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    int entityID = wrapper.get(Type.VAR_INT, 0);
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.handleMetadata(entityID, metadataList);
                }
            });
            // Cancel packet if list empty
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
                    if (metadataList.isEmpty()) {
                        wrapper.cancel();
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Effect ID
            map(Type.BYTE);
            // 2 - Amplifier
            map(Type.BYTE);
            // 3 - Duration
            map(Type.VAR_INT);
            handler(new // Handle effect indicator
            PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // In 1.8 = true->Show particles : false->Hide particles
                    boolean showParticles = wrapper.read(Type.BOOLEAN);
                    boolean newEffect = Via.getConfig().isNewEffectIndicator();
                    // 0: hide, 1: shown without indictator, 2: shown with indicator, 3: hide with beacon indicator but we don't use it.
                    wrapper.write(Type.BYTE, (byte) (showParticles ? newEffect ? 2 : 1 : 0));
                }
            });
        }
    });
    protocol.cancelClientbound(ClientboundPackets1_8.UPDATE_ENTITY_NBT);
    protocol.registerClientbound(ClientboundPackets1_8.COMBAT_EVENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Event id
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.VAR_INT, 0) == 2) {
                        // entity dead
                        // Player id
                        wrapper.passthrough(Type.VAR_INT);
                        // Entity id
                        wrapper.passthrough(Type.INT);
                        Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_PROPERTIES, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (!Via.getConfig().isMinimizeCooldown())
                        return;
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (wrapper.get(Type.VAR_INT, 0) != tracker.getProvidedEntityId()) {
                        return;
                    }
                    int propertiesToRead = wrapper.read(Type.INT);
                    Map<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> properties = new HashMap<>(propertiesToRead);
                    for (int i = 0; i < propertiesToRead; i++) {
                        String key = wrapper.read(Type.STRING);
                        Double value = wrapper.read(Type.DOUBLE);
                        int modifiersToRead = wrapper.read(Type.VAR_INT);
                        List<Triple<UUID, Double, Byte>> modifiers = new ArrayList<>(modifiersToRead);
                        for (int j = 0; j < modifiersToRead; j++) {
                            modifiers.add(new Triple<>(wrapper.read(Type.UUID), // Amount
                            wrapper.read(Type.DOUBLE), // Operation
                            wrapper.read(Type.BYTE)));
                        }
                        properties.put(key, new Pair<>(value, modifiers));
                    }
                    // == Why 15.9? ==
                    // Higher values hides the cooldown but it bugs visual animation on hand
                    // when removing item from hand with inventory gui
                    properties.put("generic.attackSpeed", new Pair<Double, List<Triple<UUID, Double, Byte>>>(15.9, // Neutralize modifiers
                    ImmutableList.of(// Tool and weapon modifier
                    new Triple<>(UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"), 0.0, (byte) 0), // Dig speed
                    new Triple<>(UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3"), 0.0, (byte) 2), // Dig slow down
                    new Triple<>(UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386"), 0.0, (byte) 2))));
                    wrapper.write(Type.INT, properties.size());
                    for (Map.Entry<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> entry : properties.entrySet()) {
                        // Key
                        wrapper.write(Type.STRING, entry.getKey());
                        // Value
                        wrapper.write(Type.DOUBLE, entry.getValue().key());
                        wrapper.write(Type.VAR_INT, entry.getValue().value().size());
                        for (Triple<UUID, Double, Byte> modifier : entry.getValue().value()) {
                            wrapper.write(Type.UUID, modifier.first());
                            // Amount
                            wrapper.write(Type.DOUBLE, modifier.second());
                            // Operation
                            wrapper.write(Type.BYTE, modifier.third());
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.ENTITY_ANIMATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID
            map(Type.VAR_INT);
            // 1 - Animation
            map(Type.UNSIGNED_BYTE);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) {
                        wrapper.cancel();
                    }
                }
            });
        }
    });
    /* Incoming Packets */
    protocol.registerServerbound(ServerboundPackets1_9.ENTITY_ACTION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Player ID
            map(Type.VAR_INT);
            // 1 - Action
            map(Type.VAR_INT);
            // 2 - Jump
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int action = wrapper.get(Type.VAR_INT, 1);
                    if (action == 6 || action == 8)
                        wrapper.cancel();
                    if (action == 7) {
                        wrapper.set(Type.VAR_INT, 1, 6);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.INTERACT_ENTITY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Entity ID (Target)
            map(Type.VAR_INT);
            // 1 - Action Type
            map(Type.VAR_INT);
            // Cancel second hand to prevent double interact
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int type = wrapper.get(Type.VAR_INT, 1);
                    if (type == 2) {
                        // 2 - X
                        wrapper.passthrough(Type.FLOAT);
                        // 3 - Y
                        wrapper.passthrough(Type.FLOAT);
                        // 4 - Z
                        wrapper.passthrough(Type.FLOAT);
                    }
                    if (type == 0 || type == 2) {
                        // 2/5 - Hand
                        int hand = wrapper.read(Type.VAR_INT);
                        if (hand == 1)
                            wrapper.cancel();
                    }
                }
            });
        }
    });
}
Also used : HashMap(java.util.HashMap) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Metadata(com.viaversion.viaversion.api.minecraft.metadata.Metadata) ArrayList(java.util.ArrayList) Item(com.viaversion.viaversion.api.minecraft.item.Item) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MetadataRewriter1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8) UUID(java.util.UUID) Pair(com.viaversion.viaversion.util.Pair) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) Triple(com.viaversion.viaversion.util.Triple) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) HashMap(java.util.HashMap) Map(java.util.Map) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Example 2 with ServerboundPackets1_9

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9 in project ViaVersion by ViaVersion.

the class PlayerPackets method register.

public static void register(Protocol1_9To1_8 protocol) {
    protocol.registerClientbound(ClientboundPackets1_8.CHAT_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Chat Message (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 1 - Chat Positon
            map(Type.BYTE);
            handler(wrapper -> {
                try {
                    JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0);
                    ChatRewriter.toClient(obj, wrapper.user());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.TAB_LIST, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Header
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 1 - Footer
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.DISCONNECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Reason
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action
            map(Type.VAR_INT);
            // We only handle if the title or subtitle is set then just write through.
            handler(wrapper -> {
                int action = wrapper.get(Type.VAR_INT, 0);
                if (action == 0 || action == 1) {
                    Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
                }
            });
        // Everything else is handled.
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.PLAYER_POSITION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Player X
            map(Type.DOUBLE);
            // 1 - Player Y
            map(Type.DOUBLE);
            // 2 - Player Z
            map(Type.DOUBLE);
            // 3 - Player Yaw
            map(Type.FLOAT);
            // 4 - Player Pitch
            map(Type.FLOAT);
            // 5 - Player Flags
            map(Type.BYTE);
            handler(wrapper -> {
                // 6 - Teleport ID was added
                wrapper.write(Type.VAR_INT, 0);
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.TEAMS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Team Name
            map(Type.STRING);
            // 1 - Mode
            map(Type.BYTE);
            handler(wrapper -> {
                // Mode
                byte mode = wrapper.get(Type.BYTE, 0);
                if (mode == 0 || mode == 2) {
                    // Display Name
                    wrapper.passthrough(Type.STRING);
                    // Prefix
                    wrapper.passthrough(Type.STRING);
                    // Suffix
                    wrapper.passthrough(Type.STRING);
                    // Friendly Fire
                    wrapper.passthrough(Type.BYTE);
                    // Name tag visibility
                    wrapper.passthrough(Type.STRING);
                    wrapper.write(Type.STRING, Via.getConfig().isPreventCollision() ? "never" : "");
                    // Colour
                    wrapper.passthrough(Type.BYTE);
                }
                if (mode == 0 || mode == 3 || mode == 4) {
                    // Players
                    String[] players = wrapper.passthrough(Type.STRING_ARRAY);
                    final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    String myName = wrapper.user().getProtocolInfo().getUsername();
                    String teamName = wrapper.get(Type.STRING, 0);
                    for (String player : players) {
                        if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
                            if (mode == 4) {
                                // since removing add to auto team
                                // Workaround for packet order issue
                                wrapper.send(Protocol1_9To1_8.class);
                                wrapper.cancel();
                                entityTracker.sendTeamPacket(true, true);
                                entityTracker.setCurrentTeam("viaversion");
                            } else {
                                // since adding remove from auto team
                                entityTracker.sendTeamPacket(false, true);
                                entityTracker.setCurrentTeam(teamName);
                            }
                        }
                    }
                }
                if (mode == 1) {
                    // Remove team
                    final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    String teamName = wrapper.get(Type.STRING, 0);
                    if (entityTracker.isAutoTeam() && teamName.equals(entityTracker.getCurrentTeam())) {
                        // team was removed
                        // Workaround for packet order issue
                        wrapper.send(Protocol1_9To1_8.class);
                        wrapper.cancel();
                        entityTracker.sendTeamPacket(true, true);
                        entityTracker.setCurrentTeam("viaversion");
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.JOIN_GAME, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Player ID
            map(Type.INT);
            // Parse this info
            handler(wrapper -> {
                int entityId = wrapper.get(Type.INT, 0);
                EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
                tracker.setClientEntityId(entityId);
            });
            // 1 - Player Gamemode
            map(Type.UNSIGNED_BYTE);
            // 2 - Player Dimension
            map(Type.BYTE);
            // 3 - World Difficulty
            map(Type.UNSIGNED_BYTE);
            // 4 - Max Players (Tab)
            map(Type.UNSIGNED_BYTE);
            // 5 - Level Type
            map(Type.STRING);
            // 6 - Reduced Debug info
            map(Type.BOOLEAN);
            handler(wrapper -> {
                EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                // Set player gamemode
                tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0)));
            });
            // Track player's dimension
            handler(wrapper -> {
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                int dimensionId = wrapper.get(Type.BYTE, 0);
                clientWorld.setEnvironment(dimensionId);
            });
            // Gotta fake their op
            handler(wrapper -> {
                CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
                provider.sendPermission(wrapper.user());
            });
            // Scoreboard will be cleared when join game is received
            handler(wrapper -> {
                EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                if (Via.getConfig().isAutoTeam()) {
                    entityTracker.setAutoTeam(true);
                    // Workaround for packet order issue
                    wrapper.send(Protocol1_9To1_8.class);
                    wrapper.cancel();
                    entityTracker.sendTeamPacket(true, true);
                    entityTracker.setCurrentTeam("viaversion");
                } else {
                    entityTracker.setAutoTeam(false);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.PLAYER_INFO, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action
            map(Type.VAR_INT);
            // 1 - Player Count
            map(Type.VAR_INT);
            // Due to this being a complex data structure we just use a handler.
            handler(wrapper -> {
                int action = wrapper.get(Type.VAR_INT, 0);
                int count = wrapper.get(Type.VAR_INT, 1);
                for (int i = 0; i < count; i++) {
                    // Player UUID
                    wrapper.passthrough(Type.UUID);
                    if (action == 0) {
                        // add player
                        // Player Name
                        wrapper.passthrough(Type.STRING);
                        int properties = wrapper.passthrough(Type.VAR_INT);
                        // loop through properties
                        for (int j = 0; j < properties; j++) {
                            // name
                            wrapper.passthrough(Type.STRING);
                            // value
                            wrapper.passthrough(Type.STRING);
                            boolean isSigned = wrapper.passthrough(Type.BOOLEAN);
                            if (isSigned) {
                                // signature
                                wrapper.passthrough(Type.STRING);
                            }
                        }
                        // gamemode
                        wrapper.passthrough(Type.VAR_INT);
                        // ping
                        wrapper.passthrough(Type.VAR_INT);
                        boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
                        if (hasDisplayName) {
                            // display name
                            Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
                        }
                    } else if ((action == 1) || (action == 2)) {
                        // update gamemode || update latency
                        wrapper.passthrough(Type.VAR_INT);
                    } else if (action == 3) {
                        // update display name
                        boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
                        if (hasDisplayName) {
                            // display name
                            Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
                        }
                    } else if (action == 4) {
                    // remove player
                    // no fields
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.PLUGIN_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Channel Name
            map(Type.STRING);
            handler(wrapper -> {
                String name = wrapper.get(Type.STRING, 0);
                if (name.equalsIgnoreCase("MC|BOpen")) {
                    // Not used anymore
                    wrapper.read(Type.REMAINING_BYTES);
                    wrapper.write(Type.VAR_INT, 0);
                }
                if (name.equalsIgnoreCase("MC|TrList")) {
                    // ID
                    wrapper.passthrough(Type.INT);
                    Short size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                    for (int i = 0; i < size; ++i) {
                        Item item1 = wrapper.passthrough(Type.ITEM);
                        ItemRewriter.toClient(item1);
                        Item item2 = wrapper.passthrough(Type.ITEM);
                        ItemRewriter.toClient(item2);
                        boolean present = wrapper.passthrough(Type.BOOLEAN);
                        if (present) {
                            Item item3 = wrapper.passthrough(Type.ITEM);
                            ItemRewriter.toClient(item3);
                        }
                        wrapper.passthrough(Type.BOOLEAN);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.RESPAWN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Dimension
            map(Type.INT);
            // 1 - Difficulty
            map(Type.UNSIGNED_BYTE);
            // 2 - GameMode
            map(Type.UNSIGNED_BYTE);
            // 3 - Level Type
            map(Type.STRING);
            // Track player's dimension
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                    int dimensionId = wrapper.get(Type.INT, 0);
                    clientWorld.setEnvironment(dimensionId);
                }
            });
            handler(wrapper -> {
                // Client unloads chunks on respawn
                wrapper.user().get(ClientChunks.class).getLoadedChunks().clear();
                int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0);
                EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                tracker.setGameMode(GameMode.getById(gamemode));
            });
            // Fake permissions to get Commandblocks working
            handler(wrapper -> {
                CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
                provider.sendPermission(wrapper.user());
                provider.unloadChunks(wrapper.user());
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.GAME_EVENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Reason
            map(Type.UNSIGNED_BYTE);
            // 1 - Value
            map(Type.FLOAT);
            handler(wrapper -> {
                short reason = wrapper.get(Type.UNSIGNED_BYTE, 0);
                if (reason == 3) {
                    // Change gamemode
                    int gamemode = wrapper.get(Type.FLOAT, 0).intValue();
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.setGameMode(GameMode.getById(gamemode));
                } else if (reason == 4) {
                    // Open credits screen
                    wrapper.set(Type.FLOAT, 0, 1F);
                }
            });
        }
    });
    /* Removed packets */
    protocol.registerClientbound(ClientboundPackets1_8.SET_COMPRESSION, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                wrapper.cancel();
                CompressionProvider provider = Via.getManager().getProviders().get(CompressionProvider.class);
                provider.handlePlayCompression(wrapper.user(), wrapper.read(Type.VAR_INT));
            });
        }
    });
    /* Incoming Packets */
    protocol.registerServerbound(ServerboundPackets1_9.TAB_COMPLETE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Requested Command
            map(Type.STRING);
            // 1 - Is Command Block
            map(Type.BOOLEAN, Type.NOTHING);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.CLIENT_SETTINGS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - locale
            map(Type.STRING);
            // 1 - View Distance
            map(Type.BYTE);
            // 2 - Chat Mode
            map(Type.VAR_INT, Type.BYTE);
            // 3 - If Chat Colours on
            map(Type.BOOLEAN);
            // 4 - Skin Parts
            map(Type.UNSIGNED_BYTE);
            handler(wrapper -> {
                int hand = wrapper.read(Type.VAR_INT);
                if (Via.getConfig().isLeftHandedHandling()) {
                    // Add 0x80 if left handed
                    if (hand == 0)
                        wrapper.set(Type.UNSIGNED_BYTE, 0, (short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80));
                }
                wrapper.sendToServer(Protocol1_9To1_8.class);
                wrapper.cancel();
                Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.ANIMATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Hand
            map(Type.VAR_INT, Type.NOTHING);
        }
    });
    protocol.cancelServerbound(ServerboundPackets1_9.TELEPORT_CONFIRM);
    protocol.cancelServerbound(ServerboundPackets1_9.VEHICLE_MOVE);
    protocol.cancelServerbound(ServerboundPackets1_9.STEER_BOAT);
    protocol.registerServerbound(ServerboundPackets1_9.PLUGIN_MESSAGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Channel Name
            map(Type.STRING);
            handler(wrapper -> {
                String name = wrapper.get(Type.STRING, 0);
                if (name.equalsIgnoreCase("MC|BSign")) {
                    Item item = wrapper.passthrough(Type.ITEM);
                    if (item != null) {
                        // Written Book
                        item.setIdentifier(387);
                        ItemRewriter.rewriteBookToServer(item);
                    }
                }
                if (name.equalsIgnoreCase("MC|AutoCmd")) {
                    wrapper.set(Type.STRING, 0, "MC|AdvCdm");
                    wrapper.write(Type.BYTE, (byte) 0);
                    // X
                    wrapper.passthrough(Type.INT);
                    // Y
                    wrapper.passthrough(Type.INT);
                    // Z
                    wrapper.passthrough(Type.INT);
                    // Command
                    wrapper.passthrough(Type.STRING);
                    // Flag
                    wrapper.passthrough(Type.BOOLEAN);
                    wrapper.clearInputBuffer();
                }
                if (name.equalsIgnoreCase("MC|AdvCmd")) {
                    wrapper.set(Type.STRING, 0, "MC|AdvCdm");
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.CLIENT_STATUS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action ID
            map(Type.VAR_INT);
            handler(wrapper -> {
                int action = wrapper.get(Type.VAR_INT, 0);
                if (action == 2) {
                    // cancel any blocking >.>
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (tracker.isBlocking()) {
                        if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
                            tracker.setSecondHand(null);
                        }
                        tracker.setBlocking(false);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - X
            map(Type.DOUBLE);
            // 1 - Y
            map(Type.DOUBLE);
            // 2 - Z
            map(Type.DOUBLE);
            // 3 - Ground
            map(Type.BOOLEAN);
            handler(new PlayerMovementMapper());
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION_AND_ROTATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - X
            map(Type.DOUBLE);
            // 1 - Y
            map(Type.DOUBLE);
            // 2 - Z
            map(Type.DOUBLE);
            // 3 - Yaw
            map(Type.FLOAT);
            // 4 - Pitch
            map(Type.FLOAT);
            // 5 - Ground
            map(Type.BOOLEAN);
            handler(new PlayerMovementMapper());
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_ROTATION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Yaw
            map(Type.FLOAT);
            // 1 - Pitch
            map(Type.FLOAT);
            // 2 - Ground
            map(Type.BOOLEAN);
            handler(new PlayerMovementMapper());
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_MOVEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Ground
            map(Type.BOOLEAN);
            handler(new PlayerMovementMapper());
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PlayerMovementMapper(com.viaversion.viaversion.protocols.protocol1_9to1_8.PlayerMovementMapper) JsonObject(com.google.gson.JsonObject) GameMode(com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.GameMode) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) ChatRewriter(com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.ChatRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Via(com.viaversion.viaversion.api.Via) Entity1_10Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types) Item(com.viaversion.viaversion.api.minecraft.item.Item) CommandBlockProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) MainHandProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) ServerboundPackets1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9) CompressionProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider) ClientboundPackets1_8(com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8) ItemRewriter(com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter) ClientChunks(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) ClientChunks(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks) PlayerMovementMapper(com.viaversion.viaversion.protocols.protocol1_9to1_8.PlayerMovementMapper) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.google.gson.JsonObject) CommandBlockProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider) CompressionProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Example 3 with ServerboundPackets1_9

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9 in project ViaVersion by ViaVersion.

the class InventoryPackets method register.

public static void register(Protocol protocol) {
    protocol.registerClientbound(ClientboundPackets1_8.WINDOW_PROPERTY, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Property Key
            map(Type.SHORT);
            // 2 - Property Value
            map(Type.SHORT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    final short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    final short property = wrapper.get(Type.SHORT, 0);
                    short value = wrapper.get(Type.SHORT, 1);
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    if (inventoryTracker.getInventory() != null) {
                        if (inventoryTracker.getInventory().equalsIgnoreCase("minecraft:enchanting_table")) {
                            if (property > 3 && property < 7) {
                                // Send 2 properties, splitting it into enchantID & level
                                final short level = (short) (value >> 8);
                                final short enchantID = (short) (value & 0xFF);
                                wrapper.create(wrapper.getId(), new PacketHandler() {

                                    @Override
                                    public void handle(PacketWrapper wrapper) throws Exception {
                                        wrapper.write(Type.UNSIGNED_BYTE, windowId);
                                        wrapper.write(Type.SHORT, property);
                                        wrapper.write(Type.SHORT, enchantID);
                                    }
                                }).scheduleSend(Protocol1_9To1_8.class);
                                wrapper.set(Type.SHORT, 0, (short) (property + 3));
                                wrapper.set(Type.SHORT, 1, level);
                            }
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Window Type
            map(Type.STRING);
            // 2 - Window Title
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 3 - Slot Count
            map(Type.UNSIGNED_BYTE);
            // There is a horse parameter after this, we don't handle it and let it passthrough
            // Inventory tracking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    String inventory = wrapper.get(Type.STRING, 0);
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    inventoryTracker.setInventory(inventory);
                }
            });
            // Brewing patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    String inventory = wrapper.get(Type.STRING, 0);
                    if (inventory.equals("minecraft:brewing_stand")) {
                        wrapper.set(Type.UNSIGNED_BYTE, 1, (short) (wrapper.get(Type.UNSIGNED_BYTE, 1) + 1));
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.SET_SLOT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Slot ID
            map(Type.SHORT);
            // 2 - Slot Value
            map(Type.ITEM);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item stack = wrapper.get(Type.ITEM, 0);
                    boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() && Via.getConfig().isShieldBlocking();
                    // Check if it is the inventory of the player
                    if (showShieldWhenSwordInHand) {
                        InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                        EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        short slotID = wrapper.get(Type.SHORT, 0);
                        byte windowId = wrapper.get(Type.UNSIGNED_BYTE, 0).byteValue();
                        // Store item in slot
                        inventoryTracker.setItemId(windowId, slotID, stack == null ? 0 : stack.identifier());
                        // Sync shield item in offhand with main hand
                        entityTracker.syncShieldWithSword();
                    }
                    ItemRewriter.toClient(stack);
                }
            });
            // Brewing patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    short slotID = wrapper.get(Type.SHORT, 0);
                    if (inventoryTracker.getInventory() != null) {
                        if (inventoryTracker.getInventory().equals("minecraft:brewing_stand")) {
                            if (slotID >= 4) {
                                wrapper.set(Type.SHORT, 0, (short) (slotID + 1));
                            }
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.WINDOW_ITEMS, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // 1 - Window Values
            map(Type.ITEM_ARRAY);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item[] stacks = wrapper.get(Type.ITEM_ARRAY, 0);
                    Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() && Via.getConfig().isShieldBlocking();
                    for (short i = 0; i < stacks.length; i++) {
                        Item stack = stacks[i];
                        // Store items in slots
                        if (showShieldWhenSwordInHand) {
                            inventoryTracker.setItemId(windowId, i, stack == null ? 0 : stack.identifier());
                        }
                        ItemRewriter.toClient(stack);
                    }
                    // Sync shield item in offhand with main hand
                    if (showShieldWhenSwordInHand) {
                        entityTracker.syncShieldWithSword();
                    }
                }
            });
            // Brewing Patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    if (inventoryTracker.getInventory() != null) {
                        if (inventoryTracker.getInventory().equals("minecraft:brewing_stand")) {
                            Item[] oldStack = wrapper.get(Type.ITEM_ARRAY, 0);
                            Item[] newStack = new Item[oldStack.length + 1];
                            for (int i = 0; i < newStack.length; i++) {
                                if (i > 4) {
                                    newStack[i] = oldStack[i - 1];
                                } else {
                                    if (i != 4) {
                                        // Leave index 3 blank
                                        newStack[i] = oldStack[i];
                                    }
                                }
                            }
                            wrapper.set(Type.ITEM_ARRAY, 0, newStack);
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // Inventory tracking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    inventoryTracker.setInventory(null);
                    inventoryTracker.resetInventory(wrapper.get(Type.UNSIGNED_BYTE, 0));
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.MAP_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Map ID
            map(Type.VAR_INT);
            // 1 - Map Scale
            map(Type.BYTE);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) {
                    // 2 - Show marker
                    wrapper.write(Type.BOOLEAN, true);
                }
            });
        // Everything else is passed through
        }
    });
    /* Incoming Packets */
    protocol.registerServerbound(ServerboundPackets1_9.CREATIVE_INVENTORY_ACTION, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Slot ID
            map(Type.SHORT);
            // 1 - Item
            map(Type.ITEM);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item stack = wrapper.get(Type.ITEM, 0);
                    boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() && Via.getConfig().isShieldBlocking();
                    if (showShieldWhenSwordInHand) {
                        InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                        EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        short slotID = wrapper.get(Type.SHORT, 0);
                        // Update item in slot
                        inventoryTracker.setItemId((short) 0, slotID, stack == null ? 0 : stack.identifier());
                        // Sync shield item in offhand with main hand
                        entityTracker.syncShieldWithSword();
                    }
                    ItemRewriter.toServer(stack);
                }
            });
            // Elytra throw patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    final short slot = wrapper.get(Type.SHORT, 0);
                    boolean throwItem = (slot == 45);
                    if (throwItem) {
                        // Send a packet wiping the slot
                        wrapper.create(ClientboundPackets1_9.SET_SLOT, new PacketHandler() {

                            @Override
                            public void handle(PacketWrapper wrapper) throws Exception {
                                wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
                                wrapper.write(Type.SHORT, slot);
                                wrapper.write(Type.ITEM, null);
                            }
                        }).send(Protocol1_9To1_8.class);
                        // Finally reset to simulate throwing item
                        // Set slot to -999
                        wrapper.set(Type.SHORT, 0, (short) -999);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.CLICK_WINDOW, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item stack = wrapper.get(Type.ITEM, 0);
                    if (Via.getConfig().isShowShieldWhenSwordInHand()) {
                        Short windowId = wrapper.get(Type.UNSIGNED_BYTE, 0);
                        byte mode = wrapper.get(Type.BYTE, 1);
                        short hoverSlot = wrapper.get(Type.SHORT, 0);
                        byte button = wrapper.get(Type.BYTE, 0);
                        // Move items in inventory to track the sword location
                        InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                        inventoryTracker.handleWindowClick(wrapper.user(), windowId, mode, hoverSlot, button);
                    }
                    ItemRewriter.toServer(stack);
                }
            });
            // Brewing patch and elytra throw patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    final short windowID = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    final short slot = wrapper.get(Type.SHORT, 0);
                    boolean throwItem = (slot == 45 && windowID == 0);
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    if (inventoryTracker.getInventory() != null) {
                        if (inventoryTracker.getInventory().equals("minecraft:brewing_stand")) {
                            if (slot == 4) {
                                throwItem = true;
                            }
                            if (slot > 4) {
                                wrapper.set(Type.SHORT, 0, (short) (slot - 1));
                            }
                        }
                    }
                    if (throwItem) {
                        // Send a packet wiping the slot
                        wrapper.create(ClientboundPackets1_9.SET_SLOT, new PacketHandler() {

                            @Override
                            public void handle(PacketWrapper wrapper) throws Exception {
                                wrapper.write(Type.UNSIGNED_BYTE, (short) windowID);
                                wrapper.write(Type.SHORT, slot);
                                wrapper.write(Type.ITEM, null);
                            }
                        }).scheduleSend(Protocol1_9To1_8.class);
                        // Finally reset to simulate throwing item
                        // Set button to 0
                        wrapper.set(Type.BYTE, 0, (byte) 0);
                        // Set mode to 0
                        wrapper.set(Type.BYTE, 1, (byte) 0);
                        // Set slot to -999
                        wrapper.set(Type.SHORT, 0, (short) -999);
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.CLOSE_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Window ID
            map(Type.UNSIGNED_BYTE);
            // Inventory tracking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    InventoryTracker inventoryTracker = wrapper.user().get(InventoryTracker.class);
                    inventoryTracker.setInventory(null);
                    inventoryTracker.resetInventory(wrapper.get(Type.UNSIGNED_BYTE, 0));
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.HELD_ITEM_CHANGE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Slot id
            map(Type.SHORT);
            // Blocking patch
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand() && Via.getConfig().isShieldBlocking();
                    EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    if (entityTracker.isBlocking()) {
                        entityTracker.setBlocking(false);
                        if (!showShieldWhenSwordInHand) {
                            entityTracker.setSecondHand(null);
                        }
                    }
                    if (showShieldWhenSwordInHand) {
                        // Update current held item slot index
                        entityTracker.setHeldItemSlot(wrapper.get(Type.SHORT, 0));
                        // Sync shield item in offhand with main hand
                        entityTracker.syncShieldWithSword();
                    }
                }
            });
        }
    });
}
Also used : EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) InventoryTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker) Item(com.viaversion.viaversion.api.minecraft.item.Item) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper)

Example 4 with ServerboundPackets1_9

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9 in project ViaVersion by ViaVersion.

the class WorldPackets method register.

public static void register(Protocol protocol) {
    protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sign Position
            map(Type.POSITION);
            // 1 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 2 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 3 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 4 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.EFFECT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Effect ID
            map(Type.INT);
            // 1 - Position
            map(Type.POSITION);
            // 2 - Data
            map(Type.INT);
            // 3 - Disable relative volume
            map(Type.BOOLEAN);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    id = Effect.getNewId(id);
                    wrapper.set(Type.INT, 0, id);
                }
            });
            // Rewrite potion effect as it changed to use a dynamic registry
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 2002) {
                        int data = wrapper.get(Type.INT, 1);
                        int newData = ItemRewriter.getNewEffectID(data);
                        wrapper.set(Type.INT, 1, newData);
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.NAMED_SOUND, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sound Name
            map(Type.STRING);
            // 1 - Sound Category ID
            // Everything else get's written through
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    String name = wrapper.get(Type.STRING, 0);
                    SoundEffect effect = SoundEffect.getByName(name);
                    int catid = 0;
                    String newname = name;
                    if (effect != null) {
                        catid = effect.getCategory().getId();
                        newname = effect.getNewName();
                    }
                    wrapper.set(Type.STRING, 0, newname);
                    // Write Category ID
                    wrapper.write(Type.VAR_INT, catid);
                    if (effect != null && effect.isBreaksound()) {
                        EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        // Position X
                        int x = wrapper.passthrough(Type.INT);
                        // Position Y
                        int y = wrapper.passthrough(Type.INT);
                        // Position Z
                        int z = wrapper.passthrough(Type.INT);
                        if (tracker.interactedBlockRecently((int) Math.floor(x / 8.0), (int) Math.floor(y / 8.0), (int) Math.floor(z / 8.0))) {
                            wrapper.cancel();
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.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);
                    ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
                    Chunk chunk = wrapper.read(new Chunk1_8Type(clientWorld));
                    long chunkHash = ClientChunks.toLong(chunk.getX(), chunk.getZ());
                    // Check if the chunk should be handled as an unload packet
                    if (chunk.isFullChunk() && chunk.getBitmask() == 0) {
                        wrapper.setPacketType(ClientboundPackets1_9.UNLOAD_CHUNK);
                        wrapper.write(Type.INT, chunk.getX());
                        wrapper.write(Type.INT, chunk.getZ());
                        // Remove commandBlocks on chunk unload
                        CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
                        provider.unloadChunk(wrapper.user(), chunk.getX(), chunk.getZ());
                        clientChunks.getLoadedChunks().remove(chunkHash);
                        // Unload the empty chunks
                        if (Via.getConfig().isChunkBorderFix()) {
                            for (BlockFace face : BlockFace.HORIZONTAL) {
                                int chunkX = chunk.getX() + face.modX();
                                int chunkZ = chunk.getZ() + face.modZ();
                                if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
                                    PacketWrapper unloadChunk = wrapper.create(ClientboundPackets1_9.UNLOAD_CHUNK);
                                    unloadChunk.write(Type.INT, chunkX);
                                    unloadChunk.write(Type.INT, chunkZ);
                                    unloadChunk.send(Protocol1_9To1_8.class);
                                }
                            }
                        }
                    } else {
                        Type<Chunk> chunkType = new Chunk1_9_1_2Type(clientWorld);
                        wrapper.write(chunkType, chunk);
                        clientChunks.getLoadedChunks().add(chunkHash);
                        // Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk
                        if (Via.getConfig().isChunkBorderFix()) {
                            for (BlockFace face : BlockFace.HORIZONTAL) {
                                int chunkX = chunk.getX() + face.modX();
                                int chunkZ = chunk.getZ() + face.modZ();
                                if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
                                    PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
                                    Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
                                    emptyChunk.write(chunkType, c);
                                    emptyChunk.send(Protocol1_9To1_8.class);
                                }
                            }
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.MAP_BULK_CHUNK, null, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(wrapper -> {
                // Cancel the packet from being sent
                wrapper.cancel();
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
                Chunk[] chunks = wrapper.read(new ChunkBulk1_8Type(clientWorld));
                Type<Chunk> chunkType = new Chunk1_9_1_2Type(clientWorld);
                // Split into multiple chunk packets
                for (Chunk chunk : chunks) {
                    PacketWrapper chunkData = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
                    chunkData.write(chunkType, chunk);
                    chunkData.send(Protocol1_9To1_8.class);
                    clientChunks.getLoadedChunks().add(ClientChunks.toLong(chunk.getX(), chunk.getZ()));
                    // Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk
                    if (Via.getConfig().isChunkBorderFix()) {
                        for (BlockFace face : BlockFace.HORIZONTAL) {
                            int chunkX = chunk.getX() + face.modX();
                            int chunkZ = chunk.getZ() + face.modZ();
                            if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
                                PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
                                Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
                                emptyChunk.write(chunkType, c);
                                emptyChunk.send(Protocol1_9To1_8.class);
                            }
                        }
                    }
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Block Position
            map(Type.POSITION);
            // 1 - Action
            map(Type.UNSIGNED_BYTE);
            // 2 - NBT (Might not be present)
            map(Type.NBT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int action = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    if (action == 1) {
                        // Update Spawner
                        CompoundTag tag = wrapper.get(Type.NBT, 0);
                        if (tag != null) {
                            if (tag.contains("EntityId")) {
                                String entity = (String) tag.get("EntityId").getValue();
                                CompoundTag spawn = new CompoundTag();
                                spawn.put("id", new StringTag(entity));
                                tag.put("SpawnData", spawn);
                            } else {
                                // EntityID does not exist
                                CompoundTag spawn = new CompoundTag();
                                // Make spawners show up as empty when no EntityId is given.
                                spawn.put("id", new StringTag("AreaEffectCloud"));
                                tag.put("SpawnData", spawn);
                            }
                        }
                    }
                    if (action == 2) {
                        // Update Command Block
                        CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
                        provider.addOrUpdateBlock(wrapper.user(), wrapper.get(Type.POSITION, 0), wrapper.get(Type.NBT, 0));
                        // To prevent window issues don't send updates
                        wrapper.cancel();
                    }
                }
            });
        }
    });
    /* Incoming Packets */
    protocol.registerServerbound(ServerboundPackets1_9.UPDATE_SIGN, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Sign Position
            map(Type.POSITION);
            // 1 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 2 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 3 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
            // 4 - Sign Line (json)
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_DIGGING, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Action
            map(Type.VAR_INT);
            // Position
            map(Type.POSITION);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int status = wrapper.get(Type.VAR_INT, 0);
                    if (status == 6)
                        wrapper.cancel();
                }
            });
            // Blocking
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int status = wrapper.get(Type.VAR_INT, 0);
                    if (status == 5 || status == 4 || status == 3) {
                        EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        if (entityTracker.isBlocking()) {
                            entityTracker.setBlocking(false);
                            if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
                                entityTracker.setSecondHand(null);
                            }
                        }
                    }
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.USE_ITEM, null, new PacketRemapper() {

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

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int hand = wrapper.read(Type.VAR_INT);
                    // Wipe the input buffer
                    wrapper.clearInputBuffer();
                    // First set this packet ID to Block placement
                    wrapper.setId(0x08);
                    wrapper.write(Type.POSITION, new Position(-1, (short) -1, -1));
                    wrapper.write(Type.UNSIGNED_BYTE, (short) 255);
                    // Write item in hand
                    Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
                    // Blocking patch
                    if (Via.getConfig().isShieldBlocking()) {
                        EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                        // Check if the shield is already there or if we have to give it here
                        boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand();
                        // Method to identify the sword in hand
                        boolean isSword = showShieldWhenSwordInHand ? tracker.hasSwordInHand() : item != null && Protocol1_9To1_8.isSword(item.identifier());
                        if (isSword) {
                            if (hand == 0) {
                                if (!tracker.isBlocking()) {
                                    tracker.setBlocking(true);
                                    // Check if the shield is already in the offhand
                                    if (!showShieldWhenSwordInHand && tracker.getItemInSecondHand() == null) {
                                        // Set shield in offhand when interacting with main hand
                                        Item shield = new DataItem(442, (byte) 1, (short) 0, null);
                                        tracker.setSecondHand(shield);
                                    }
                                }
                            }
                            // Use the main hand to trigger the blocking
                            boolean blockUsingMainHand = Via.getConfig().isNoDelayShieldBlocking() && !showShieldWhenSwordInHand;
                            if (blockUsingMainHand && hand == 1 || !blockUsingMainHand && hand == 0) {
                                wrapper.cancel();
                            }
                        } else {
                            if (!showShieldWhenSwordInHand) {
                                // Remove the shield from the offhand
                                tracker.setSecondHand(null);
                            }
                            tracker.setBlocking(false);
                        }
                    }
                    wrapper.write(Type.ITEM, item);
                    wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
                    wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
                    wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
                }
            });
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Position
            map(Type.POSITION);
            // 1 - Block Face
            map(Type.VAR_INT, Type.UNSIGNED_BYTE);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // 2 - Hand
                    final int hand = wrapper.read(Type.VAR_INT);
                    if (hand != 0)
                        wrapper.cancel();
                }
            });
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
                    // 3 - Item
                    wrapper.write(Type.ITEM, item);
                }
            });
            // 4 - X
            map(Type.UNSIGNED_BYTE);
            // 5 - Y
            map(Type.UNSIGNED_BYTE);
            // 6 - Z
            map(Type.UNSIGNED_BYTE);
            // Register block place to fix sounds
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int face = wrapper.get(Type.UNSIGNED_BYTE, 0);
                    if (face == 255)
                        return;
                    Position p = wrapper.get(Type.POSITION, 0);
                    int x = p.x();
                    int y = p.y();
                    int z = p.z();
                    switch(face) {
                        case 0:
                            y--;
                            break;
                        case 1:
                            y++;
                            break;
                        case 2:
                            z--;
                            break;
                        case 3:
                            z++;
                            break;
                        case 4:
                            x--;
                            break;
                        case 5:
                            x++;
                            break;
                    }
                    EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
                    tracker.addBlockInteraction(new Position(x, y, z));
                }
            });
            // Handle CommandBlocks
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
                    Position pos = wrapper.get(Type.POSITION, 0);
                    Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
                    // Send the Update Block Entity packet if present
                    if (tag.isPresent()) {
                        PacketWrapper updateBlockEntity = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, null, wrapper.user());
                        updateBlockEntity.write(Type.POSITION, pos);
                        updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);
                        updateBlockEntity.write(Type.NBT, tag.get());
                        updateBlockEntity.scheduleSend(Protocol1_9To1_8.class);
                    }
                }
            });
        }
    });
}
Also used : PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) Effect(com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.Effect) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Item(com.viaversion.viaversion.api.minecraft.item.Item) CommandBlockProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider) ArrayList(java.util.ArrayList) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) BlockFace(com.viaversion.viaversion.api.minecraft.BlockFace) Chunk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.Chunk1_8Type) ClientboundPackets1_8(com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8) ItemRewriter(com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter) SoundEffect(com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect) Nullable(org.checkerframework.checker.nullness.qual.Nullable) ClientChunks(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks) Position(com.viaversion.viaversion.api.minecraft.Position) Chunk1_9_1_2Type(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type) BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) Protocol(com.viaversion.viaversion.api.protocol.Protocol) ChunkBulk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.ChunkBulk1_8Type) Via(com.viaversion.viaversion.api.Via) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) ServerboundPackets1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9) Optional(java.util.Optional) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) ClientboundPackets1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9) StringTag(com.github.steveice10.opennbt.tag.builtin.StringTag) ClientChunks(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) BlockFace(com.viaversion.viaversion.api.minecraft.BlockFace) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) ArrayList(java.util.ArrayList) CommandBlockProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider) ChunkBulk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.ChunkBulk1_8Type) Item(com.viaversion.viaversion.api.minecraft.item.Item) DataItem(com.viaversion.viaversion.api.minecraft.item.DataItem) Chunk1_9_1_2Type(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag) SoundEffect(com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect) BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) Position(com.viaversion.viaversion.api.minecraft.Position) Chunk(com.viaversion.viaversion.api.minecraft.chunks.Chunk) BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) Chunk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.Chunk1_8Type) Type(com.viaversion.viaversion.api.type.Type) Chunk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.Chunk1_8Type) Chunk1_9_1_2Type(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type) ChunkBulk1_8Type(com.viaversion.viaversion.protocols.protocol1_9to1_8.types.ChunkBulk1_8Type) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Aggregations

Item (com.viaversion.viaversion.api.minecraft.item.Item)4 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)4 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)4 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 EntityTracker1_9 (com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9)4 Protocol1_9To1_8 (com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)3 Via (com.viaversion.viaversion.api.Via)2 Type (com.viaversion.viaversion.api.type.Type)2 ClientboundPackets1_8 (com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8)2 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)2 ItemRewriter (com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter)2 ServerboundPackets1_9 (com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9)2 CommandBlockProvider (com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider)2 ClientChunks (com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks)2 ArrayList (java.util.ArrayList)2 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)1 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)1 ImmutableList (com.google.common.collect.ImmutableList)1 JsonObject (com.google.gson.JsonObject)1 BlockFace (com.viaversion.viaversion.api.minecraft.BlockFace)1