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 fu, final Direction fz) {
        this.action = a;
        this.pos = fu.immutable();
        this.direction = fz;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.action = mg.<Action>readEnum(Action.class);
        this.pos = mg.readBlockPos();
        this.direction = Direction.from3DDataValue(mg.readUnsignedByte());
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeEnum(this.action);
        mg.writeBlockPos(this.pos);
        mg.writeByte(this.direction.get3DDataValue());
    }
    
    @Override
    public void handle(final ServerGamePacketListener qz) {
        qz.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_ITEM_WITH_OFFHAND;
    }
}
