ProtocolLib icon indicating copy to clipboard operation
ProtocolLib copied to clipboard

Where is support for the new 1.21.4 client input packet?

Open spring-dependency-management opened this issue 10 months ago • 2 comments

package net.minecraft.network.protocol.game;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketType;
import net.minecraft.world.entity.player.Input;

public record ServerboundPlayerInputPacket(Input input) implements Packet<ServerGamePacketListener> {
	public static final StreamCodec<FriendlyByteBuf, ServerboundPlayerInputPacket> STREAM_CODEC = StreamCodec.composite(
		Input.STREAM_CODEC, ServerboundPlayerInputPacket::input, ServerboundPlayerInputPacket::new
	);

	@Override
	public PacketType<ServerboundPlayerInputPacket> type() {
		return GamePacketTypes.SERVERBOUND_PLAYER_INPUT;
	}

	public void handle(ServerGamePacketListener serverGamePacketListener) {
		serverGamePacketListener.handlePlayerInput(this);
	}
}

public record Input(boolean forward, boolean backward, boolean left, boolean right, boolean jump, boolean shift, boolean sprint) {
	private static final byte FLAG_FORWARD = 1;
	private static final byte FLAG_BACKWARD = 2;
	private static final byte FLAG_LEFT = 4;
	private static final byte FLAG_RIGHT = 8;
	private static final byte FLAG_JUMP = 16;
	private static final byte FLAG_SHIFT = 32;
	private static final byte FLAG_SPRINT = 64;
	public static final StreamCodec<FriendlyByteBuf, Input> STREAM_CODEC = new StreamCodec<FriendlyByteBuf, Input>() {
		public void encode(FriendlyByteBuf friendlyByteBuf, Input input) {
			byte b = 0;
			b = (byte)(b | (input.forward() ? 1 : 0));
			b = (byte)(b | (input.backward() ? 2 : 0));
			b = (byte)(b | (input.left() ? 4 : 0));
			b = (byte)(b | (input.right() ? 8 : 0));
			b = (byte)(b | (input.jump() ? 16 : 0));
			b = (byte)(b | (input.shift() ? 32 : 0));
			b = (byte)(b | (input.sprint() ? 64 : 0));
			friendlyByteBuf.writeByte(b);
		}

		public Input decode(FriendlyByteBuf friendlyByteBuf) {
			byte b = friendlyByteBuf.readByte();
			boolean bl = (b & 1) != 0;
			boolean bl2 = (b & 2) != 0;
			boolean bl3 = (b & 4) != 0;
			boolean bl4 = (b & 8) != 0;
			boolean bl5 = (b & 16) != 0;
			boolean bl6 = (b & 32) != 0;
			boolean bl7 = (b & 64) != 0;
			return new Input(bl, bl2, bl3, bl4, bl5, bl6, bl7);
		}
	};
	public static Input EMPTY = new Input(false, false, false, false, false, false, false);
}

I believe protocollib mistakes this new packet for a steer vehicle packet (ServerboundMoveVehiclePacket), this is a new and completely separate packet, also ENTITY_TELEPORT silently breaks in 1.21.4 unless you replace it with ENTITY_POSITION_SYNC.

It is worth noting that the old Steer Vehicle packet is not equivalent to the new Move Vehicle packet either. The former sends input data while the latter sends position data.

Cxom avatar Jan 21 '25 19:01 Cxom

It is worth noting that the old Steer Vehicle packet is not equivalent to the new Move Vehicle packet either. The former sends input data while the latter sends position data.

Yes I think there are quite a few weird naming inconsistences with packets and the authors should decide what version of minecraft protocollib is for, since ATM maintaining backwards compatibility hurts everyone

ghost avatar Jan 22 '25 17:01 ghost

switched to packet events

ghost avatar Mar 30 '25 11:03 ghost