use of forestry.api.lepidopterology.IButterfly in project ForestryMC by ForestryMC.
the class Butterfly method copy.
@Override
public IButterfly copy() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new Butterfly(nbttagcompound);
}
use of forestry.api.lepidopterology.IButterfly in project ForestryMC by ForestryMC.
the class Butterfly method spawnCaterpillar.
@Override
@Nullable
public IButterfly spawnCaterpillar(World world, IButterflyNursery nursery) {
// We need a mated queen to produce offspring.
if (mate == null) {
return null;
}
IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
IChromosome[] parent1 = genome.getChromosomes();
IChromosome[] parent2 = mate.getChromosomes();
// Check for mutation. Replace one of the parents with the mutation
// template if mutation occured.
IChromosome[] mutated1 = mutateSpecies(world, nursery, genome, mate);
if (mutated1 != null) {
parent1 = mutated1;
}
IChromosome[] mutated2 = mutateSpecies(world, nursery, mate, genome);
if (mutated2 != null) {
parent2 = mutated2;
}
for (int i = 0; i < parent1.length; i++) {
if (parent1[i] != null && parent2[i] != null) {
chromosomes[i] = Chromosome.inheritChromosome(rand, parent1[i], parent2[i]);
}
}
return new Butterfly(new ButterflyGenome(chromosomes));
}
use of forestry.api.lepidopterology.IButterfly in project ForestryMC by ForestryMC.
the class CocoonDecorator method decorateCocoons.
public static void decorateCocoons(World world, Random rand, int chunkX, int chunkZ) {
List<IButterfly> butterflys = ButterflyManager.butterflyRoot.getIndividualTemplates();
Collections.shuffle(butterflys, rand);
for (IButterfly butterfly : butterflys) {
if (genCocoon(world, rand, chunkX, chunkZ, butterfly)) {
return;
}
}
}
use of forestry.api.lepidopterology.IButterfly in project ForestryMC by ForestryMC.
the class EntityButterfly method readEntityFromNBT.
@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
super.readEntityFromNBT(nbttagcompound);
IButterfly butterfly = null;
if (nbttagcompound.hasKey("BTFLY")) {
butterfly = new Butterfly((NBTTagCompound) nbttagcompound.getTag("BTFLY"));
}
setIndividual(butterfly);
if (nbttagcompound.hasKey("PLN")) {
NBTTagCompound pollenNBT = nbttagcompound.getCompoundTag("PLN");
ISpeciesRoot root;
if (pollenNBT.hasKey("Root")) {
root = AlleleManager.alleleRegistry.getSpeciesRoot(pollenNBT.getString("Root"));
} else {
root = TreeManager.treeRoot;
}
pollen = root.getMember(pollenNBT);
}
EnumButterflyState state = EnumButterflyState.VALUES[nbttagcompound.getByte("STATE")];
setState(state);
exhaustion = nbttagcompound.getInteger("EXH");
BlockPos home = new BlockPos(nbttagcompound.getInteger("homeX"), nbttagcompound.getInteger("homeY"), nbttagcompound.getInteger("homeZ"));
setHomePosAndDistance(home, ModuleLepidopterology.maxDistance);
}
use of forestry.api.lepidopterology.IButterfly in project ForestryMC by ForestryMC.
the class ItemButterflyGE method onEntityItemUpdate.
@Override
public boolean onEntityItemUpdate(EntityItem entityItem) {
if (type != EnumFlutterType.BUTTERFLY) {
return false;
}
if (entityItem.world.isRemote || entityItem.ticksExisted < 80) {
return false;
}
if (rand.nextInt(24) != 0) {
return false;
}
IButterfly butterfly = ButterflyManager.butterflyRoot.getMember(entityItem.getItem());
if (butterfly == null) {
return false;
}
if (!butterfly.canTakeFlight(entityItem.world, entityItem.posX, entityItem.posY, entityItem.posZ)) {
return false;
}
if (entityItem.world.countEntities(EntityButterfly.class) > ModuleLepidopterology.entityConstraint) {
return false;
}
EntityUtil.spawnEntity(entityItem.world, new EntityButterfly(entityItem.world, butterfly, entityItem.getPosition()), entityItem.posX, entityItem.posY, entityItem.posZ);
if (!entityItem.getItem().isEmpty()) {
entityItem.getItem().shrink(1);
} else {
entityItem.setDead();
}
return true;
}
Aggregations