Files
MagicBees/magicbees_src/magicbees/bees/BeeMutation.java
T

276 lines
6.8 KiB
Java
Raw Normal View History

2013-05-23 21:07:28 -07:00
package magicbees.bees;
2012-12-24 15:12:37 -08:00
import forestry.api.apiculture.*;
2013-04-28 22:11:56 -07:00
import forestry.api.core.BlockInterface;
import forestry.api.core.ItemInterface;
2012-12-24 15:12:37 -08:00
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import java.util.ArrayList;
2013-05-23 21:07:28 -07:00
import magicbees.main.ThaumicBees;
import magicbees.main.utils.MoonPhase;
import magicbees.main.utils.compat.ArsMagicaHelper;
import magicbees.main.utils.compat.EquivalentExchangeHelper;
import magicbees.main.utils.compat.ExtraBeesHelper;
import magicbees.main.utils.compat.ForestryHelper;
import magicbees.main.utils.compat.ThaumcraftHelper;
2013-04-28 22:11:56 -07:00
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
2013-02-09 14:12:43 -08:00
import cpw.mods.fml.common.FMLLog;
2013-01-26 13:42:39 -08:00
import thaumcraft.api.ThaumcraftApi;
2013-04-21 15:38:52 -07:00
import thaumcraft.api.aura.AuraNode;
import thaumcraft.api.aura.EnumNodeType;
2013-01-26 13:42:39 -08:00
2012-12-24 15:12:37 -08:00
public class BeeMutation implements IBeeMutation
{
2013-02-09 14:12:43 -08:00
public static void setupMutations()
{
}
2012-12-27 00:27:23 -08:00
2012-12-24 15:12:37 -08:00
private IAllele parent1;
private IAllele parent2;
private IAllele mutationTemplate[];
2012-12-27 00:27:23 -08:00
private int baseChance;
2012-12-24 15:12:37 -08:00
private boolean isSecret;
2013-01-19 03:29:47 -08:00
private boolean isMoonRestricted;
private MoonPhase moonPhaseStart;
private MoonPhase moonPhaseEnd;
private float moonPhaseMutationBonus;
2013-01-26 13:42:39 -08:00
private boolean nodeRequired;
private EnumNodeType nodeType;
private double nodeRange;
2013-04-28 22:11:56 -07:00
private boolean requiresBlock;
private int requiredBlockId;
private int requiredBlockMeta;
private String requiredBlockOreDictEntry;
2012-12-24 15:12:37 -08:00
2013-01-19 03:29:47 -08:00
public BeeMutation(IAlleleBeeSpecies species0, IAlleleBeeSpecies species1, BeeSpecies resultSpecies, int percentChance)
2012-12-24 15:12:37 -08:00
{
2013-01-19 03:29:47 -08:00
this.parent1 = species0;
this.parent2 = species1;
this.mutationTemplate = resultSpecies.getGenome();
this.baseChance = percentChance;
this.isSecret = false;
this.isMoonRestricted = false;
this.moonPhaseMutationBonus = -1f;
2013-01-26 13:42:39 -08:00
this.nodeType = null;
2013-04-28 22:11:56 -07:00
this.requiresBlock = false;
this.requiredBlockMeta = OreDictionary.WILDCARD_VALUE;
this.requiredBlockOreDictEntry = null;
Allele.beeRoot.registerMutation(this);
2012-12-24 15:12:37 -08:00
}
2013-04-15 00:17:50 -07:00
public float getChance(IBeeHousing housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1)
2012-12-24 15:12:37 -08:00
{
2013-04-15 00:17:50 -07:00
float finalChance = 0f;
2013-01-19 03:29:47 -08:00
float chance = this.baseChance * 1f;
2012-12-27 00:27:23 -08:00
2013-01-26 13:42:39 -08:00
if (this.arePartners(allele0, allele1))
2012-12-27 00:27:23 -08:00
{
// This mutation applies. Continue calculation.
2013-01-19 03:29:47 -08:00
if (this.moonPhaseStart != null && this.moonPhaseEnd != null)
{
// Only occurs during the phases.
if (this.isMoonRestricted && !MoonPhase.getMoonPhase(housing.getWorld()).isBetween(this.moonPhaseStart, this.moonPhaseEnd))
{
chance = 0;
}
else if (this.moonPhaseMutationBonus != -1f)
{
// There is a bonus to this mutation during moon phases...
if (MoonPhase.getMoonPhase(housing.getWorld()).isBetween(this.moonPhaseStart, this.moonPhaseEnd))
{
chance = (int)(chance * this.moonPhaseMutationBonus);
}
}
}
2013-01-26 13:42:39 -08:00
if (this.nodeRequired)
{
int nodeId = ThaumcraftApi.getClosestAuraWithinRange(housing.getWorld(),
housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), this.nodeRange);
if (nodeId >= 0)
2013-01-26 13:42:39 -08:00
{
if (this.nodeType != null)
2013-01-26 13:42:39 -08:00
{
// Needs a _specific_ variety of node
AuraNode node = ThaumcraftApi.getNodeCopy(nodeId);
if (node.type != this.nodeType)
{
chance = 0;
}
2013-01-26 13:42:39 -08:00
}
}
else
{
chance = 0;
}
}
2013-04-28 22:11:56 -07:00
if (this.requiresBlock)
{
int blockId = housing.getWorld().getBlockId(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
int blockMeta = housing.getWorld().getBlockMetadata(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
if (this.requiredBlockOreDictEntry != null)
{
int dicId = OreDictionary.getOreID(new ItemStack(blockId, 1, blockMeta));
if (dicId != -1)
{
if (!OreDictionary.getOreName(dicId).equals(this.requiredBlockOreDictEntry))
{
chance = 0;
}
}
else
{
chance = 0;
}
}
else if (this.requiredBlockId != blockId || (this.requiredBlockMeta != OreDictionary.WILDCARD_VALUE && this.requiredBlockMeta != blockMeta))
{
chance = 0;
}
}
finalChance = Math.round(chance
* housing.getMutationModifier((IBeeGenome) genome0,
2013-04-15 00:17:50 -07:00
(IBeeGenome) genome1, chance)
* Allele.beeRoot.getBeekeepingMode(housing.getWorld())
.getMutationModifier((IBeeGenome) genome0,
2013-04-15 00:17:50 -07:00
(IBeeGenome) genome1, chance));
2012-12-27 00:27:23 -08:00
}
2013-01-19 03:29:47 -08:00
return finalChance;
2012-12-24 15:12:37 -08:00
}
public IAllele getAllele0()
{
return parent1;
}
public IAllele getAllele1()
{
return parent2;
}
public IAllele[] getTemplate()
{
return mutationTemplate;
}
2013-04-15 00:17:50 -07:00
public float getBaseChance()
2012-12-24 15:12:37 -08:00
{
2012-12-27 00:27:23 -08:00
return baseChance;
2012-12-24 15:12:37 -08:00
}
public boolean isPartner(IAllele allele)
{
return parent1.getUID().equals(allele.getUID()) || parent2.getUID().equals(allele.getUID());
}
public IAllele getPartner(IAllele allele)
{
IAllele val = parent1;
if (val.getUID().equals(allele.getUID()))
val = parent2;
return val;
}
2013-01-19 03:29:47 -08:00
2013-01-26 13:42:39 -08:00
public boolean arePartners(IAllele alleleA, IAllele alleleB)
{
return (this.parent1.getUID().equals(alleleA.getUID())) && this.parent2.getUID().equals(alleleB.getUID()) ||
this.parent1.getUID().equals(alleleB.getUID()) && this.parent2.getUID().equals(alleleA.getUID());
}
2013-01-19 03:29:47 -08:00
public BeeMutation setSecret()
{
this.isSecret = true;
return this;
}
2012-12-24 15:12:37 -08:00
public boolean isSecret()
{
return isSecret;
}
2013-01-19 03:29:47 -08:00
2013-04-28 22:11:56 -07:00
public BeeMutation setBlockRequired(int blockId)
{
this.requiresBlock = true;
this.requiredBlockId = blockId;
return this;
}
public BeeMutation setBlockRequired(Block block)
{
this.requiresBlock = true;
this.requiredBlockId = block.blockID;
return this;
}
public BeeMutation setBlockAndMetaRequired(int blockId, int meta)
{
this.requiresBlock = true;
this.requiredBlockId = blockId;
this.requiredBlockMeta = meta;
return this;
}
public BeeMutation setBlockAndMetaRequired(Block block, int meta)
{
this.requiresBlock = true;
this.requiredBlockId = block.blockID;
this.requiredBlockMeta = meta;
return this;
}
public BeeMutation setBlockRequired(String oreDictEntry)
{
this.requiresBlock = true;
this.requiredBlockOreDictEntry = oreDictEntry;
return this;
}
2013-01-19 03:29:47 -08:00
public BeeMutation setMoonPhaseRestricted(MoonPhase begin, MoonPhase end)
{
this.isMoonRestricted = true;
this.moonPhaseStart = begin;
this.moonPhaseEnd = end;
return this;
}
public BeeMutation setMoonPhaseBonus(MoonPhase begin, MoonPhase end, float mutationBonus)
{
this.moonPhaseMutationBonus = mutationBonus;
this.moonPhaseStart = begin;
this.moonPhaseEnd = end;
return this;
}
2013-01-26 13:42:39 -08:00
public BeeMutation setAuraNodeRequired(double range)
{
this.nodeRequired = true;
this.nodeRange = range;
return this;
}
public BeeMutation setAuraNodeTypeRequired(double range, EnumNodeType type)
{
this.nodeType = type;
return this.setAuraNodeRequired(range);
}
2012-12-24 15:12:37 -08:00
}