Allow overriding climate when checking for mutations (#1373)

* Allow overriding climate when checking for mutations
This commit is contained in:
bdew authored and James Mitchell committed 2016-08-02 14:22:05 -07:00
1 parent e0676030d6
commit 89cfbfca9c
19 files changed
+102 -25

No files matched your search

@@ -7,6 +7,7 @@ package forestry.api.apiculture;
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.EnumTemperature;
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,10 +40,6 @@ public interface IBeeHousing extends IHousing, IErrorLogicSource {
IBeekeepingLogic getBeekeepingLogic();
EnumTemperature getTemperature();
EnumHumidity getHumidity();
int getBlockLightValue();
boolean canBlockSeeTheSky();
@@ -50,8 +47,6 @@ public interface IBeeHousing extends IHousing, IErrorLogicSource {
/** 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 @@ public interface IClimateManager {
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 @@ public interface IMutationCondition {
* 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 class BeeMutation extends Mutation implements IBeeMutation, IBeeMutationB
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 class TreeMutation extends Mutation implements ITreeMutation, ITreeMutati
@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.ITree;
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.nbt.NBTTagCompound;
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 class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
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 class ClimateManager implements IClimateManager{
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 java.util.List;
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 abstract class Mutation implements IMutation, IMutationBuilder {
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.Arrays;
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 class MutationConditionBiome implements IMutationCondition {
}
@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 class MutationConditionDaytime implements IMutationCondition {
}
@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 class MutationConditionHumidity implements IMutationCondition {
}
@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.HashSet;
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 class MutationConditionRequiresResource implements IMutationCondition {
}
@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 class MutationConditionTemperature implements IMutationCondition {
}
@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 @@ package forestry.core.genetics.mutations;
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 class MutationConditionTimeLimited implements IMutationCondition {
}
@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 class ButterflyMutation extends Mutation implements IButterflyMutation, I
@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;
}