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;
}
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);
}
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())));
}
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);
}
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;
}
Aggregations