Search in sources :

Example 6 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class EntityButterfly method onUpdate.

/* UPDATING */
@Override
public void onUpdate() {
    super.onUpdate();
    // Update stuff client side
    if (world.isRemote) {
        if (species == null) {
            String speciesUid = dataManager.get(DATAWATCHER_ID_SPECIES);
            IAllele allele = AlleleManager.alleleRegistry.getAllele(speciesUid);
            if (allele instanceof IAlleleButterflySpecies) {
                species = (IAlleleButterflySpecies) allele;
                textureResource = new ResourceLocation(species.getEntityTexture());
                size = dataManager.get(DATAWATCHER_ID_SIZE) / 100f;
            }
        }
        byte stateOrdinal = dataManager.get(DATAWATCHER_ID_STATE);
        if (state.ordinal() != stateOrdinal) {
            setState(EnumButterflyState.VALUES[stateOrdinal]);
        }
    }
    motionY *= 0.6000000238418579d;
    // Make sure we die if the butterfly hasn't rested in a long, long time.
    if (exhaustion > EXHAUSTION_CONSUMPTION && getRNG().nextInt(20) == 0) {
        attackEntityFrom(DamageSource.GENERIC, 1);
    }
    if (ticksExisted > MAX_LIFESPAN) {
        attackEntityFrom(DamageSource.GENERIC, 1);
    }
    // Reduce cooldowns
    if (cooldownEgg > 0) {
        cooldownEgg--;
    }
    if (cooldownPollination > 0) {
        cooldownPollination--;
    }
    if (cooldownMate > 0) {
        cooldownMate--;
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ResourceLocation(net.minecraft.util.ResourceLocation) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies)

Example 7 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class ModuleLepidopterology method parseRarity.

private static void parseRarity(LocalizedConfiguration config) {
    List<String> butterflyRarity = Lists.newArrayList();
    for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
        if (allele instanceof IAlleleButterflySpecies) {
            IAlleleButterflySpecies species = (IAlleleButterflySpecies) allele;
            butterflyRarity.add(species.getUID() + ":" + species.getRarity());
        }
    }
    Collections.sort(butterflyRarity);
    String[] defaultRaritys = butterflyRarity.toArray(new String[butterflyRarity.size()]);
    Property rarityConf = config.get("butterfly.alleles", "rarity", defaultRaritys);
    rarityConf.setComment(Translator.translateToLocal("for.config.butterfly.alleles.rarity"));
    String[] configRaritys = rarityConf.getStringList();
    for (String rarity : configRaritys) {
        if (rarity.contains(":") && rarity.length() > 3) {
            String[] raritys = rarity.split(":");
            try {
                spawnRaritys.put(raritys[0], Float.parseFloat(raritys[1]));
            } catch (Exception e) {
                Log.error("Failed to parse spawn rarity for butterfly. {}", rarity, e);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) Property(net.minecraftforge.common.config.Property) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies)

Aggregations

IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)7 EnumHumidity (forestry.api.core.EnumHumidity)2 EnumTemperature (forestry.api.core.EnumTemperature)2 IErrorState (forestry.api.core.IErrorState)2 EnumTolerance (forestry.api.genetics.EnumTolerance)2 IAllele (forestry.api.genetics.IAllele)2 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)2 HashSet (java.util.HashSet)2 World (net.minecraft.world.World)2 IAlleleInteger (forestry.api.genetics.IAlleleInteger)1 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)1 AlleleBoolean (forestry.core.genetics.alleles.AlleleBoolean)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Property (net.minecraftforge.common.config.Property)1