Skip to content
Permalink
Browse files

Allow overriding climate when checking for mutations (#1373)

* Allow overriding climate when checking for mutations
  • Loading branch information
bdew authored and mezz committed Aug 2, 2016
1 parent e067603 commit 89cfbfca9ca8942f6233f6ab7d81409b4faaeb15
@@ -7,6 +7,7 @@

import javax.annotation.Nonnull;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
@@ -18,7 +19,7 @@
import forestry.api.core.IErrorLogicSource;
import forestry.api.genetics.IHousing;

public interface IBeeHousing extends IHousing, IErrorLogicSource {
public interface IBeeHousing extends IHousing, IErrorLogicSource, IClimateProvider {

/**
* Used by BeeManager.beeRoot.createBeeHousingModifier(IBeeHousing housing)
@@ -39,19 +40,13 @@

IBeekeepingLogic getBeekeepingLogic();

EnumTemperature getTemperature();

EnumHumidity getHumidity();

int getBlockLightValue();

boolean canBlockSeeTheSky();

/** Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 */
World getWorldObj();

Biome getBiome();

GameProfile getOwner();

/**
@@ -3,7 +3,7 @@
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion = "4.8.0", owner = "ForestryAPI|core", provides = "ForestryAPI|apiculture")
@API(apiVersion = "5.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|apiculture")
package forestry.api.apiculture;

import net.minecraftforge.fml.common.API;
@@ -13,5 +13,7 @@
float getTemperature(World world, BlockPos pos);

float getHumidity(World world, BlockPos pos);


IClimateProvider getDefaultClimate(World world, BlockPos pos);

}
@@ -0,0 +1,11 @@
package forestry.api.core;

import net.minecraft.world.biome.Biome;

public interface IClimateProvider {
Biome getBiome();

EnumTemperature getTemperature();

EnumHumidity getHumidity();
}
@@ -5,6 +5,7 @@
******************************************************************************/
package forestry.api.genetics;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@@ -15,7 +16,7 @@
* Most will return 1 if the condition is met and 0 otherwise,
* but the float offers flexibility for more advanced conditions.
*/
float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1);
float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate);

/**
* A localized description of the mutation condition. (i.e. "A temperature of HOT is required.")
@@ -5,10 +5,11 @@
******************************************************************************/
package forestry.api.lepidopterology;

import forestry.api.core.IClimateProvider;
import forestry.api.genetics.IHousing;
import forestry.api.genetics.IIndividual;

public interface IButterflyNursery extends IHousing {
public interface IButterflyNursery extends IHousing, IClimateProvider {

IButterfly getCaterpillar();

@@ -45,7 +45,7 @@ public float getChance(IBeeHousing housing, IAlleleBeeSpecies allele0, IAlleleBe
World world = housing.getWorldObj();
BlockPos housingPos = housing.getCoordinates();

float processedChance = super.getChance(world, housingPos, allele0, allele1, genome0, genome1);
float processedChance = super.getChance(world, housingPos, allele0, allele1, genome0, genome1, housing);
if (processedChance <= 0) {
return 0;
}
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.arboriculture.genetics;

import forestry.api.core.ForestryAPI;
import forestry.core.DefaultClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@@ -40,7 +42,7 @@ public ITreeRoot getRoot() {

@Override
public float getChance(World world, BlockPos pos, IAlleleTreeSpecies allele0, IAlleleTreeSpecies allele1, ITreeGenome genome0, ITreeGenome genome1) {
float processedChance = super.getChance(world, pos, allele0, allele1, genome0, genome1);
float processedChance = super.getChance(world, pos, allele0, allele1, genome0, genome1, ForestryAPI.climateManager.getDefaultClimate(world, pos));
if (processedChance <= 0) {
return 0;
}
@@ -27,6 +27,9 @@
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.arboriculture.ITreekeepingMode;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IEffectData;
@@ -55,6 +58,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.EnumPlantType;

public class TileLeaves extends TileTreeContainer implements IPollinatable, IFruitBearer, IButterflyNursery, IRipeningPacketReceiver {
@@ -495,4 +499,19 @@ public boolean canNurse(IButterfly butterfly) {
ITree tree = getTree();
return !isDestroyed(tree, damage) && caterpillar == null;
}

@Override
public Biome getBiome() {
return worldObj.getBiome(pos);
}

@Override
public EnumTemperature getTemperature() {
return EnumTemperature.getFromBiome(worldObj.getBiome(pos), worldObj, pos);
}

@Override
public EnumHumidity getHumidity() {
return EnumHumidity.getFromValue(ForestryAPI.climateManager.getHumidity(worldObj, pos));
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
@@ -42,4 +43,8 @@ public float getHumidity(World world, BlockPos pos) {
return biome.getRainfall();
}

@Override
public IClimateProvider getDefaultClimate(World world, BlockPos pos) {
return new DefaultClimateProvider(world, pos);
}
}
@@ -0,0 +1,34 @@
package forestry.core;

import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;

public class DefaultClimateProvider implements IClimateProvider {
private World world;
private BlockPos pos;

public DefaultClimateProvider(World world, BlockPos pos) {
this.world = world;
this.pos = pos;
}

@Override
public Biome getBiome() {
return world.getBiome(pos);
}

@Override
public EnumTemperature getTemperature() {
return EnumTemperature.getFromBiome(world.getBiome(pos), world, pos);
}

@Override
public EnumHumidity getHumidity() {
return EnumHumidity.getFromValue(ForestryAPI.climateManager.getHumidity(world, pos));
}
}
@@ -16,6 +16,7 @@

import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.IClimateProvider;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IGenome;
@@ -124,10 +125,10 @@ public Mutation addMutationCondition(IMutationCondition mutationCondition) {
return this;
}

protected float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
protected float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
float mutationChance = chance;
for (IMutationCondition mutationCondition : mutationConditions) {
mutationChance *= mutationCondition.getChance(world, pos, allele0, allele1, genome0, genome1);
mutationChance *= mutationCondition.getChance(world, pos, allele0, allele1, genome0, genome1, climate);
if (mutationChance == 0) {
return 0;
}
@@ -14,6 +14,7 @@
import java.util.List;
import java.util.Locale;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
@@ -34,8 +35,8 @@ public MutationConditionBiome(BiomeDictionary.Type... types) {
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
Biome biome = world.getBiome(pos);
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
Biome biome = climate.getBiome();
for (BiomeDictionary.Type type : validBiomeTypes) {
if (BiomeDictionary.isBiomeOfType(biome, type)) {
return 1;
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.genetics.mutations;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@@ -27,7 +28,7 @@ public MutationConditionDaytime(boolean daytime) {
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
if (world.isDaytime() == daytime) {
return 1;
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.genetics.mutations;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@@ -31,8 +32,8 @@ public MutationConditionHumidity(EnumHumidity minHumidity, EnumHumidity maxHumid
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
EnumHumidity biomeHumidity = EnumHumidity.getFromValue(ForestryAPI.climateManager.getHumidity(world, pos));
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
EnumHumidity biomeHumidity = climate.getHumidity();

if (biomeHumidity.ordinal() < minHumidity.ordinal() || biomeHumidity.ordinal() > maxHumidity.ordinal()) {
return 0;
@@ -15,6 +15,7 @@
import java.util.Set;

import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.IClimateProvider;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IMutationCondition;
@@ -54,7 +55,7 @@ public MutationConditionRequiresResource(IBlockState... acceptedBlockStates) {
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
TileEntity tile;
do {
pos = pos.down();
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.genetics.mutations;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
@@ -32,9 +33,9 @@ public MutationConditionTemperature(EnumTemperature minTemperature, EnumTemperat
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
Biome biome = world.getBiomeProvider().getBiome(pos);
EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, world, pos);
EnumTemperature biomeTemperature = climate.getTemperature();

if (biomeTemperature.ordinal() < minTemperature.ordinal() || biomeTemperature.ordinal() > maxTemperature.ordinal()) {
return 0;
@@ -12,6 +12,7 @@

import java.util.Calendar;

import forestry.api.core.IClimateProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@@ -32,7 +33,7 @@ public MutationConditionTimeLimited(int startMonth, int startDay, int endMonth,
}

@Override
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
DayMonth now = new DayMonth();

// If we are equal to start day, return 1.
@@ -35,7 +35,7 @@ public IButterflyMutation build() {

@Override
public float getChance(World world, IButterflyNursery housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
float processedChance = super.getChance(world, housing.getCoordinates(), allele0, allele1, genome0, genome1);
float processedChance = super.getChance(world, housing.getCoordinates(), allele0, allele1, genome0, genome1, housing);
if (processedChance <= 0) {
return 0;
}

0 comments on commit 89cfbfc

Please sign in to comment.
You can’t perform that action at this time.