package com.zivilon.cinder_loe.world.biome;

import com.zivilon.cinder_loe.entity.animals.Monkey;
import lotr.common.entity.animal.*;
import lotr.common.world.LOTRWorldChunkManager;
import lotr.common.world.biome.LOTRBiomeGenFarHaradCloudForest;
import lotr.common.world.biome.LOTRMusicRegion;
import lotr.common.world.biome.variant.LOTRBiomeVariant;
import lotr.common.world.feature.LOTRTreeType;
import lotr.common.world.feature.LOTRWorldGenDoubleFlower;
import lotr.common.world.map.LOTRWaypoint;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraft.world.gen.feature.WorldGenerator;

import java.util.Random;

public class GenMistyForest extends CinderBiome {

    public GenMistyForest(int i, boolean major) {
        super(i, major);
        this.spawnableCreatureList.clear();
        this.spawnableCreatureList.add(new BiomeGenBase.SpawnListEntry(LOTREntityFlamingo.class, 10, 4, 4));
        this.spawnableLOTRAmbientList.clear();
        this.spawnableLOTRAmbientList.add(new BiomeGenBase.SpawnListEntry(LOTREntityBird.class, 10, 4, 4));
        this.spawnableLOTRAmbientList.add(new BiomeGenBase.SpawnListEntry(LOTREntityButterfly.class, 10, 4, 4));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(LOTREntityJungleScorpion.class, 30, 4, 4));
        this.spawnableLOTRAmbientList.add(new BiomeGenBase.SpawnListEntry(LOTREntityWhiteOryx.class, 10, 4, 4));
        this.spawnableMonsterList.add(new BiomeGenBase.SpawnListEntry(Monkey.class, 1, 4, 4));
        this.addBiomeVariantSet(LOTRBiomeVariant.SET_FOREST);
        this.decorator.treesPerChunk = 10;
        this.decorator.vinesPerChunk = 50;
        this.decorator.flowersPerChunk = 4;
        this.decorator.doubleFlowersPerChunk = 4;
        this.decorator.grassPerChunk = 15;
        this.decorator.doubleGrassPerChunk = 10;
        this.decorator.enableFern = true;
        this.decorator.melonPerChunk = 0.1f;
        this.decorator.clearTrees();
        this.decorator.addTree(LOTRTreeType.JUNGLE_CLOUD, 4000);
        this.decorator.addTree(LOTRTreeType.JUNGLE, 500);
        this.decorator.addTree(LOTRTreeType.JUNGLE_SHRUB, 1000);
        this.decorator.addTree(LOTRTreeType.MANGO, 20);
        this.decorator.addTree(LOTRTreeType.BANANA, 20);
        this.registerJungleFlowers();
        this.biomeColors.setGrass(2007124);
        this.biomeColors.setFoliage(428338);
        this.biomeColors.setSky(11452859);
        this.biomeColors.setFoggy(true);
    }

    @Override
    public LOTRWaypoint.Region getBiomeWaypoints() {
        return null;
    }

    @Override
    public LOTRMusicRegion.Sub getBiomeMusic() {
        return LOTRMusicRegion.FAR_HARAD_JUNGLE.getSubregion("cloudForest");
    }

    @Override
    public float getChanceToSpawnAnimals() {
        return super.getChanceToSpawnAnimals() * 0.5f;
    }

    @Override
    public WorldGenerator getRandomWorldGenForDoubleFlower(Random random) {
        LOTRWorldGenDoubleFlower doubleFlowerGen = new LOTRWorldGenDoubleFlower();
        if (random.nextInt(5) == 0) {
            doubleFlowerGen.setFlowerType(3);
        } else {
            doubleFlowerGen.setFlowerType(2);
        }
        return doubleFlowerGen;
    }

    @Override
    public void decorate(World world, Random random, int i, int k) {
        super.decorate(world, random, i, k);
        LOTRBiomeVariant variant = ((LOTRWorldChunkManager)world.getWorldChunkManager()).getBiomeVariantAt(i + 8, k + 8);
        if (variant == LOTRBiomeVariant.RIVER && random.nextInt(3) == 0) {
            WorldGenAbstractTree bananaTree = LOTRTreeType.BANANA.create(false, random);
            int bananas = 3 + random.nextInt(8);
            for (int l = 0; l < bananas; ++l) {
                int i1 = i + random.nextInt(16) + 8;
                int k1 = k + random.nextInt(16) + 8;
                int j1 = world.getTopSolidOrLiquidBlock(i1, k1);
                bananaTree.generate(world, random, i1, j1, k1);
            }
        }
    }
}
