Search in sources :

Example 1 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker in project ForestryMC by ForestryMC.

the class BreedingTracker method synchToPlayer.

@Override
public void synchToPlayer(EntityPlayer player) {
    if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
        IBreedingTracker breedingTracker = getBreedingTracker(player);
        String modeName = breedingTracker.getModeName();
        setModeName(modeName);
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        encodeToNBT(nbttagcompound);
        PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbttagcompound);
        NetworkUtil.sendToPlayer(packet, player);
    }
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketGenomeTrackerSync(forestry.core.network.packets.PacketGenomeTrackerSync) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 2 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker in project ForestryMC by ForestryMC.

the class AlleleSpecies method getResearchBounty.

@Override
public NonNullList<ItemStack> getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
    if (world.rand.nextFloat() < bountyLevel / 16.0f) {
        List<? extends IMutation> allMutations = getRoot().getCombinations(this);
        if (!allMutations.isEmpty()) {
            List<IMutation> unresearchedMutations = new ArrayList<>();
            IBreedingTracker tracker = individual.getGenome().getSpeciesRoot().getBreedingTracker(world, researcher);
            for (IMutation mutation : allMutations) {
                if (!tracker.isResearched(mutation)) {
                    unresearchedMutations.add(mutation);
                }
            }
            IMutation chosenMutation;
            if (!unresearchedMutations.isEmpty()) {
                chosenMutation = unresearchedMutations.get(world.rand.nextInt(unresearchedMutations.size()));
            } else {
                chosenMutation = allMutations.get(world.rand.nextInt(allMutations.size()));
            }
            ItemStack researchNote = AlleleManager.alleleRegistry.getMutationNoteStack(researcher, chosenMutation);
            NonNullList<ItemStack> bounty = NonNullList.create();
            bounty.add(researchNote);
            return bounty;
        }
    }
    return NonNullList.create();
}
Also used : IMutation(forestry.api.genetics.IMutation) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker in project ForestryMC by ForestryMC.

the class PickupHandlerCore method onItemPickup.

@Override
public boolean onItemPickup(EntityPlayer entityPlayer, EntityItem entityitem) {
    ItemStack itemstack = entityitem.getItem();
    if (itemstack.isEmpty()) {
        return false;
    }
    ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(itemstack);
    if (root != null) {
        IIndividual individual = root.getMember(itemstack);
        if (individual != null) {
            IBreedingTracker tracker = root.getBreedingTracker(entityitem.world, entityPlayer.getGameProfile());
            tracker.registerPickup(individual);
        }
    }
    return false;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker in project Binnie by ForestryMC.

the class WindowAnalyst method initialiseServer.

@Override
public void initialiseServer() {
    for (IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        ISpeciesRoot root = system.getSpeciesRoot();
        if (root != null) {
            IBreedingTracker tracker = root.getBreedingTracker(getWorld(), getUsername());
            if (tracker != null) {
                tracker.synchToPlayer(getPlayer());
            }
        }
    }
    // create slots
    getWindowInventory().createSlot(0);
    getWindowInventory().createSlot(1);
    setupValidators();
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IBreedingTracker(forestry.api.genetics.IBreedingTracker) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem)

Example 5 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker in project ForestryMC by ForestryMC.

the class TileSapling method tryGrow.

public void tryGrow(Random random, boolean bonemealed) {
    ITree tree = getTree();
    if (tree == null) {
        return;
    }
    int maturity = getRequiredMaturity(world, tree);
    if (timesTicked < maturity) {
        if (bonemealed) {
            timesTicked = maturity;
        }
        return;
    }
    WorldGenerator generator = tree.getTreeGenerator(world, getPos(), bonemealed);
    final boolean generated;
    if (generator instanceof WorldGenBase) {
        generated = ((WorldGenBase) generator).generate(world, random, getPos(), false);
    } else {
        generated = generator.generate(world, random, getPos());
    }
    if (generated) {
        IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(world, getOwnerHandler().getOwner());
        breedingTracker.registerBirth(tree);
    }
}
Also used : WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ITree(forestry.api.arboriculture.ITree) WorldGenBase(forestry.core.worldgen.WorldGenBase)

Aggregations

IBreedingTracker (forestry.api.genetics.IBreedingTracker)13 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)7 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 IIndividual (forestry.api.genetics.IIndividual)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)2 IMutation (forestry.api.genetics.IMutation)2 PacketGenomeTrackerSync (forestry.core.network.packets.PacketGenomeTrackerSync)2 ArrayList (java.util.ArrayList)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)1 IItemAnalysable (binnie.core.api.genetics.IItemAnalysable)1 ITree (forestry.api.arboriculture.ITree)1 IAlleleRegistry (forestry.api.genetics.IAlleleRegistry)1 IGenome (forestry.api.genetics.IGenome)1 WorldGenBase (forestry.core.worldgen.WorldGenBase)1 BufferedWriter (java.io.BufferedWriter)1