package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.Packet;

public class ServerboundPlayerActionPacket implements Packet<ServerGamePacketListener> {
    private BlockPos pos;
    private Direction direction;
    private Action action;
    
    public ServerboundPlayerActionPacket() {
    }
    
    public ServerboundPlayerActionPacket(final Action a, final BlockPos fk, final Direction fp) {
        this.action = a;
        this.pos = fk.immutable();
        this.direction = fp;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.action = kv.<Action>readEnum(Action.class);
        this.pos = kv.readBlockPos();
        this.direction = Direction.from3DDataValue(kv.readUnsignedByte());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeEnum(this.action);
        kv.writeBlockPos(this.pos);
        kv.writeByte(this.direction.get3DDataValue());
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handlePlayerAction(this);
    }
    
    public BlockPos getPos() {
        return this.pos;
    }
    
    public Direction getDirection() {
        return this.direction;
    }
    
    public Action getAction() {
        return this.action;
    }
    
    public enum Action {
        START_DESTROY_BLOCK, 
        ABORT_DESTROY_BLOCK, 
        STOP_DESTROY_BLOCK, 
        DROP_ALL_ITEMS, 
        DROP_ITEM, 
        RELEASE_USE_ITEM, 
        SWAP_HELD_ITEMS;
    }
}
