package common.block.foliage;

import common.init.Blocks;
import common.model.Model;
import common.model.ModelProvider;
import common.rng.Random;
import common.util.BlockPos;
import common.util.Identifyable;
import common.vars.Vars;
import common.world.State;
import common.world.AWorldServer;

public class BlockFlower extends BlockBush
{
	public static final BlockFlower[] FLOWERS = new BlockFlower[EnumFlowerType.values().length];
	
    private final EnumFlowerType type;
    
    public static BlockFlower getByType(EnumFlowerType type) {
    	return FLOWERS[type.ordinal()];
    }

    public BlockFlower(EnumFlowerType type)
    {
    	this.type = type;
        this.setFlammable(60, 100);
    	FLOWERS[type.ordinal()] = this;
    }
    
    public EnumFlowerType getType() {
    	return this.type;
    }

    public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
    {
        if(Vars.flowerDry && worldIn.getTemperatureC(pos) >= 50.0f)
        {
        	worldIn.setState(pos, worldIn.rand.chance(3) ? Blocks.air.getState() : 
        			Blocks.dead_bush.getState());
        	return;
        }
        super.updateTick(worldIn, pos, state, rand);
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel(this.type.getName()).cross();
    }

    public static enum EnumFlowerType implements Identifyable
    {
        DANDELION("dandelion", "Löwenzahn"),
        ROSE("rose", "Rose"),
        POPPY("poppy", "Mohn"),
        BLUE_ORCHID("blue_orchid", "Blaue Orchidee"),
        ALLIUM("allium", "Sternlauch"),
        HOUSTONIA("houstonia", "Porzellansternchen"),
        RED_TULIP("red_tulip", "Rote Tulpe"),
        ORANGE_TULIP("orange_tulip", "Orange Tulpe"),
        WHITE_TULIP("white_tulip", "Weiße Tulpe"),
        PINK_TULIP("pink_tulip", "Rosa Tulpe"),
        OXEYE_DAISY("daisy", "Margerite"),
        BLACK_LOTUS("black_lotus", "Schwarzer Lotus");

        private final String name;
        private final String display;

        private EnumFlowerType(String name, String display)
        {
            this.name = name;
            this.display = display;
        }

        public String toString()
        {
            return this.name;
        }

        public String getName()
        {
            return this.name;
        }

        public String getDisplay()
        {
            return this.display;
        }
    }
}
