package common.worldgen;

import java.util.List;

import common.block.Block;
import common.collect.Lists;
import common.init.BlockRegistry;
import common.util.ExtMath;
import common.world.State;

public class DebugStates {
	private static final List<State> STATES = Lists.<State>newArrayList();
	private static final int XSTRETCH;
	private static final int ZSTRETCH;
	
	static {
		for(Block block : BlockRegistry.REGISTRY) {
			STATES.addAll(block.getValidStates());
		}
		XSTRETCH = ExtMath.ceilf(ExtMath.sqrtf((float)STATES.size()));
		ZSTRETCH = ExtMath.ceilf((float)STATES.size() / (float)XSTRETCH);
	}

	public static State getState(int x, int z) {
		State state = null;
		if(x > 0 && z > 0 && x % 2 != 0 && z % 2 != 0) {
			x = x / 2;
			z = z / 2;
			if(x <= XSTRETCH && z <= ZSTRETCH) {
				int idx = ExtMath.absi(x * XSTRETCH + z);
				if(idx < STATES.size()) {
					state = STATES.get(idx);
				}
			}
		}
		return state;
	}
}
