package common.packet;

import java.io.IOException;

import common.entity.npc.EntityNPC;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;

public class SPacketPlayerAbilities implements Packet<IClientPlayer> {
	private boolean flying;
	private boolean noClip;

	public SPacketPlayerAbilities() {
	}

	public SPacketPlayerAbilities(EntityNPC capabilities) {
		this.flying = capabilities.flying;
		this.noClip = capabilities.noclip;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		byte bt = buf.readByte();
		this.flying = (bt & 1) > 0;
		this.noClip = (bt & 2) > 0;
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		byte bt = 0;

		if(this.isFlying()) {
			bt = (byte)(bt | 1);
		}

		if(this.isNoclip()) {
			bt = (byte)(bt | 2);
		}

		buf.writeByte(bt);
	}

	public void processPacket(IClientPlayer handler) {
		handler.handlePlayerAbilities(this);
	}

	public boolean isFlying() {
		return this.flying;
	}

	public boolean isNoclip() {
		return this.noClip;
	}
}
