Search in sources :

Example 6 with EnumHumidity

use of forestry.api.core.EnumHumidity in project ForestryMC by ForestryMC.

the class Bee method isSuitableBiome.

private boolean isSuitableBiome(Biome biome) {
    EnumTemperature temperature = EnumTemperature.getFromBiome(biome);
    EnumHumidity humidity = EnumHumidity.getFromValue(biome.getRainfall());
    return isSuitableClimate(temperature, humidity);
}
Also used : EnumHumidity(forestry.api.core.EnumHumidity) EnumTemperature(forestry.api.core.EnumTemperature)

Example 7 with EnumHumidity

use of forestry.api.core.EnumHumidity in project ForestryMC by ForestryMC.

the class VillageApiaristHouse method getRandomVillageBee.

private static IBee getRandomVillageBee(World world, BlockPos pos) {
    // Get current biome
    Biome biome = world.getBiome(pos);
    List<IBeeGenome> candidates;
    if (BeeManager.uncommonVillageBees != null && !BeeManager.uncommonVillageBees.isEmpty() && world.rand.nextDouble() < 0.2) {
        candidates = BeeManager.uncommonVillageBees;
    } else {
        candidates = BeeManager.commonVillageBees;
    }
    EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, world, pos);
    EnumHumidity biomeHumidity = EnumHumidity.getFromValue(biome.getRainfall());
    // Add bees that can live in this environment
    List<IBeeGenome> valid = new ArrayList<>();
    for (IBeeGenome genome : candidates) {
        if (checkBiomeHazard(genome, biomeTemperature, biomeHumidity)) {
            valid.add(genome);
        }
    }
    // No valid ones found, return any of the common ones.
    if (valid.isEmpty()) {
        int index = world.rand.nextInt(BeeManager.commonVillageBees.size());
        IBeeGenome genome = BeeManager.commonVillageBees.get(index);
        return BeeManager.beeRoot.getBee(genome);
    }
    return BeeManager.beeRoot.getBee(valid.get(world.rand.nextInt(valid.size())));
}
Also used : Biome(net.minecraft.world.biome.Biome) ArrayList(java.util.ArrayList) EnumHumidity(forestry.api.core.EnumHumidity) IBeeGenome(forestry.api.apiculture.IBeeGenome) EnumTemperature(forestry.api.core.EnumTemperature)

Example 8 with EnumHumidity

use of forestry.api.core.EnumHumidity in project ForestryMC by ForestryMC.

the class HiveDecorator method decorateHivesDebug.

private static void decorateHivesDebug(World world, Random rand, int chunkX, int chunkZ, List<Hive> hives) {
    int worldX = (chunkX << 4) + 8;
    int worldZ = (chunkZ << 4) + 8;
    Biome biome = world.getBiome(new BlockPos(chunkX, 0, chunkZ));
    EnumHumidity humidity = EnumHumidity.getFromValue(biome.getRainfall());
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            Collections.shuffle(hives, world.rand);
            for (Hive hive : hives) {
                if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity)) {
                    continue;
                }
                tryGenHive(world, rand, worldX + x, worldZ + z, hive);
            }
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) EnumHumidity(forestry.api.core.EnumHumidity)

Example 9 with EnumHumidity

use of forestry.api.core.EnumHumidity in project ForestryMC by ForestryMC.

the class HiveDecorator method decorateHives.

public static void decorateHives(World world, Random rand, int chunkX, int chunkZ) {
    List<Hive> hives = ModuleApiculture.getHiveRegistry().getHives();
    if (Config.generateBeehivesDebug) {
        decorateHivesDebug(world, rand, chunkX, chunkZ, hives);
        return;
    }
    int worldX = (chunkX << 4) + 8;
    int worldZ = (chunkZ << 4) + 8;
    Collections.shuffle(hives, rand);
    for (int tries = 0; tries < 4; tries++) {
        int x = worldX + rand.nextInt(16);
        int z = worldZ + rand.nextInt(16);
        BlockPos pos = new BlockPos(x, 0, z);
        if (!world.isBlockLoaded(pos)) {
            Log.error("tried to generate a hive in an unloaded area.");
            return;
        }
        Biome biome = world.getBiome(pos);
        EnumHumidity humidity = EnumHumidity.getFromValue(biome.getRainfall());
        for (Hive hive : hives) {
            if (hive.genChance() * Config.getBeehivesAmount() >= rand.nextFloat() * 100.0f) {
                if (hive.isGoodBiome(biome) && hive.isGoodHumidity(humidity)) {
                    if (tryGenHive(world, rand, x, z, hive)) {
                        return;
                    }
                }
            }
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) EnumHumidity(forestry.api.core.EnumHumidity)

Example 10 with EnumHumidity

use of forestry.api.core.EnumHumidity in project ForestryMC by ForestryMC.

the class Butterfly method getCanSpawn.

@Override
public Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
    World world = nursery.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    // / Night or darkness requires nocturnal species
    boolean isDaytime = world.isDaytime();
    if (!isActiveThisTime(isDaytime)) {
        if (isDaytime) {
            errorStates.add(EnumErrorCode.NOT_NIGHT);
        } else {
            errorStates.add(EnumErrorCode.NOT_DAY);
        }
    }
    // / And finally climate check
    IAlleleButterflySpecies species = genome.getPrimary();
    EnumTemperature actualTemperature = nursery.getTemperature();
    EnumTemperature baseTemperature = species.getTemperature();
    EnumTolerance toleranceTemperature = genome.getToleranceTemp();
    EnumHumidity actualHumidity = nursery.getHumidity();
    EnumHumidity baseHumidity = species.getHumidity();
    EnumTolerance toleranceHumidity = genome.getToleranceHumid();
    ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
    return errorStates;
}
Also used : IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies) EnumTemperature(forestry.api.core.EnumTemperature)

Aggregations

EnumHumidity (forestry.api.core.EnumHumidity)11 EnumTemperature (forestry.api.core.EnumTemperature)9 Biome (net.minecraft.world.biome.Biome)5 IErrorState (forestry.api.core.IErrorState)3 EnumTolerance (forestry.api.genetics.EnumTolerance)3 HashSet (java.util.HashSet)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)3 IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)2 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IBeeGenome (forestry.api.apiculture.IBeeGenome)1 IBeeModifier (forestry.api.apiculture.IBeeModifier)1 ITreeGenome (forestry.api.arboriculture.ITreeGenome)1 ArrayList (java.util.ArrayList)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1