Removed item exporter service

This commit is contained in:
yueh
2020-06-07 15:54:38 +02:00
parent 6011b2dd49
commit 2dc2f90d5b
10 changed files with 0 additions and 927 deletions
@@ -1,41 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
/**
* Defines a concrete result type when using the {@link Checker#isEqual(Object)} from the {@link Checker} class.
*
* @author thatsIch
* @version rv3 - 25.09.2015
* @see Checker
* @since rv3 - 25.09.2015
*/
enum CheckType
{
/**
* If checking resulted in both objects being <b>equal</b>
*/
EQUAL,
/**
* If checking resulted in both objects being <b>unequal</b>
*/
UNEQUAL
}
@@ -1,45 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import javax.annotation.Nonnull;
/**
* Checks against a specific type with its own check type for clear outcome.
*
* The constructor will generally have a value which the checker will check against
*
* @author thatsIch
* @version rv3 - 01.09.2015
* @since rv3 - 01.09.2015
*/
interface Checker<T>
{
/**
* @param checkedAgainst the object it is checked against
*
* @return non null being either equal or unequal
*
* @since rv3 - 01.09.2015
*/
@Nonnull
CheckType isEqual( @Nonnull final T checkedAgainst );
}
@@ -1,82 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import javax.annotation.Nonnull;
/**
* @author thatsIch
* @version rv3 - 14.08.2015
* @since rv3 14.08.2015
*/
public interface ExportConfig
{
/**
* config switch to disable the exporting.
* if the recipes system is not used
* there is no reason to export them.
* Still can be useful for debugging purpose,
* thus not tying it to the recipe system directly.
*
* @return true if exporting is enabled
*/
boolean isExportingItemNamesEnabled();
/**
* config switch for using the digest cache.
*
* @return true if cache is enabled
*/
boolean isCacheEnabled();
/**
* config switch to always refresh the CSV. Might be useful to activate on debugging.
*
* @return true if force refresh is enabled
*/
boolean isForceRefreshEnabled();
/**
* config switch to export more information mostly used for debugging
*
* @return true if additional information are enabled
*/
boolean isAdditionalInformationEnabled();
/**
* Will get the cache from last session. Can be used to reduce I/O operations though containing itself calculation.
*
* @return a digest from the last calculation
*/
String getCache();
/**
* sets the cache for the next session to reduce calculation overhead
*
* @param digest new digest for the cache
*/
void setCache( @Nonnull String digest );
/**
* Will delegate the saving
*/
void save();
}
@@ -1,42 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
/**
* Defines the different modes which need to be distinguished upon exporting.
*
* using a different mode will result in a different export outcome.
*
* @author thatsIch
* @version rv3 - 23.09.2015
* @since rv3 - 23.09.2015
*/
enum ExportMode
{
/**
* Will provide general users with information required for recipe making
*/
MINIMAL,
/**
* Will provide advanced users with information with debugging functionality
*/
VERBOSE
}
@@ -1,130 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import appeng.core.AELog;
/**
* Main entry point for exporting the CSV file
*
* makes everything threadable
*
* @author thatsIch
* @version rv3 - 14.08.2015
* @since rv3 14.08.2015
*/
public class ExportProcess implements Runnable
{
private static final String FORCE_REFRESH_MESSAGE = "Force Refresh enabled. Will ignore cache and export CSV content.";
private static final String CACHE_ENABLED_MESSAGE = "Cache is enabled. Checking for new mod configurations.";
private static final String EQUAL_CONTENT_MESSAGE = "Same mod configuration was found. Not updating CSV content.";
private static final String UNEQUAL_CONTENT_MESSAGE = "New mod configuration was found. Commencing exporting.";
private static final String CACHE_DISABLED_MESSAGE = "Cache is disabled. Commencing exporting.";
private static final String EXPORT_START_MESSAGE = "Item Exporting ( started )";
private static final String EXPORT_END_MESSAGE = "Item Exporting ( ended after %s ms)";
@Nonnull
private final File exportDirectory;
@Nonnull
private final Checker<List<ModContainer>> modChecker;
@Nonnull
private final ExportConfig config;
/**
* @param exportDirectory directory where the final CSV file will be exported to
* @param config configuration to manipulate the export process
*/
public ExportProcess( @Nonnull final File exportDirectory, @Nonnull final ExportConfig config )
{
this.exportDirectory = Preconditions.checkNotNull( exportDirectory );
this.config = Preconditions.checkNotNull( config );
this.modChecker = new ModListChecker( config );
}
/**
* Will check and export if various config settings will lead to exporting the CSV file.
*/
@Override
public void run()
{
// no priority to this thread
Thread.yield();
// logic when to cancel the export process
if( this.config.isForceRefreshEnabled() )
{
AELog.info( FORCE_REFRESH_MESSAGE );
}
else
{
if( this.config.isCacheEnabled() )
{
AELog.info( CACHE_ENABLED_MESSAGE );
final Loader loader = Loader.instance();
final List<ModContainer> mods = loader.getActiveModList();
if( this.modChecker.isEqual( mods ) == CheckType.EQUAL )
{
AELog.info( EQUAL_CONTENT_MESSAGE );
return;
}
else
{
AELog.info( UNEQUAL_CONTENT_MESSAGE );
}
}
else
{
AELog.info( CACHE_DISABLED_MESSAGE );
}
}
AELog.info( EXPORT_START_MESSAGE );
final Stopwatch watch = Stopwatch.createStarted();
final IForgeRegistry<Item> itemRegistry = ForgeRegistries.ITEMS;
final ExportMode mode = this.config.isAdditionalInformationEnabled() ? ExportMode.VERBOSE : ExportMode.MINIMAL;
final Exporter exporter = new MinecraftItemCSVExporter( this.exportDirectory, itemRegistry, mode );
exporter.export();
AELog.info( EXPORT_END_MESSAGE, watch.elapsed( TimeUnit.MILLISECONDS ) );
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
/**
* General purpose interface to define an export operation with side effects
*
* @author thatsIch
* @version rv3 - 19.08.2015
* @since rv3 19.08.2015
*/
interface Exporter
{
/**
* Will export something defined by the Exporter with side effects
*/
void export();
}
@@ -1,133 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
/**
* Offers configuration switches for the user to change the export process
*
* @author thatsIch
* @version rv3 - 14.08.2015
* @since rv3 14.08.2015
*/
public final class ForgeExportConfig implements ExportConfig
{
private static final String GENERAL_CATEGORY = "general";
private static final String CACHE_CATEGORY = "cache";
private static final String EXPORT_ITEM_NAMES_KEY = "exportItemNames";
private static final boolean EXPORT_ITEM_NAMES_DEFAULT = true;
private static final String EXPORT_ITEM_NAMES_DESCRIPTION = "If true, all registered items will be exported containing the internal minecraft name and the localized name to actually find the item you are using. This also contains the item representation of the blocks, but are missing items, which are too much to display e.g. FMP.";
private static final String ENABLE_FORCE_REFRESH_KEY = "enableForceRefresh";
private static final boolean ENABLE_FORCE_REFRESH_DEFAULT = false;
private static final String ENABLE_FORCE_REFRESH_DESCRIPTION = "If true, the CSV exporting will always happen. This will not use the cache to reduce the computation.";
private static final String ENABLE_CACHE_KEY = "enableCache";
private static final boolean ENABLE_CACHE_DEFAULT = true;
private static final String ENABLE_CACHE_DESCRIPTION = "Caching can save processing time, if there are a lot of items.";
private static final String ENABLE_ADDITIONAL_INFO_KEY = "enableAdditionalInfo";
private static final boolean ENABLE_ADDITIONAL_INFO_DEFAULT = false;
private static final String ENABLE_ADDITIONAL_INFO_DESCRIPTION = "Will output more detailed information into the CSV like corresponding items";
private static final String DIGEST_KEY = "digest";
private static final String DIGEST_DEFAULT = "";
private static final String DIGEST_DESCRIPTION = "Digest of all the mods and versions to check if a re-export of the item names is required.";
private final boolean exportItemNamesEnabled;
private final boolean cacheEnabled;
private final boolean forceRefreshEnabled;
private final boolean additionalInformationEnabled;
private final String cache;
private final Configuration config;
/**
* Constructor using the configuration. Apparently there are some race conditions if constructing configurations on
* multiple file accesses
*
* @param config to be wrapped configuration.
*/
public ForgeExportConfig( @Nonnull final Configuration config )
{
this.config = Preconditions.checkNotNull( config );
this.exportItemNamesEnabled = this.config.getBoolean( EXPORT_ITEM_NAMES_KEY, GENERAL_CATEGORY, EXPORT_ITEM_NAMES_DEFAULT,
EXPORT_ITEM_NAMES_DESCRIPTION );
this.cacheEnabled = this.config.getBoolean( ENABLE_CACHE_KEY, CACHE_CATEGORY, ENABLE_CACHE_DEFAULT, ENABLE_CACHE_DESCRIPTION );
this.additionalInformationEnabled = this.config.getBoolean( ENABLE_ADDITIONAL_INFO_KEY, GENERAL_CATEGORY, ENABLE_ADDITIONAL_INFO_DEFAULT,
ENABLE_ADDITIONAL_INFO_DESCRIPTION );
this.cache = this.config.getString( DIGEST_KEY, CACHE_CATEGORY, DIGEST_DEFAULT, DIGEST_DESCRIPTION );
this.forceRefreshEnabled = this.config.getBoolean( ENABLE_FORCE_REFRESH_KEY, GENERAL_CATEGORY, ENABLE_FORCE_REFRESH_DEFAULT,
ENABLE_FORCE_REFRESH_DESCRIPTION );
}
@Override
public boolean isExportingItemNamesEnabled()
{
return this.exportItemNamesEnabled;
}
@Override
public boolean isCacheEnabled()
{
return this.cacheEnabled;
}
@Override
public boolean isForceRefreshEnabled()
{
return this.forceRefreshEnabled;
}
@Override
public boolean isAdditionalInformationEnabled()
{
return this.additionalInformationEnabled;
}
@Override
public String getCache()
{
return this.cache;
}
@Override
public void setCache( @Nonnull final String digest )
{
final Property digestProperty = this.config.get( CACHE_CATEGORY, DIGEST_KEY, DIGEST_DEFAULT );
digestProperty.set( digest );
this.config.save();
}
@Override
public void save()
{
this.config.save();
}
}
@@ -1,291 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import appeng.core.AELog;
/**
* handles the exporting including processing, transformation and persisting the information
*
* @author thatsIch
* @version rv3 - 14.08.2015
* @since rv3 14.08.2015
*/
final class MinecraftItemCSVExporter implements Exporter
{
private static final String ITEM_CSV_FILE_NAME = "items.csv";
private static final String MINIMAL_HEADER = "Mod:Item:MetaData, Localized Name";
private static final String VERBOSE_HEADER = MINIMAL_HEADER + ", Unlocalized Name, Is Block?, Class Name";
private static final String EXPORT_SUCCESSFUL_MESSAGE = "Exported successfully %d items into %s";
private static final String EXPORT_UNSUCCESSFUL_MESSAGE = "Exporting was unsuccessful.";
@Nonnull
private final File exportDirectory;
@Nonnull
private final IForgeRegistry<Item> itemRegistry;
@Nonnull
private final ExportMode mode;
/**
* @param exportDirectory directory of the resulting export file. Non-null required.
* @param itemRegistry the registry with minecraft items. Needs to be populated at that time, thus the exporting can
* only happen in init (pre-init is the
* phase when all items are determined)
* @param mode mode in which the export should be operated. Resulting CSV will change depending on this.
*/
MinecraftItemCSVExporter( @Nonnull final File exportDirectory, @Nonnull final IForgeRegistry<Item> itemRegistry, @Nonnull final ExportMode mode )
{
this.exportDirectory = Preconditions.checkNotNull( exportDirectory );
Preconditions.checkArgument( !exportDirectory.isFile() );
this.itemRegistry = Preconditions.checkNotNull( itemRegistry );
this.mode = Preconditions.checkNotNull( mode );
}
@Override
public void export()
{
final Iterable<Item> items = this.itemRegistry;
final List<Item> itemList = Lists.newArrayList( items );
final List<String> lines = Lists.transform( itemList, new ItemRowExtractFunction( this.itemRegistry, this.mode ) );
final Joiner newLineJoiner = Joiner.on( '\n' );
final Joiner newLineJoinerIgnoringNull = newLineJoiner.skipNulls();
final String joined = newLineJoinerIgnoringNull.join( lines );
final File file = new File( this.exportDirectory, ITEM_CSV_FILE_NAME );
try( final Writer writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ), Charset.forName( "UTF-8" ) ) ) )
{
FileUtils.forceMkdir( this.exportDirectory );
final String header = this.mode == ExportMode.MINIMAL ? MINIMAL_HEADER : VERBOSE_HEADER;
writer.write( header );
writer.write( "\n" );
writer.write( joined );
writer.flush();
AELog.info( EXPORT_SUCCESSFUL_MESSAGE, lines.size(), ITEM_CSV_FILE_NAME );
}
catch( final IOException e )
{
AELog.warn( EXPORT_UNSUCCESSFUL_MESSAGE );
AELog.debug( e );
}
}
/**
* Extracts item name with meta and the display name
*/
private static final class TypeExtractFunction implements Function<ItemStack, String>
{
private static final String EXTRACTING_NULL_MESSAGE = "extracting type null";
private static final String EXTRACTING_ITEM_MESSAGE = "extracting type %s:%d";
@Nonnull
private final String itemName;
@Nonnull
private final ExportMode mode;
private TypeExtractFunction( @Nonnull final String itemName, @Nonnull final ExportMode mode )
{
this.itemName = Preconditions.checkNotNull( itemName );
Preconditions.checkArgument( !itemName.isEmpty() );
this.mode = Preconditions.checkNotNull( mode );
}
@Nullable
@Override
public String apply( @Nullable final ItemStack input )
{
if( input == null )
{
AELog.debug( EXTRACTING_NULL_MESSAGE );
return null;
}
else
{
AELog.debug( EXTRACTING_ITEM_MESSAGE, input.getDisplayName(), input.getItemDamage() );
}
final List<String> joinedBlockAttributes = Lists.newArrayListWithCapacity( 5 );
final int meta = input.getItemDamage();
final String metaName = this.itemName + ':' + meta;
final String localization = input.getDisplayName();
joinedBlockAttributes.add( metaName );
joinedBlockAttributes.add( localization );
if( this.mode == ExportMode.VERBOSE )
{
final Item item = input.getItem();
final String unlocalizedItem = input.getTranslationKey();
final Block block = Block.getBlockFromItem( item );
final boolean isBlock = block != Blocks.AIR && !block.equals( Blocks.AIR );
final Class<? extends ItemStack> stackClass = input.getClass();
final String stackClassName = stackClass.getName();
joinedBlockAttributes.add( unlocalizedItem );
joinedBlockAttributes.add( Boolean.toString( isBlock ) );
joinedBlockAttributes.add( stackClassName );
}
final Joiner csvJoiner = Joiner.on( ", " );
final Joiner csvJoinerIgnoringNulls = csvJoiner.skipNulls();
return csvJoinerIgnoringNulls.join( joinedBlockAttributes );
}
}
/**
* transforms an item into a row representation of the CSV file
*/
private static final class ItemRowExtractFunction implements Function<Item, String>
{
/**
* this extension is required to apply the {@link I18n}
*/
private static final String LOCALIZATION_NAME_EXTENSION = ".name";
private static final String EXPORTING_NOTHING_MESSAGE = "Exporting nothing";
private static final String EXPORTING_SUBTYPES_MESSAGE = "Exporting input %s with subtypes: %b";
private static final String EXPORTING_SUBTYPES_FAILED_MESSAGE = "Could not export subtypes of: %s";
@Nonnull
private final IForgeRegistry<Item> itemRegistry;
@Nonnull
private final ExportMode mode;
/**
* @param itemRegistry used to retrieve the name of the item
* @param mode extracts more or less information from item depending on mode
*/
ItemRowExtractFunction( @Nonnull final IForgeRegistry<Item> itemRegistry, @Nonnull final ExportMode mode )
{
this.itemRegistry = Preconditions.checkNotNull( itemRegistry );
this.mode = Preconditions.checkNotNull( mode );
}
@Nullable
@Override
public String apply( @Nullable final Item input )
{
if( input == null )
{
AELog.debug( EXPORTING_NOTHING_MESSAGE );
return null;
}
else
{
AELog.debug( EXPORTING_SUBTYPES_MESSAGE, input.getTranslationKey(), input.getHasSubtypes() );
}
final String itemName = ForgeRegistries.ITEMS.getKey( input ).toString();
final boolean hasSubtypes = input.getHasSubtypes();
if( hasSubtypes )
{
final CreativeTabs creativeTab = input.getCreativeTab();
final NonNullList<ItemStack> stacks = NonNullList.create();
// modifies the stacks list and adds the different sub types to it
try
{
input.getSubItems( creativeTab, stacks );
}
catch( final Exception ignored )
{
AELog.warn( EXPORTING_SUBTYPES_FAILED_MESSAGE, input.getTranslationKey() );
AELog.debug( ignored );
// ignore if mods do bullshit in their code
return null;
}
// list can be empty, no clue why
if( stacks.isEmpty() )
{
return null;
}
final Joiner newLineJoiner = Joiner.on( '\n' );
final Joiner typeJoiner = newLineJoiner.skipNulls();
final List<String> transformedTypes = Lists.transform( stacks, new TypeExtractFunction( itemName, this.mode ) );
return typeJoiner.join( transformedTypes );
}
final List<String> joinedBlockAttributes = Lists.newArrayListWithCapacity( 5 );
final String unlocalizedItem = input.getTranslationKey();
final String localization = I18n.translateToLocal( unlocalizedItem + LOCALIZATION_NAME_EXTENSION );
joinedBlockAttributes.add( itemName );
joinedBlockAttributes.add( localization );
if( this.mode == ExportMode.VERBOSE )
{
final Block block = Block.getBlockFromItem( input );
final boolean isBlock = block != Blocks.AIR && !block.equals( Blocks.AIR );
final Class<? extends Item> itemClass = input.getClass();
final String itemClassName = itemClass.getName();
joinedBlockAttributes.add( unlocalizedItem );
joinedBlockAttributes.add( Boolean.toString( isBlock ) );
joinedBlockAttributes.add( itemClassName );
}
final Joiner csvJoiner = Joiner.on( ", " );
final Joiner csvJoinerIgnoringNulls = csvJoiner.skipNulls();
return csvJoinerIgnoringNulls.join( joinedBlockAttributes );
}
}
}
@@ -1,95 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.export;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import org.apache.commons.codec.digest.DigestUtils;
import net.minecraftforge.fml.commons.ModContainer;
/**
* Checks the cached digest against the current mods including their versions.
* Use the config to manipulate the process
*
* @author thatsIch
* @version rv3 - 01.09.2015
* @since rv3 - 01.09.2015
*/
final class ModListChecker implements Checker<List<ModContainer>>
{
private final String configHashValue;
@Nonnull
private final ExportConfig config;
/**
* @param config uses the config to retrieve the old hash of the mod list
*/
ModListChecker( @Nonnull final ExportConfig config )
{
this.config = Preconditions.checkNotNull( config );
this.configHashValue = Preconditions.checkNotNull( config.getCache() );
}
/**
* Compiles a list of all mods and their versions to a digest which is updated, if it differs from the config. This
* is used to elevate the need to export
* the csv once again, if no change was detected.
*
* @param modContainers all mods and their versions to check if a difference exists between the current instance and
* the previous instance
*
* @return CheckType.EQUAL if no change was detected
*/
@Nonnull
@Override
public CheckType isEqual( @Nonnull final List<ModContainer> modContainers )
{
Preconditions.checkNotNull( modContainers );
final StringBuilder builder = new StringBuilder();
for( final ModContainer container : modContainers )
{
builder.append( container.getModId() );
builder.append( container.getVersion() );
}
final String allModsAndVersions = builder.toString();
final String hex = DigestUtils.md5Hex( allModsAndVersions );
if( hex.equals( this.configHashValue ) )
{
return CheckType.EQUAL;
}
else
{
this.config.setCache( hex );
return CheckType.UNEQUAL;
}
}
}
@@ -1,33 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
/**
* the export package is to export all the required information for recipes into a convenient CSV file
* often names are difficult to acquire without access to the internal names.
*
* To save from rescanning every start-up it can save a list of mods and their version
* and if only something changed, it requires to update the CSV.
*
* There is no explicit check if it was manually tempered
*
* @author thatsIch
* @version rv3 - 14.08.2015
* @since rv3 14.08.2015
*/
package appeng.services.export;