|
| 1 | +/* |
| 2 | + * This file is part of ViaLoadingBase - https://github.com/FlorianMichael/ViaLoadingBase |
| 3 | + * Copyright (C) 2023 FlorianMichael/EnZaXD and contributors |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +package de.florianmichael.vialoadingbase.platform.providers; |
| 19 | + |
| 20 | +import com.viaversion.viaversion.api.connection.UserConnection; |
| 21 | +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; |
| 22 | +import com.viaversion.viaversion.api.protocol.packet.State; |
| 23 | +import com.viaversion.viaversion.api.type.Type; |
| 24 | +import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8; |
| 25 | +import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; |
| 26 | +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; |
| 27 | +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker; |
| 28 | + |
| 29 | +public class VLBMovementTransmitterProvider extends MovementTransmitterProvider { |
| 30 | + @Override |
| 31 | + public Object getFlyingPacket() { |
| 32 | + return null; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public Object getGroundPacket() { |
| 37 | + return null; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void sendPlayer(UserConnection userConnection) { |
| 42 | + if (userConnection.getProtocolInfo().getState() != State.PLAY) return; |
| 43 | + |
| 44 | + final int playerId = userConnection.getEntityTracker(Protocol1_9To1_8.class).clientEntityId(); |
| 45 | + if (playerId == -1) return; // Only apply if the player is initialized |
| 46 | + |
| 47 | + final MovementTracker movementTracker = userConnection.get(MovementTracker.class); |
| 48 | + movementTracker.incrementIdlePacket(); |
| 49 | + |
| 50 | + userConnection.getChannel().eventLoop().submit(() -> { // Sync |
| 51 | + final PacketWrapper c03 = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, userConnection); |
| 52 | + c03.write(Type.BOOLEAN, movementTracker.isGround()); |
| 53 | + |
| 54 | + try { |
| 55 | + c03.sendToServer(Protocol1_9To1_8.class); |
| 56 | + } catch (Exception e) { |
| 57 | + e.printStackTrace(); |
| 58 | + } |
| 59 | + }); |
| 60 | + } |
| 61 | +} |
0 commit comments