package common.packet;

import java.io.IOException;

import common.dimension.Dimension;
import common.nbt.NBTTagCompound;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;

public class SPacketRespawn implements Packet<IClientPlayer>
{
    private NBTTagCompound dimension;
    private int type;
    private boolean editor;

    public SPacketRespawn()
    {
    }

    public SPacketRespawn(Dimension dimensionIn, int type, boolean editor)
    {
        this.dimension = dimensionIn.toNbt(false);
        this.type = type;
		this.editor = editor;
    }
    
    public void processPacket(IClientPlayer handler)
    {
        handler.handleRespawn(this);
    }
    
    public void readPacketData(PacketBuffer buf) throws IOException
    {
        this.dimension = buf.readNBTTagCompoundFromBuffer();
        this.type = buf.readUnsignedShort();
        this.editor = buf.readBoolean();
    }
    
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeNBTTagCompoundToBuffer(this.dimension);
        buf.writeShort(this.type & 65535);
        buf.writeBoolean(this.editor);
    }

    public Dimension getDimension()
    {
        return Dimension.getByNbt(this.dimension, false);
    }

    public int getEntityType()
    {
        return this.type;
    }

    public boolean isInEditor() {
        return this.editor;
    }
}
