package projectzombie.tiles;

import gl_engine.vec.Vec2i;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.model.Model;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;

public class TileSapling extends Tile
{

	@Override
	public Model getModel(byte meta)
	{
		switch(meta)
		{
		case 0: return Models.TILE_SAPLING_1;
		case 1: return Models.TILE_SAPLING_2;
		case 2: return Models.TILE_SAPLING_3;
		default: return Models.TILE_SAPLING_4;
		}
	}
	
	@Override
	public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) {
		super.tickRandomly(layer, chunk, state, pos);
		
		if(Math.random() > 0.95) {
			if(state.meta < 4) {
				layer.setFrontTile(new TileState(this, state.meta + 1), pos);
			}
			
			else {
				Tile bt = layer.getBackTile(pos).tile;
				
				if(bt == Tiles.SNOW) {
					layer.setFrontTile(new TileState(Tiles.TREE, 1), pos);
				} else if(bt == Tiles.GRASS) {
					layer.setFrontTile(new TileState(Tiles.TREE, 0), pos);
				}
			}
		}
	}

}
