mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
Update code to handle mutations with modified climate
This commit is contained in:
1 parent
7ea1f150e0
commit
7e889775c1
16 files changed
+121
-20
No files matched your search
@@ -12,6 +12,7 @@ package forestry;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import forestry.core.ClimateManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
@@ -74,6 +75,7 @@ public class Forestry {
|
||||
|
||||
public Forestry() {
|
||||
ForestryAPI.instance = this;
|
||||
ForestryAPI.climateManager = new ClimateManager();
|
||||
ForestryAPI.forestryConstants = new Constants();
|
||||
ForestryAPI.errorStateRegistry = new ErrorStateRegistry();
|
||||
EnumErrorCode.init();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BeeMutation extends Mutation implements IBeeMutationCustom {
|
||||
int y = housingCoordinates.posY;
|
||||
int z = housingCoordinates.posZ;
|
||||
|
||||
float processedChance = super.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
float processedChance = super.getChance(world, x, y, z, allele0, allele1, genome0, genome1, housing);
|
||||
if (processedChance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.genetics;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
@@ -33,7 +34,7 @@ public class TreeMutation extends Mutation implements ITreeMutationCustom {
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAlleleTreeSpecies allele0, IAlleleTreeSpecies allele1, ITreeGenome genome0, ITreeGenome genome1) {
|
||||
float processedChance = super.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
float processedChance = super.getChance(world, x, y, z, allele0, allele1, genome0, genome1, ForestryAPI.climateManager.getDefaultClimate(world, x, y, z));
|
||||
if (processedChance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
@@ -39,6 +40,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;
|
||||
@@ -576,4 +580,19 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
ITree tree = getTree();
|
||||
return !isDecorative && !isDestroyed(tree, damage) && caterpillar == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiome() {
|
||||
return worldObj.getBiomeGenForCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromBiome(getBiome(), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(ForestryAPI.climateManager.getHumidity(worldObj, xCoord, yCoord, zCoord));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import forestry.api.core.IClimateManager;
|
||||
|
||||
public class ClimateManager implements IClimateManager {
|
||||
|
||||
@Override
|
||||
public float getTemperature(World world, int x, int y, int z) {
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
|
||||
return biome.temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHumidity(World world, int x, int y, int z) {
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
|
||||
return biome.rainfall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateProvider getDefaultClimate(World world, int x, int y, int z) {
|
||||
return new DefaultClimateProvider(world, x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class DefaultClimateProvider implements IClimateProvider {
|
||||
private World world;
|
||||
private int xCoord, yCoord, zCoord;
|
||||
|
||||
public DefaultClimateProvider(World world, int x, int y, int z) {
|
||||
this.world = world;
|
||||
this.xCoord = x;
|
||||
this.yCoord = y;
|
||||
this.zCoord = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiome() {
|
||||
return world.getBiomeGenForCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromBiome(getBiome(), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(ForestryAPI.climateManager.getHumidity(world, xCoord, yCoord, zCoord));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
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 IMutationCustom {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
protected float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
float mutationChance = chance;
|
||||
for (IMutationCondition mutationCondition : mutationConditions) {
|
||||
mutationChance *= mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1);
|
||||
mutationChance *= mutationCondition.getChance(world, x, y, z, allele0, allele1, genome0, genome1, climate);
|
||||
if (mutationChance == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
@@ -33,8 +34,8 @@ public class MutationConditionBiome implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
BiomeGenBase biome = climate.getBiome();
|
||||
for (BiomeDictionary.Type type : validBiomeTypes) {
|
||||
if (BiomeDictionary.isBiomeOfType(biome, type)) {
|
||||
return 1;
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.genetics.mutations;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
@@ -26,7 +27,7 @@ public class MutationConditionDaytime implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
if (world.isDaytime() == daytime) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
@@ -30,9 +30,8 @@ public class MutationConditionHumidity implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(x, z);
|
||||
EnumHumidity biomeHumidity = EnumHumidity.getFromValue(biome.rainfall);
|
||||
public float getChance(World world, int x, int y, int z, 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;
|
||||
|
||||
+3
-1
@@ -11,6 +11,7 @@
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
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;
|
||||
@@ -18,6 +19,7 @@ import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -34,7 +36,7 @@ public class MutationConditionRequiresResource implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
/*
|
||||
Block block;
|
||||
TileEntity tile;
|
||||
|
||||
+3
-1
@@ -11,11 +11,13 @@
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
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;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
@@ -40,7 +42,7 @@ public class MutationConditionRequiresResourceOreDict implements IMutationCondit
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
/*
|
||||
Block block;
|
||||
int meta;
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
@@ -31,9 +31,8 @@ public class MutationConditionTemperature implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(x, z);
|
||||
EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, x, y, z);
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
EnumTemperature biomeTemperature = climate.getTemperature();
|
||||
|
||||
if (biomeTemperature.ordinal() < minTemperature.ordinal() || biomeTemperature.ordinal() > maxTemperature.ordinal()) {
|
||||
return 0;
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.Calendar;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.IClimateProvider;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
@@ -31,7 +32,7 @@ public class MutationConditionTimeLimited implements IMutationCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1, IClimateProvider climate) {
|
||||
DayMonth now = new DayMonth();
|
||||
|
||||
// If we are equal to start day, return 1.
|
||||
|
||||
@@ -248,7 +248,7 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
}
|
||||
|
||||
for (IButterflyMutation mutation : ButterflyManager.butterflyRoot.getMutations(true)) {
|
||||
float chance = mutation.getChance(nursery, allele0, allele1, genome0, genome1);
|
||||
float chance = mutation.getChance(nursery, allele0, allele1, genome0, genome1, nursery);
|
||||
if (chance > rand.nextFloat() * 100) {
|
||||
return ButterflyManager.butterflyRoot.templateAsChromosomes(mutation.getTemplate());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user