package common.packet;

import java.io.IOException;

import common.dimension.Dimension;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.tags.TagObject;

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

    public SPacketRespawn()
    {
    }

    public SPacketRespawn(Dimension dimensionIn, int type, boolean editor)
    {
        this.dimension = dimensionIn.toTags(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.readTag();
        this.type = buf.readUnsignedShort();
        this.editor = buf.readBoolean();
    }
    
    public void writePacketData(PacketBuffer buf) throws IOException
    {
        buf.writeTag(this.dimension);
        buf.writeShort(this.type & 65535);
        buf.writeBoolean(this.editor);
    }

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

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

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