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 SPacketJoinGame implements Packet<IClientPlayer> {
	private int entityId;
	private TagObject dimension;
    private int type;
    private boolean editor;

	public SPacketJoinGame() {
	}

	public SPacketJoinGame(int entityIdIn, Dimension dimensionIn, int type, boolean editor) {
		this.entityId = entityIdIn;
		this.dimension = dimensionIn.toTags(false);
		this.type = type;
		this.editor = editor;
	}

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.entityId = buf.readInt();
		this.dimension = buf.readTag();
        this.type = buf.readUnsignedShort();
        this.editor = buf.readBoolean();
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeInt(this.entityId);
		buf.writeTag(this.dimension);
        buf.writeShort(this.type & 65535);
        buf.writeBoolean(this.editor);
	}

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

	public int getEntityId() {
		return this.entityId;
	}

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

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

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