mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-24 22:04:34 +00:00
Update the butterfly mutations
This commit is contained in:
1 parent
5b42b5fbae
commit
39c6e52d73
10 files changed
+130
-9
No files matched your search
@@ -11,11 +11,19 @@
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
public class ButterflyManager {
|
||||
|
||||
|
||||
/**
|
||||
* Convenient access to AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies")
|
||||
*/
|
||||
public static IButterflyRoot butterflyRoot;
|
||||
|
||||
/**
|
||||
* Used to create new butterflies.
|
||||
*/
|
||||
public static IButterflyFactory butterflyFactory;
|
||||
|
||||
/**
|
||||
* Used to create new butterfly mutations.
|
||||
*/
|
||||
public static IButterflyMutationFactory butterflyMutationFactory;
|
||||
}
|
||||
@@ -56,7 +56,11 @@ public interface IButterfly extends IIndividualLiving {
|
||||
*/
|
||||
boolean isAcceptedEnvironment(World world, double x, double y, double z);
|
||||
|
||||
IButterfly spawnCaterpillar(IButterflyNursery nursery);
|
||||
/**
|
||||
* @param world
|
||||
* @return create a caterpillar with the two genome's from the nursery.
|
||||
*/
|
||||
IButterfly spawnCaterpillar(World world, IButterflyNursery nursery);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
|
||||
@@ -8,7 +8,8 @@ package forestry.api.lepidopterology;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IButterflyMutation extends IMutation {
|
||||
float getChance(IButterflyNursery housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1);
|
||||
float getChance(World world, IButterflyNursery housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import forestry.api.genetics.IMutationCustom;
|
||||
|
||||
public interface IButterflyMutationCustom extends IButterflyMutation, IMutationCustom {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
public interface IButterflyMutationFactory {
|
||||
/**
|
||||
* Creates a new butterfly mutation.
|
||||
* Automatically registered with ButterflyManager.butterflyRoot.registerMutation()
|
||||
* See IButterflyMutationCustom and IMutationCustom for adding additional properties to the returned mutation.
|
||||
*
|
||||
* @param parentTree0 A parent butterfly for this mutation
|
||||
* @param parentTree1 A parent butterfly for this mutation
|
||||
* @param result The resulting alleles for this mutation
|
||||
* @param chance The chance that breeding the two parent butterfly's will result in this mutation
|
||||
* @return a new tree mutation.
|
||||
*/
|
||||
IButterflyMutationCustom createMutation(IAlleleButterflySpecies parentButterfly0, IAlleleButterflySpecies parentButterfly1, IAllele[] result, int chance);
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import forestry.lepidopterology.genetics.ButterflyBranchDefinition;
|
||||
import forestry.lepidopterology.genetics.ButterflyDefinition;
|
||||
import forestry.lepidopterology.genetics.ButterflyFactory;
|
||||
import forestry.lepidopterology.genetics.ButterflyMutationFactory;
|
||||
import forestry.lepidopterology.genetics.ButterflyRoot;
|
||||
import forestry.lepidopterology.genetics.MothDefinition;
|
||||
import forestry.lepidopterology.genetics.alleles.AlleleButterflyEffect;
|
||||
@@ -76,6 +77,7 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
AlleleManager.alleleRegistry.registerSpeciesRoot(ButterflyManager.butterflyRoot);
|
||||
|
||||
ButterflyManager.butterflyFactory = new ButterflyFactory();
|
||||
ButterflyManager.butterflyMutationFactory = new ButterflyMutationFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,7 +65,7 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(nursery));
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(entity.worldObj, nursery));
|
||||
// Log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getRNG().nextFloat() < 1.0f / entity.getButterfly().getGenome().getFertility()) {
|
||||
entity.setHealth(0);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IButterfly spawnCaterpillar(IButterflyNursery nursery) {
|
||||
public IButterfly spawnCaterpillar(World world, IButterflyNursery nursery) {
|
||||
// We need a mated queen to produce offspring.
|
||||
if (mate == null) {
|
||||
return null;
|
||||
@@ -200,11 +200,11 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
|
||||
// Check for mutation. Replace one of the parents with the mutation
|
||||
// template if mutation occured.
|
||||
IChromosome[] mutated1 = mutateSpecies(nursery, genome, mate);
|
||||
IChromosome[] mutated1 = mutateSpecies(world, nursery, genome, mate);
|
||||
if (mutated1 != null) {
|
||||
parent1 = mutated1;
|
||||
}
|
||||
IChromosome[] mutated2 = mutateSpecies(nursery, mate, genome);
|
||||
IChromosome[] mutated2 = mutateSpecies(world, nursery, mate, genome);
|
||||
if (mutated2 != null) {
|
||||
parent2 = mutated2;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
return new Butterfly(new ButterflyGenome(chromosomes));
|
||||
}
|
||||
|
||||
private static IChromosome[] mutateSpecies(IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) {
|
||||
private static IChromosome[] mutateSpecies(World world, IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) {
|
||||
|
||||
IChromosome[] parent1 = genomeOne.getChromosomes();
|
||||
IChromosome[] parent2 = genomeTwo.getChromosomes();
|
||||
@@ -243,7 +243,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(world, nursery, allele0, allele1, genome0, genome1);
|
||||
if (chance > rand.nextFloat() * 100) {
|
||||
return ButterflyManager.butterflyRoot.templateAsChromosomes(mutation.getTemplate());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* 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.lepidopterology.genetics;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterflyMutationCustom;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.genetics.mutations.Mutation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ButterflyMutation extends Mutation implements IButterflyMutationCustom {
|
||||
|
||||
protected ButterflyMutation(IAlleleSpecies species0, IAlleleSpecies species1, IAllele[] template, int chance) {
|
||||
super(species0, species1, template, chance);
|
||||
}
|
||||
|
||||
@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);
|
||||
if (processedChance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return processedChance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpeciesRoot getRoot() {
|
||||
return ButterflyManager.butterflyRoot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* 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.lepidopterology.genetics;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IButterflyMutationCustom;
|
||||
import forestry.api.lepidopterology.IButterflyMutationFactory;
|
||||
|
||||
public class ButterflyMutationFactory implements IButterflyMutationFactory {
|
||||
|
||||
@Override
|
||||
public IButterflyMutationCustom createMutation(IAlleleButterflySpecies parentButterfly0, IAlleleButterflySpecies parentButterfly1, IAllele[] result, int chance) {
|
||||
IButterflyMutationCustom mutation = new ButterflyMutation(parentButterfly0, parentButterfly1, result, chance);
|
||||
ButterflyManager.butterflyRoot.registerMutation(mutation);
|
||||
return mutation;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user