package common.packet;

import java.io.IOException;

import common.network.IPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.BlockPos;
import common.util.Facing;

public class CPacketBreak implements Packet<IPlayer>
{
    private BlockPos position;
    private Facing facing;
    private CPacketBreak.Action status;

    public CPacketBreak()
    {
    }

    public CPacketBreak(CPacketBreak.Action statusIn, BlockPos posIn, Facing facingIn)
    {
        this.status = statusIn;
        this.position = posIn;
        this.facing = facingIn;
    }
    
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.status = (CPacketBreak.Action)buf.readEnumValue(CPacketBreak.Action.class);
        this.position = buf.readBlockPos();
        this.facing = Facing.getFront(buf.readUnsignedByte());
    }
    
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeEnumValue(this.status);
        buf.writeBlockPos(this.position);
        buf.writeByte(this.facing.getIndex());
    }
    
    public void processPacket(IPlayer handler)
    {
        handler.processBreak(this);
    }

    public BlockPos getPosition()
    {
        return this.position;
    }

    public Facing getFacing()
    {
        return this.facing;
    }

    public CPacketBreak.Action getStatus()
    {
        return this.status;
    }

    public static enum Action
    {
        START_DESTROY_BLOCK,
        ABORT_DESTROY_BLOCK,
        STOP_DESTROY_BLOCK,
        DROP_ALL_ITEMS,
        DROP_ITEM,
        RELEASE_USE_ITEM;
    }
}
