package ch.spacebase.mc.protocol.packet.ingame.client.entity.player;

import java.io.IOException;

import ch.spacebase.packetlib.io.NetInput;
import ch.spacebase.packetlib.io.NetOutput;
import ch.spacebase.packetlib.packet.Packet;

public class ClientPlayerDigPacket implements Packet {
	
	private Status status;
	private int x;
	private int y;
	private int z;
	private Face face;
	
	public ClientPlayerDigPacket() {
	}
	
	public ClientPlayerDigPacket(Status status, int x, int y, int z, Face face) {
		this.status = status;
		this.x = x;
		this.y = y;
		this.z = z;
		this.face = face;
	}
	
	public Status getStatus() {
		return this.status;
	}
	
	public int getX() {
		return this.x;
	}
	
	public int getY() {
		return this.y;
	}
	
	public int getZ() {
		return this.z;
	}
	
	public Face getFace() {
		return this.face;
	}

	@Override
	public void read(NetInput in) throws IOException {
		this.status = Status.values()[in.readUnsignedByte()];
		this.x = in.readInt();
		this.y = in.readUnsignedByte();
		this.z = in.readInt();
		this.face = Face.values()[in.readUnsignedByte()];
	}

	@Override
	public void write(NetOutput out) throws IOException {
		out.writeByte(this.status.ordinal());
		out.writeInt(this.x);
		out.writeByte(this.y);
		out.writeInt(this.z);
		out.writeByte(this.face.ordinal());
	}
	
	@Override
	public boolean isPriority() {
		return false;
	}
	
	public static enum Status {
		START_DIGGING,
		CANCEL_DIGGING,
		FINISH_DIGGING,
		DROP_ITEM_STACK,
		DROP_ITEM,
		SHOOT_ARROW_OR_FINISH_EATING;
	}
	
	public static enum Face {
		BOTTOM,
		TOP,
		EAST,
		WEST,
		NORTH,
		SOUTH;
	}

}

@@ -1040,22 +1040,20 @@
 e = 
-Face.values()%5B
+valueToFace(
 in.r
@@ -1069,17 +1069,17 @@
 edByte()
-%5D
+)
 ;%0A%09%7D%0A%0A%09@
@@ -1267,24 +1267,36 @@
 t.writeByte(
+faceToValue(
 this.face.or
@@ -1292,25 +1292,16 @@
 his.face
-.ordinal(
 ));%0A%09%7D%0A%09
@@ -1356,32 +1356,613 @@
 urn false;%0A%09%7D%0A%09%0A
+%09private static Face valueToFace(int value) %7B%0A%09%09switch(value) %7B%0A%09%09%09case 0:%0A%09%09%09%09return Face.BOTTOM;%0A%09%09%09case 1:%0A%09%09%09%09return Face.TOP;%0A%09%09%09case 2:%0A%09%09%09%09return Face.EAST;%0A%09%09%09case 3:%0A%09%09%09%09return Face.WEST;%0A%09%09%09case 4:%0A%09%09%09%09return Face.NORTH;%0A%09%09%09case 5:%0A%09%09%09%09return Face.SOUTH;%0A%09%09%09default:%0A%09%09%09%09return Face.INVALID;%0A%09%09%7D%0A%09%7D%0A%09%0A%09private static int faceToValue(Face face) %7B%0A%09%09switch(face) %7B%0A%09%09%09case BOTTOM:%0A%09%09%09%09return 0;%0A%09%09%09case TOP:%0A%09%09%09%09return 1;%0A%09%09%09case EAST:%0A%09%09%09%09return 2;%0A%09%09%09case WEST:%0A%09%09%09%09return 3;%0A%09%09%09case NORTH:%0A%09%09%09%09return 4;%0A%09%09%09case SOUTH:%0A%09%09%09%09return 5;%0A%09%09%09default:%0A%09%09%09%09return 255;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09public static e
@@ -2169,15 +2169,26 @@
 TH,%0A
-
 %09%09SOUTH
+,%0A%09%09INVALID
 ;%0A%09%7D

Implement INVALID Face values in ClientPlayerDigPacket for received values such as 255