Search in sources :

Example 6 with IBreedingTracker

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

the class BreedingTracker method syncToPlayer.

private void syncToPlayer(Collection<String> discoveredSpecies, Collection<String> discoveredMutations, Collection<String> researchedMutations) {
    if (world != null && username != null && username.getName() != null) {
        EntityPlayer player = world.getPlayerEntityByName(username.getName());
        if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
            IBreedingTracker breedingTracker = getBreedingTracker(player);
            String modeName = breedingTracker.getModeName();
            setModeName(modeName);
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            writeToNBT(nbtTagCompound, discoveredSpecies, discoveredMutations, researchedMutations);
            PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbtTagCompound);
            NetworkUtil.sendToPlayer(packet, player);
            for (String species : discoveredSpecies) {
                SpeciesDiscoveredTrigger.INSTANCE.trigger((EntityPlayerMP) player, AlleleManager.alleleRegistry.getAllele(species));
            }
        }
    }
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketGenomeTrackerSync(forestry.core.network.packets.PacketGenomeTrackerSync) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 7 with IBreedingTracker

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

the class EventHandlerCore method syncBreedingTrackers.

private static void syncBreedingTrackers(EntityPlayer player) {
    IAlleleRegistry alleleRegistry = AlleleManager.alleleRegistry;
    Collection<ISpeciesRoot> speciesRoots = alleleRegistry.getSpeciesRoot().values();
    for (ISpeciesRoot speciesRoot : speciesRoots) {
        IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.getEntityWorld(), player.getGameProfile());
        breedingTracker.synchToPlayer(player);
    }
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IAlleleRegistry(forestry.api.genetics.IAlleleRegistry) IBreedingTracker(forestry.api.genetics.IBreedingTracker)

Example 8 with IBreedingTracker

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

the class CommandSaveStats method executeSubCommand.

@Override
public void executeSubCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length > 1) {
        printHelp(sender);
        return;
    }
    String newLine = System.getProperty("line.separator");
    World world = sender.getEntityWorld();
    EntityPlayerMP player;
    if (args.length > 0) {
        player = CommandBase.getPlayer(server, sender, args[0]);
    } else {
        player = CommandBase.getPlayer(server, sender, sender.getName());
    }
    Collection<String> statistics = new ArrayList<>();
    String date = DateFormat.getInstance().format(new Date());
    statistics.add(Translator.translateToLocalFormatted(saveHelper.getUnlocalizedSaveStatsString(), player.getDisplayName(), date));
    statistics.add("");
    statistics.add(Translator.translateToLocalFormatted("for.chat.command.forestry.stats.save.mode", modeHelper.getModeName(world)));
    statistics.add("");
    IBreedingTracker tracker = saveHelper.getBreedingTracker(world, player.getGameProfile());
    saveHelper.addExtraInfo(statistics, tracker);
    Collection<IAlleleSpecies> species = saveHelper.getSpecies();
    String speciesCount = Translator.translateToLocal("for.gui.speciescount");
    String speciesCountLine = String.format("%s (%s):", speciesCount, species.size());
    statistics.add(speciesCountLine);
    statistics.add(StringUtil.line(speciesCountLine.length()));
    statistics.add(discoveredSymbol + ": " + Translator.translateToLocal("for.chat.command.forestry.stats.save.key.discovered"));
    statistics.add(blacklistedSymbol + ": " + Translator.translateToLocal("for.chat.command.forestry.stats.save.key.blacklisted"));
    statistics.add(notCountedSymbol + ": " + Translator.translateToLocal("for.chat.command.forestry.stats.save.key.notCounted"));
    statistics.add("");
    String header = generateSpeciesListHeader();
    statistics.add(header);
    statistics.add(StringUtil.line(header.length()));
    statistics.add("");
    for (IAlleleSpecies allele : species) {
        statistics.add(generateSpeciesListEntry(allele, tracker));
    }
    File file = new File(Proxies.common.getForestryRoot(), "config/" + Constants.MOD_ID + "/stats/" + player.getDisplayNameString() + '-' + saveHelper.getFileSuffix() + ".log");
    try {
        File folder = file.getParentFile();
        if (folder != null && !folder.exists()) {
            boolean success = file.getParentFile().mkdirs();
            if (!success) {
                CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1");
                return;
            }
        }
        if (!file.exists() && !file.createNewFile()) {
            CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1");
            return;
        }
        if (!file.canWrite()) {
            CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error2");
            return;
        }
        FileOutputStream fileout = new FileOutputStream(file);
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileout, "UTF-8"));
        writer.write("# " + Constants.MOD_ID + newLine + "# " + Constants.VERSION + newLine);
        for (String line : statistics) {
            writer.write(line + newLine);
        }
        writer.close();
    } catch (IOException ex) {
        CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error3");
        Log.error(Translator.translateToLocal("for.for.chat.command.forestry.stats.save.error3"), ex);
        return;
    }
    CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.saved", player.getDisplayName());
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) ArrayList(java.util.ArrayList) IOException(java.io.IOException) World(net.minecraft.world.World) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) FileOutputStream(java.io.FileOutputStream) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 9 with IBreedingTracker

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

the class GuiAlyzer method drawAnalyticsPageMutations.

public void drawAnalyticsPageMutations(IIndividual individual) {
    textLayout.startPage(COLUMN_0, COLUMN_1, COLUMN_2);
    textLayout.drawLine(Translator.translateToLocal("for.gui.beealyzer.mutations") + ":", COLUMN_0);
    textLayout.newLine();
    RenderHelper.enableGUIStandardItemLighting();
    IGenome genome = individual.getGenome();
    ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
    IAlleleSpecies species = genome.getPrimary();
    int columnWidth = 50;
    int x = 0;
    EntityPlayer player = Minecraft.getMinecraft().player;
    IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
    for (IMutation mutation : speciesRoot.getCombinations(species)) {
        if (breedingTracker.isDiscovered(mutation)) {
            drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
        } else {
            // Do not display secret undiscovered mutations.
            if (mutation.isSecret()) {
                continue;
            }
            drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
        }
        x += columnWidth;
        if (x >= columnWidth * 4) {
            x = 0;
            textLayout.newLine(16);
        }
    }
    textLayout.endPage();
}
Also used : IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IMutation(forestry.api.genetics.IMutation) IBreedingTracker(forestry.api.genetics.IBreedingTracker) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 10 with IBreedingTracker

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

the class ItemInventoryAlyzer method analyzeSpecimen.

private void analyzeSpecimen(ItemStack specimen) {
    if (specimen.isEmpty()) {
        return;
    }
    ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
    if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
        setInventorySlotContents(SLOT_SPECIMEN, convertedSpecimen);
        specimen = convertedSpecimen;
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
    // No individual, abort
    if (speciesRoot == null) {
        return;
    }
    IIndividual individual = speciesRoot.getMember(specimen);
    // Analyze if necessary
    if (individual != null && !individual.isAnalyzed()) {
        final boolean requiresEnergy = ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE));
        if (requiresEnergy) {
            // Requires energy
            if (!isAlyzingFuel(getStackInSlot(SLOT_ENERGY))) {
                return;
            }
        }
        if (individual.analyze()) {
            IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
            breedingTracker.registerSpecies(individual.getGenome().getPrimary());
            breedingTracker.registerSpecies(individual.getGenome().getSecondary());
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            individual.writeToNBT(nbttagcompound);
            specimen.setTagCompound(nbttagcompound);
            if (requiresEnergy) {
                // Decrease energy
                decrStackSize(SLOT_ENERGY, 1);
            }
        }
    }
    setInventorySlotContents(SLOT_ANALYZE_1, specimen);
    setInventorySlotContents(SLOT_SPECIMEN, ItemStack.EMPTY);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

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