package common.packet;

import java.io.IOException;

import common.biome.Biome;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.BlockPos;

public class SPacketBiome implements Packet<IClientPlayer> {
	private int posX;
	private int posZ;
	private Biome biome;

	public SPacketBiome() {
	}

	public SPacketBiome(BlockPos pos, Biome biome) {
		this.posX = pos.getX();
		this.posZ = pos.getZ();
		this.biome = biome;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.posX = buf.readInt();
		this.posZ = buf.readInt();
		this.biome = buf.readEnumValue(Biome.class);
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeInt(this.posX);
		buf.writeInt(this.posZ);
		buf.writeEnumValue(this.biome);
	}

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

	public int getChunkX() {
		return this.posX >> 4;
	}

	public int getChunkZ() {
		return this.posZ >> 4;
	}
	
	public BlockPos getPos() {
		return new BlockPos(this.posX, 0, this.posZ);
	}

	public Biome getBiome() {
		return this.biome;
	}
}
