package common.packet;

import java.io.IOException;

import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;

public class SPacketWorld implements Packet<IClientPlayer> {
	private float gravity;
	private int timeFactor;
	private boolean dayCycle;

	public SPacketWorld() {
	}

	public SPacketWorld(float gravity, boolean dayCycle, int timeFactor) {
		this.gravity = gravity;
		this.timeFactor = timeFactor;
		this.dayCycle = dayCycle;
	}

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

	public void readPacketData(PacketBuffer buf) throws IOException {
		this.gravity = buf.readFloat();
		this.timeFactor = buf.readVarInt();
		int flags = buf.readUnsignedByte();
		this.dayCycle = (flags & 1) > 0;
	}

	public void writePacketData(PacketBuffer buf) throws IOException {
		buf.writeFloat(this.gravity);
		buf.writeVarInt(this.timeFactor);
		buf.writeByte(this.dayCycle ? 1 : 0);
	}

	public float getGravity() {
		return this.gravity;
	}

	public int getTimeFactor() {
		return this.timeFactor;
	}

	public boolean hasDayCycle() {
		return this.dayCycle;
	}
}
