Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is support for the new 1.21.4 client input packet? #3346

Open
spring-dependency-management opened this issue Jan 21, 2025 · 2 comments

Comments

@spring-dependency-management
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.

@Cxom
Copy link

Cxom commented Jan 21, 2025

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.

@spring-dependency-management
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants