| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.network.FriendlyByteBuf;
|
| 4 | import net.minecraft.network.codec.StreamCodec;
|
| 5 | import net.minecraft.network.protocol.Packet;
|
| 6 | import net.minecraft.network.protocol.PacketType;
|
| 7 | import net.minecraft.world.entity.Entity;
|
| 8 |
|
| 9 | public class ServerboundPlayerCommandPacket implements Packet<ServerGamePacketListener> {
|
| 10 | public static final StreamCodec<FriendlyByteBuf, ServerboundPlayerCommandPacket> STREAM_CODEC = Packet.codec(
|
| 11 | ServerboundPlayerCommandPacket::write, ServerboundPlayerCommandPacket::new
|
| 12 | );
|
| 13 | private final int id;
|
| 14 | private final ServerboundPlayerCommandPacket.Action action;
|
| 15 | private final int data;
|
| 16 |
|
| 17 | public ServerboundPlayerCommandPacket(final Entity entity, final ServerboundPlayerCommandPacket.Action action) {
|
| 18 | this(entity, action, 0);
|
| 19 | }
|
| 20 |
|
| 21 | public ServerboundPlayerCommandPacket(final Entity entity, final ServerboundPlayerCommandPacket.Action action, final int data) {
|
| 22 | this.id = entity.getId();
|
| 23 | this.action = action;
|
| 24 | this.data = data;
|
| 25 | }
|
| 26 |
|
| 27 | private ServerboundPlayerCommandPacket(final FriendlyByteBuf input) {
|
| 28 | this.id = input.readVarInt();
|
| 29 | this.action = input.readEnum(ServerboundPlayerCommandPacket.Action.class);
|
| 30 | this.data = input.readVarInt();
|
| 31 | }
|
| 32 |
|
| 33 | private void write(final FriendlyByteBuf output) {
|
| 34 | output.writeVarInt(this.id);
|
| 35 | output.writeEnum(this.action);
|
| 36 | output.writeVarInt(this.data);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public PacketType<ServerboundPlayerCommandPacket> type() {
|
| 41 | return GamePacketTypes.SERVERBOUND_PLAYER_COMMAND;
|
| 42 | }
|
| 43 |
|
| 44 | public void handle(final ServerGamePacketListener listener) {
|
| 45 | listener.handlePlayerCommand(this);
|
| 46 | }
|
| 47 |
|
| 48 | public int getId() {
|
| 49 | return this.id;
|
| 50 | }
|
| 51 |
|
| 52 | public ServerboundPlayerCommandPacket.Action getAction() {
|
| 53 | return this.action;
|
| 54 | }
|
| 55 |
|
| 56 | public int getData() {
|
| 57 | return this.data;
|
| 58 | }
|
| 59 |
|
| 60 | public enum Action {
|
| 61 | STOP_SLEEPING,
|
| 62 | START_SPRINTING,
|
| 63 | STOP_SPRINTING,
|
| 64 | START_RIDING_JUMP,
|
| 65 | STOP_RIDING_JUMP,
|
| 66 | OPEN_INVENTORY,
|
| 67 | START_FALL_FLYING;
|
| 68 | }
|
| 69 | }
|
| 70 |
|