| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.network.FriendlyByteBuf;
|
| 6 | import net.minecraft.network.codec.StreamCodec;
|
| 7 | import net.minecraft.network.protocol.Packet;
|
| 8 | import net.minecraft.network.protocol.PacketType;
|
| 9 |
|
| 10 | public class ServerboundPlayerActionPacket implements Packet<ServerGamePacketListener> {
|
| 11 | public static final StreamCodec<FriendlyByteBuf, ServerboundPlayerActionPacket> STREAM_CODEC = Packet.codec(
|
| 12 | ServerboundPlayerActionPacket::write, ServerboundPlayerActionPacket::new
|
| 13 | );
|
| 14 | private final BlockPos pos;
|
| 15 | private final Direction direction;
|
| 16 | private final ServerboundPlayerActionPacket.Action action;
|
| 17 | private final int sequence;
|
| 18 |
|
| 19 | public ServerboundPlayerActionPacket(final ServerboundPlayerActionPacket.Action action, final BlockPos pos, final Direction direction, final int sequence) {
|
| 20 | this.action = action;
|
| 21 | this.pos = pos.immutable();
|
| 22 | this.direction = direction;
|
| 23 | this.sequence = sequence;
|
| 24 | }
|
| 25 |
|
| 26 | public ServerboundPlayerActionPacket(final ServerboundPlayerActionPacket.Action action, final BlockPos pos, final Direction direction) {
|
| 27 | this(action, pos, direction, 0);
|
| 28 | }
|
| 29 |
|
| 30 | private ServerboundPlayerActionPacket(final FriendlyByteBuf input) {
|
| 31 | this.action = input.readEnum(ServerboundPlayerActionPacket.Action.class);
|
| 32 | this.pos = input.readBlockPos();
|
| 33 | this.direction = Direction.from3DDataValue(input.readUnsignedByte());
|
| 34 | this.sequence = input.readVarInt();
|
| 35 | }
|
| 36 |
|
| 37 | private void write(final FriendlyByteBuf output) {
|
| 38 | output.writeEnum(this.action);
|
| 39 | output.writeBlockPos(this.pos);
|
| 40 | output.writeByte(this.direction.get3DDataValue());
|
| 41 | output.writeVarInt(this.sequence);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public PacketType<ServerboundPlayerActionPacket> type() {
|
| 46 | return GamePacketTypes.SERVERBOUND_PLAYER_ACTION;
|
| 47 | }
|
| 48 |
|
| 49 | public void handle(final ServerGamePacketListener listener) {
|
| 50 | listener.handlePlayerAction(this);
|
| 51 | }
|
| 52 |
|
| 53 | public BlockPos getPos() {
|
| 54 | return this.pos;
|
| 55 | }
|
| 56 |
|
| 57 | public Direction getDirection() {
|
| 58 | return this.direction;
|
| 59 | }
|
| 60 |
|
| 61 | public ServerboundPlayerActionPacket.Action getAction() {
|
| 62 | return this.action;
|
| 63 | }
|
| 64 |
|
| 65 | public int getSequence() {
|
| 66 | return this.sequence;
|
| 67 | }
|
| 68 |
|
| 69 | public enum Action {
|
| 70 | START_DESTROY_BLOCK,
|
| 71 | CHANGE_DESTROY_DIRECTION,
|
| 72 | ABORT_DESTROY_BLOCK,
|
| 73 | STOP_DESTROY_BLOCK,
|
| 74 | DROP_ALL_ITEMS,
|
| 75 | DROP_ITEM,
|
| 76 | RELEASE_USE_ITEM,
|
| 77 | SWAP_ITEM_WITH_OFFHAND,
|
| 78 | STAB;
|
| 79 | }
|
| 80 | }
|
| 81 |
|