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