package projectzombie.entity;

import mainloop.task.IMainloopTask;
import projectzombie.Main;
import projectzombie.world.chunk.ChunkEventHandler;

public class EntityEventHandler implements IMainloopTask
{
	public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler();

	@Override
	public boolean MainLoopDelay(long millis) {
		return millis > Main.tickrate;
	}

	@Override
	public boolean MainLoopRepeat() {
		return true;
	}

	@Override
	public void MainLoopUpdate()
	{
		Main.menu.update();
		
		if(!Main.menu.doGameloop || !ChunkEventHandler.loaded) {
			return;
		}
		
		// Update the world and spawn random entities
		Main.world.tickEntities();
		Main.world.spawnRandomEntities();
		Main.player.tick(null, Main.world.getLayer());
	}
}
