Search in sources :

Example 6 with EnumTemperature

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

the class Bee method getCanWork.

@Override
public Set<IErrorState> getCanWork(IBeeHousing housing) {
    World world = housing.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
    // / Rain needs tolerant flyers
    if (housing.isRaining() && !canFlyInRain(beeModifier)) {
        errorStates.add(EnumErrorCode.IS_RAINING);
    }
    // / Night or darkness requires nocturnal species
    if (world.isDaytime()) {
        if (!canWorkDuringDay()) {
            errorStates.add(EnumErrorCode.NOT_NIGHT);
        }
    } else {
        if (!canWorkAtNight(beeModifier)) {
            errorStates.add(EnumErrorCode.NOT_DAY);
        }
    }
    if (housing.getBlockLightValue() > Constants.APIARY_MIN_LEVEL_LIGHT) {
        if (!canWorkDuringDay()) {
            errorStates.add(EnumErrorCode.NOT_GLOOMY);
        }
    } else {
        if (!canWorkAtNight(beeModifier)) {
            errorStates.add(EnumErrorCode.NOT_BRIGHT);
        }
    }
    // / Check for the sky, except if in hell
    if (!world.provider.isNether()) {
        if (!housing.canBlockSeeTheSky() && !canWorkUnderground(beeModifier)) {
            errorStates.add(EnumErrorCode.NO_SKY);
        }
    }
    // / And finally climate check
    IAlleleBeeSpecies species = genome.getPrimary();
    {
        EnumTemperature actualTemperature = housing.getTemperature();
        EnumTemperature beeBaseTemperature = species.getTemperature();
        EnumTolerance beeToleranceTemperature = genome.getToleranceTemp();
        if (!AlleleManager.climateHelper.isWithinLimits(actualTemperature, beeBaseTemperature, beeToleranceTemperature)) {
            if (beeBaseTemperature.ordinal() > actualTemperature.ordinal()) {
                errorStates.add(EnumErrorCode.TOO_COLD);
            } else {
                errorStates.add(EnumErrorCode.TOO_HOT);
            }
        }
    }
    {
        EnumHumidity actualHumidity = housing.getHumidity();
        EnumHumidity beeBaseHumidity = species.getHumidity();
        EnumTolerance beeToleranceHumidity = genome.getToleranceHumid();
        if (!AlleleManager.climateHelper.isWithinLimits(actualHumidity, beeBaseHumidity, beeToleranceHumidity)) {
            if (beeBaseHumidity.ordinal() > actualHumidity.ordinal()) {
                errorStates.add(EnumErrorCode.TOO_ARID);
            } else {
                errorStates.add(EnumErrorCode.TOO_HUMID);
            }
        }
    }
    return errorStates;
}
Also used : IAlleleBeeSpecies(forestry.api.apiculture.IAlleleBeeSpecies) IBeeModifier(forestry.api.apiculture.IBeeModifier) IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) EnumTemperature(forestry.api.core.EnumTemperature)

Example 7 with EnumTemperature

use of forestry.api.core.EnumTemperature 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 8 with EnumTemperature

use of forestry.api.core.EnumTemperature 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 9 with EnumTemperature

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

the class HiveDecorator method tryGenHive.

public static boolean tryGenHive(World world, Random rand, int x, int z, Hive hive) {
    final BlockPos hivePos = hive.getPosForHive(world, x, z);
    if (hivePos == null) {
        return false;
    }
    if (!hive.canReplace(world, hivePos)) {
        return false;
    }
    Biome biome = world.getBiome(hivePos);
    EnumTemperature temperature = EnumTemperature.getFromValue(biome.getFloatTemperature(hivePos));
    if (!hive.isGoodTemperature(temperature)) {
        return false;
    }
    if (!hive.isValidLocation(world, hivePos)) {
        return false;
    }
    return setHive(world, rand, hivePos, hive);
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) EnumTemperature(forestry.api.core.EnumTemperature)

Example 10 with EnumTemperature

use of forestry.api.core.EnumTemperature 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

EnumTemperature (forestry.api.core.EnumTemperature)14 EnumHumidity (forestry.api.core.EnumHumidity)9 World (net.minecraft.world.World)5 Biome (net.minecraft.world.biome.Biome)5 BlockPos (net.minecraft.util.math.BlockPos)4 IErrorState (forestry.api.core.IErrorState)3 EnumTolerance (forestry.api.genetics.EnumTolerance)3 HashSet (java.util.HashSet)3 IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 Vec3i (net.minecraft.util.math.Vec3i)2 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)1 EnumMoisture (binnie.botany.api.gardening.EnumMoisture)1 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