package com.edicatad.emvi.handlers;

import java.util.logging.Level;
import java.util.logging.Logger;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;

@Mod.EventBusSubscriber
public class SpawnHandler {
	private static long worldTime;
	
	@SubscribeEvent
	public static void worldTick(WorldTickEvent event){
		// The world time ticks up indefinitely so we mod it to get the time within a day
		worldTime = Math.floorMod(event.world.getWorldTime(),24000);
		if(Math.floorMod(worldTime, 100)!=0){
			return;
		}
		
		switch(event.phase){
		case END:
			break;
		case START:
			/*
			 * TODO 
			 * use getWorldTime to only run spawn checker code at dawn or something
			 * spawn villagers based on random chance
			 * limit villagers spawned on a per-chunk basis
			 * maintain the limit in the world save file
			 */
			// this is a switch in case I want to provide mod support to other mods or add villagers to the nether or something
			switch(event.world.provider.getDimension()){
			case 0:
				// We're ticking the overworld dimension!
				// using a bed sticks you at a multiple of 24000
				if(Math.floorMod(worldTime, 10)==0){
					Logger.getLogger("EMVI").log(Level.INFO,String.format("TESTING %d", worldTime));
				}
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}
	}
}

@@ -34,74 +34,8 @@
 s;%0A%0A
-import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A
 impo
@@ -72,16 +72,16 @@
 on.Mod;%0A
+
 import n
@@ -515,16 +515,193 @@
 24000);%0A
+%09%09// I want my code to run as little as possible for speed.  Since this runs before I check the phase it runs twice per tick%0A%09%09// so it should run the code once every 5 seconds%0A
 %09%09if(Mat
@@ -1288,100 +1288,156 @@
 %09// 
-using a bed sticks you at a multiple of 24000%0A%09%09%09%09if(Math.floorMod(worldTime, 10)==0)%7B%0A%09%09%09%09%09
+Logger.getLogger(%22EMVI%22).log(Level.INFO,String.format(%22WorldTime: %25d%22, worldTime));%0A%09%09%09%09// event.world.playerEntities.parallelStream().forEach((a)-%3E
 Logg
@@ -1491,39 +1491,58 @@
 at(%22
-TESTING %25d%22, worldTime));%0A%09%09%09%09%7D
+Player in world: %25s%22, a.getDisplayNameString())));
 %0A%09%09%09

Add comments and logging to SpawnHandler