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));
}
}
}
}
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);
}
}
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());
}
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();
}
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);
}
Aggregations