Use new bee API for species and mutations. For Forestry 4.2.1 (future)

This commit is contained in:
mezz committed 2015-11-22 09:15:51 -08:00
1 parent ab70d8aec2
commit ab5b7c7532
27 files changed
+715 -1162

No files matched your search

+111 -361
View File
@@ -1,52 +1,32 @@
package magicbees.bees;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import magicbees.main.CommonProxy;
import magicbees.main.Config;
import magicbees.main.utils.LocalizationManager;
import magicbees.main.utils.compat.AppliedEnergisticsHelper;
import magicbees.main.utils.compat.ArsMagicaHelper;
import magicbees.main.utils.compat.BloodMagicHelper;
import magicbees.main.utils.compat.BotaniaHelper;
import magicbees.main.utils.compat.EquivalentExchangeHelper;
import magicbees.main.utils.compat.ForestryHelper;
import magicbees.main.utils.compat.RedstoneArsenalHelper;
import magicbees.main.utils.compat.ThaumcraftHelper;
import magicbees.main.utils.compat.ThermalModsHelper;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.apiculture.IAlleleBeeSpeciesCustom;
import forestry.api.apiculture.IBeeFactory;
import forestry.api.apiculture.IBeeIconColourProvider;
import forestry.api.apiculture.IBeeIconProvider;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.IIconProvider;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.EnumTolerance;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleTolerance;
import forestry.api.genetics.IClassification;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider
import magicbees.main.utils.compat.AppliedEnergisticsHelper;
import magicbees.main.utils.compat.ArsMagicaHelper;
import magicbees.main.utils.compat.BloodMagicHelper;
import magicbees.main.utils.compat.BotaniaHelper;
import magicbees.main.utils.compat.EquivalentExchangeHelper;
import magicbees.main.utils.compat.RedstoneArsenalHelper;
import magicbees.main.utils.compat.ThaumcraftHelper;
import magicbees.main.utils.compat.ThermalModsHelper;
public enum BeeSpecies
{
MYSTICAL("Mystical", "mysticum", BeeClassification.VEILED,
0xAFFFB7, EnumTemperature.NORMAL, EnumHumidity.NORMAL, false, false, true),
@@ -573,87 +553,94 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider
if (!AppliedEnergisticsHelper.isActive()) {
AE_SKYSTONE.setInactive();
}
for (BeeSpecies beeSpecies : BeeSpecies.values()) {
if (beeSpecies.isActive()) {
beeSpecies.setupCustomIconProvider();
}
}
}
private String binomial;
private String authority;
private int primaryColour;
private int secondaryColour;
private EnumTemperature temperature;
private EnumHumidity humidity;
private boolean hasEffect;
private boolean isSecret;
private boolean isCounted;
private boolean isActive;
private boolean isNocturnal;
private IClassification branch;
private HashMap<ItemStack, Float> products;
private HashMap<ItemStack, Float> specialties;
private static final String authority = "MysteriousAges";
private final IAlleleBeeSpeciesCustom species;
private final EnumTemperature temperature;
private final EnumHumidity humidity;
private boolean active = true;
private IAllele genomeTemplate[];
private String uid;
private boolean dominant;
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
private BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour,
BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour,
EnumTemperature preferredTemp, EnumHumidity preferredHumidity, boolean hasGlowEffect, boolean isSpeciesDominant) {
this(speciesName, genusName, classification, firstColour, BodyColours.DEFAULT,
preferredTemp, preferredHumidity, hasGlowEffect, true, true, isSpeciesDominant, false);
}
private BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
EnumTemperature preferredTemp, EnumHumidity preferredHumidity, boolean hasGlowEffect, boolean isSpeciesDominant) {
this(speciesName, genusName, classification, firstColour, secondColour,
preferredTemp, preferredHumidity, hasGlowEffect, true, true, isSpeciesDominant, false);
}
private BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
EnumTemperature preferredTemp, EnumHumidity preferredHumidity, boolean isSecret, boolean hasGlowEffect, boolean isSpeciesDominant) {
this(speciesName, genusName, classification, firstColour, secondColour,
preferredTemp, preferredHumidity, hasGlowEffect, isSecret, true, isSpeciesDominant, false);
}
private BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour,
BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour,
EnumTemperature preferredTemp, EnumHumidity preferredHumidity, boolean isSecret, boolean hasGlowEffect, boolean isSpeciesDominant) {
this(speciesName, genusName, classification, firstColour, BodyColours.DEFAULT,
preferredTemp, preferredHumidity, hasGlowEffect, isSecret, true, isSpeciesDominant, false);
}
private BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
BeeSpecies(String speciesName, String genusName, IClassification classification, int firstColour, int secondColour,
EnumTemperature preferredTemp, EnumHumidity preferredHumidity, boolean hasGlowEffect, boolean isSpeciesSecret, boolean isSpeciesCounted,
boolean isSpeciesDominant, boolean isSpeciesNocturnal) {
this.uid = "magicbees.species" + speciesName;
this.dominant = isSpeciesDominant;
AlleleManager.alleleRegistry.registerAllele(this);
binomial = genusName;
authority = "MysteriousAges";
primaryColour = firstColour;
secondaryColour = secondColour;
temperature = preferredTemp;
humidity = preferredHumidity;
hasEffect = hasGlowEffect;
isSecret = isSpeciesSecret;
isCounted = isSpeciesCounted;
products = new HashMap<ItemStack, Float>();
specialties = new HashMap<ItemStack, Float>();
this.branch = classification;
this.branch.addMemberSpecies(this);
this.isNocturnal = isSpeciesNocturnal;
this.isActive = true;
String uid = "magicbees.species" + speciesName;
this.temperature = preferredTemp;
this.humidity = preferredHumidity;
IBeeFactory beeFactory = forestry.api.apiculture.BeeManager.beeFactory;
this.species = beeFactory.createSpecies(uid, isSpeciesDominant, authority, uid, uid + ".description", classification, genusName, firstColour, secondColour);
this.species.setTemperature(preferredTemp);
this.species.setHumidity(preferredHumidity);
if (isSpeciesNocturnal) {
this.species.setNocturnal();
}
if (hasGlowEffect) {
this.species.setHasEffect();
}
if (isSpeciesSecret) {
this.species.setIsSecret();
}
if (!isSpeciesCounted) {
this.species.setIsNotCounted();
}
classification.addMemberSpecies(species);
}
public IAllele[] getGenome() {
return genomeTemplate;
}
public IAlleleBeeSpecies getSpecies() {
return species;
}
public BeeSpecies addProduct(ItemStack produce, float chance) {
products.put(produce, chance);
species.addProduct(produce, chance);
return this;
}
public BeeSpecies addSpecialty(ItemStack produce, float chance) {
specialties.put(produce, chance);
species.addSpecialty(produce, chance);
return this;
}
@@ -661,301 +648,72 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider
return BeeManager.beeRoot.getMemberStack(BeeManager.beeRoot.getBee(null, BeeManager.beeRoot.templateAsGenome(genomeTemplate)), beeType.ordinal());
}
@Override
public String getName() {
return LocalizationManager.getLocalizedString(getUID());
}
@Override
public String getDescription() {
return LocalizationManager.getLocalizedString(getUID() + ".description");
}
@Override
public String getUnlocalizedName() {
return getUID();
}
@Override
public EnumTemperature getTemperature() {
return temperature;
}
@Override
public EnumHumidity getHumidity() {
return humidity;
}
@Override
public boolean hasEffect() {
return hasEffect;
}
public BeeSpecies setInactive() {
this.isActive = false;
AlleleManager.alleleRegistry.blacklistAllele(this.getUID());
this.active = false;
AlleleManager.alleleRegistry.blacklistAllele(species.getUID());
return this;
}
public boolean isActive() {
return this.isActive;
return active;
}
@Override
public boolean isSecret() {
return isSecret;
}
@Override
public boolean isCounted() {
return isCounted;
}
@Override
public String getBinomial() {
return binomial;
}
@Override
public String getAuthority() {
return authority;
}
@Override
public IClassification getBranch() {
return this.branch;
}
@Override
public Map<ItemStack, Float> getProductChances() {
return products;
}
@Override
public Map<ItemStack, Float> getSpecialtyChances() {
return specialties;
}
@Override
public String getUID() {
return this.uid;
}
@Override
public boolean isDominant() {
return this.dominant;
}
@Override
public IBeeRoot getRoot() {
return BeeManager.beeRoot;
}
@Override
public boolean isNocturnal() {
return this.isNocturnal;
}
@Override
public boolean isJubilant(IBeeGenome genome, IBeeHousing housing) {
return true;
}
public void registerGenomeTemplate(IAllele[] genome) {
genomeTemplate = genome;
BeeManager.beeRoot.registerTemplate(getUID(), genome);
BeeManager.beeRoot.registerTemplate(species.getUID(), genome);
}
@Override
public int getIconColour(int renderPass) {
int value = 0xffffff;
if (renderPass == 0) {
if (this.primaryColour == -1) {
int hue = (int) (System.currentTimeMillis() >> 2) % 360;
value = Color.getHSBColor(hue / 360f, 0.75f, 0.80f).getRGB();
} else {
value = this.primaryColour;
}
} else if (renderPass == 1) {
if (this.secondaryColour == -1) {
int hue = (int) (System.currentTimeMillis() >> 3) % 360;
hue += 60;
hue = hue % 360;
value = Color.getHSBColor(hue / 360f, 0.5f, 0.6f).getRGB();
} else {
value = this.secondaryColour;
}
}
return value;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return this;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(EnumBeeType type, int renderPass) {
return icons[type.ordinal()][Math.min(renderPass, 2)];
}
@Override
public int getComplexity() {
return 1 + getMutationPathLength(this, new ArrayList<IAllele>());
}
private int getMutationPathLength(IAllele species, ArrayList<IAllele> excludeSpecies) {
int own = 1;
int highest = 0;
excludeSpecies.add(species);
for (IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES)) {
if (!excludeSpecies.contains(mutation.getAllele0())) {
int otherAdvance = getMutationPathLength(mutation.getAllele0(), excludeSpecies);
if (otherAdvance > highest)
highest = otherAdvance;
}
if (!excludeSpecies.contains(mutation.getAllele1())) {
int otherAdvance = getMutationPathLength(mutation.getAllele1(), excludeSpecies);
if (otherAdvance > highest)
highest = otherAdvance;
}
private void setupCustomIconProvider() {
IBeeIconProvider iconProvider = getCustomIconProvider();
if (iconProvider != null) {
this.species.setCustomBeeIconProvider(iconProvider);
}
return own + (highest > 0 ? highest : 0);
}
@Override
public float getResearchSuitability(ItemStack itemStack) {
if (itemStack == null) {
return 0f;
}
for (ItemStack product : this.products.keySet()) {
if (itemStack.isItemEqual(product)) {
return 1f;
}
}
for (ItemStack specialty : this.specialties.keySet()) {
if (specialty.isItemEqual(itemStack)) {
return 1f;
}
}
if (itemStack.getItem() == ForestryHelper.honeyDrop) {
return 0.5f;
} else if (itemStack.getItem() == ForestryHelper.honeydew) {
return 0.7f;
} else if (itemStack.getItem() == ForestryHelper.beeComb || itemStack.getItem() == Config.combs) {
return 0.4f;
} else if (getRoot().isMember(itemStack)) {
return 1.0f;
} else {
for (Map.Entry<ItemStack, Float> catalyst : BeeManager.beeRoot.getResearchCatalysts().entrySet()) {
if (OreDictionary.itemMatches(itemStack, catalyst.getKey(), false)) {
return catalyst.getValue();
}
}
}
return 0f;
}
@Override
public ItemStack[] getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
System.out.println("Bounty level: " + bountyLevel);
ArrayList<ItemStack> bounty = new ArrayList<ItemStack>();
if (world.rand.nextFloat() < ((10f / bountyLevel))) {
Collection<? extends IMutation> resultantMutations = getRoot().getCombinations(this);
if (resultantMutations.size() > 0) {
IMutation[] candidates = resultantMutations.toArray(new IMutation[resultantMutations.size()]);
bounty.add(AlleleManager.alleleRegistry.getMutationNoteStack(researcher, candidates[world.rand.nextInt(candidates.length)]));
}
}
for (ItemStack product : this.products.keySet()) {
ItemStack copy = product.copy();
copy.stackSize = 1 + world.rand.nextInt(bountyLevel / 2);
bounty.add(copy);
}
for (ItemStack specialty : this.specialties.keySet()) {
ItemStack copy = specialty.copy();
copy.stackSize = world.rand.nextInt(bountyLevel / 3);
if (copy.stackSize > 0) {
bounty.add(copy);
}
}
return bounty.toArray(new ItemStack[bounty.size()]);
}
@Override
public String getEntityTexture() {
return "/gfx/forestry/entities/bees/honeyBee.png";
}
@Override
public void registerIcons(IIconRegister itemMap) {
this.icons = new IIcon[EnumBeeType.values().length][3];
String root = this.getIconPath();
IIcon body1 = itemMap.registerIcon(root + "body1");
for (int i = 0; i < EnumBeeType.values().length; i++) {
if (EnumBeeType.values()[i] == EnumBeeType.NONE)
continue;
icons[i][0] = itemMap.registerIcon(root + EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".outline");
icons[i][1] = (EnumBeeType.values()[i] != EnumBeeType.LARVAE) ? body1 : itemMap.registerIcon(root
+ EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".body");
icons[i][2] = itemMap.registerIcon(root + EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".body2");
IBeeIconColourProvider iconColourProvider = getCustomIconColourProvider();
if (iconColourProvider != null) {
this.species.setCustomBeeIconColourProvider(iconColourProvider);
}
}
private String getIconPath() {
String value;
private IBeeIconProvider getCustomIconProvider() {
switch (this) {
case SKULKING:
case GHASTLY:
case SPIDERY:
case SMOULDERING:
case BIGBAD:
case BATTY:
case SHEEPISH:
case HORSE:
case CATTY:
case BRAINY:
case TC_WISPY:
case AM_VORTEX:
case AM_WIGHT:
case TE_BLIZZY:
case TE_GELID:
case TE_DANTE:
case TE_PYRO:
case TE_SHOCKING:
case TE_AMPED:
case TE_GROUNDED:
case TE_ROCKING:
value = CommonProxy.DOMAIN + ":bees/skulking/";
break;
case DOCTORAL:
value = CommonProxy.DOMAIN + ":bees/doctoral/";
break;
case SKULKING:
case GHASTLY:
case SPIDERY:
case SMOULDERING:
case BIGBAD:
case BATTY:
case SHEEPISH:
case HORSE:
case CATTY:
case BRAINY:
case TC_WISPY:
case AM_VORTEX:
case AM_WIGHT:
case TE_BLIZZY:
case TE_GELID:
case TE_DANTE:
case TE_PYRO:
case TE_SHOCKING:
case TE_AMPED:
case TE_GROUNDED:
case TE_ROCKING:
return BeeIconProvider.SKULKING;
default:
value = ForestryHelper.Name.toLowerCase() + ":bees/default/";
break;
case DOCTORAL:
return BeeIconProvider.DOCTORAL;
default:
return null;
}
}
return value;
private IBeeIconColourProvider getCustomIconColourProvider() {
switch (this) {
case BOT_ALFHEIM:
return BeeIconColourProvider.RAINBOW;
}
return null;
}
public boolean canWorkInTemperature(EnumTemperature temp) {
@@ -969,12 +727,4 @@ public enum BeeSpecies implements IAlleleBeeSpecies, IIconProvider
return AlleleManager.climateHelper.isWithinLimits(EnumTemperature.NORMAL, humid, EnumTemperature.NORMAL, EnumTolerance.NONE, humidity,
tolerance.getValue());
}
// --------- Unused Functions ---------------------------------------------
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(short texUID) {
return icons[0][0];
}
}