3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00

Inline player on-ground movement handler (#3777)

Dieser Commit ist enthalten in:
EnZaXD 2024-04-06 09:29:57 +02:00 committet von GitHub
Ursprung d0cc531386
Commit 73178b504e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 11 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -1,35 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_9to1_8;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
public class PlayerMovementMapper implements PacketHandler {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
MovementTracker tracker = wrapper.user().get(MovementTracker.class);
tracker.incrementIdlePacket();
// If packet has the ground data
if (wrapper.is(Type.BOOLEAN, 0)) {
tracker.setGround(wrapper.get(Type.BOOLEAN, 0));
}
}
}

Datei anzeigen

@ -22,11 +22,11 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.PlayerMovementMapper;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.chat.ChatRewriter;
@ -36,6 +36,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.Compressio
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import java.util.logging.Level; import java.util.logging.Level;
public class PlayerPackets { public class PlayerPackets {
@ -451,6 +452,11 @@ public class PlayerPackets {
} }
}); });
final PacketHandler onGroundHandler = wrapper -> {
final MovementTracker tracker = wrapper.user().get(MovementTracker.class);
tracker.incrementIdlePacket();
tracker.setGround(wrapper.get(Type.BOOLEAN, 0));
};
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
@ -458,7 +464,7 @@ public class PlayerPackets {
map(Type.DOUBLE); // 1 - Y map(Type.DOUBLE); // 1 - Y
map(Type.DOUBLE); // 2 - Z map(Type.DOUBLE); // 2 - Z
map(Type.BOOLEAN); // 3 - Ground map(Type.BOOLEAN); // 3 - Ground
handler(new PlayerMovementMapper()); handler(onGroundHandler);
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION_AND_ROTATION, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION_AND_ROTATION, new PacketHandlers() {
@ -470,7 +476,7 @@ public class PlayerPackets {
map(Type.FLOAT); // 3 - Yaw map(Type.FLOAT); // 3 - Yaw
map(Type.FLOAT); // 4 - Pitch map(Type.FLOAT); // 4 - Pitch
map(Type.BOOLEAN); // 5 - Ground map(Type.BOOLEAN); // 5 - Ground
handler(new PlayerMovementMapper()); handler(onGroundHandler);
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_ROTATION, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9.PLAYER_ROTATION, new PacketHandlers() {
@ -479,14 +485,14 @@ public class PlayerPackets {
map(Type.FLOAT); // 0 - Yaw map(Type.FLOAT); // 0 - Yaw
map(Type.FLOAT); // 1 - Pitch map(Type.FLOAT); // 1 - Pitch
map(Type.BOOLEAN); // 2 - Ground map(Type.BOOLEAN); // 2 - Ground
handler(new PlayerMovementMapper()); handler(onGroundHandler);
} }
}); });
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_MOVEMENT, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_9.PLAYER_MOVEMENT, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.BOOLEAN); // 0 - Ground map(Type.BOOLEAN); // 0 - Ground
handler(new PlayerMovementMapper()); handler(onGroundHandler);
} }
}); });
} }