diff --git a/build.gradle b/build.gradle index 47f5148..25ef375 100644 --- a/build.gradle +++ b/build.gradle @@ -51,10 +51,11 @@ jar { from('src/main/java') { include 'lang/**' - } - from('./') { + include '**/*.dat' + } + from('./') { include 'LICENSE' - } + } } processResources diff --git a/src/main/java/craftedMods/lotr/recipes/api/recipeHandlers/AbstractAlloyForgeRecipeHandler.java b/src/main/java/craftedMods/lotr/recipes/api/recipeHandlers/AbstractAlloyForgeRecipeHandler.java index 3a50196..384dba3 100644 --- a/src/main/java/craftedMods/lotr/recipes/api/recipeHandlers/AbstractAlloyForgeRecipeHandler.java +++ b/src/main/java/craftedMods/lotr/recipes/api/recipeHandlers/AbstractAlloyForgeRecipeHandler.java @@ -18,6 +18,8 @@ import java.util.*; +import org.apache.logging.log4j.Logger; + import craftedMods.lotr.recipes.api.recipeHandlers.AbstractAlloyForgeRecipeHandler.AlloyForgeRecipe; import craftedMods.lotr.recipes.api.utils.LOTRRecipeHandlerUtils; import craftedMods.recipes.api.*; @@ -36,6 +38,7 @@ public abstract class AbstractAlloyForgeRecipeHandler extends AbstractRecipeHand protected final AlloyForgeAccess alloyForgeDummy; protected boolean wasCacheLoaded = false; + protected boolean useHardcodedRecipes = false; private final AlloyForgeRecipeHandlerRenderer renderer = new AlloyForgeRecipeHandlerRenderer (); private final AlloyForgeRecipeHandlerCacheManager cacheManager = new AlloyForgeRecipeHandlerCacheManager (this); @@ -47,6 +50,40 @@ protected AbstractAlloyForgeRecipeHandler (String unlocalizedName, AlloyForgeAcc this.alloyForgeDummy = alloyForgeDummy; } + public void onPreLoad (RecipeHandlerConfiguration config, Logger logger) + { + super.onPreLoad (config, logger); + + this.useHardcodedRecipes = config.getBoolean ("Use hardcoded recipes", false, + "Enable this when you experience performance issues caused by this mod. This fixes that issue at the cost of lost compatibility - eventually NEI doesn't show all recipes this device supports."); + } + + public void onPostLoad (Collection staticRecipes) + { + super.onPostLoad (staticRecipes); + + if (this.useHardcodedRecipes) + { + Collection hardcodedRecipes = getHardcodedRecipes (); + + if (hardcodedRecipes.size () == 0) + { + this.logger.warn ( + "This recipe handler was configured to load hardcoded recipes, but there weren't any - thus this handler shows no recipes."); + } + else + { + this.logger.debug ("Found " + hardcodedRecipes.size () + " hardcoded recipes that will be used"); + } + getStaticRecipes ().addAll (getHardcodedRecipes ()); + } + } + + protected Collection getHardcodedRecipes () + { + return Arrays.asList (); + } + @Override public String getDisplayName () { @@ -89,7 +126,7 @@ public List getSlotsForRecipeItems (AlloyForgeRecipe recipe, Enu @Override public int getComplicatedStaticRecipeDepth () { - return wasCacheLoaded ? 0 : 2; + return (this.useHardcodedRecipes || this.wasCacheLoaded) ? 0 : 2; } @Override @@ -142,6 +179,11 @@ public AlloyForgeRecipeHandlerCacheManager (AbstractAlloyForgeRecipeHandler hand super (handler); } + public boolean isCacheEnabled () + { + return ! ((AbstractAlloyForgeRecipeHandler) this.handler).useHardcodedRecipes; + } + @Override @SuppressWarnings("unchecked") public Collection readRecipesFromCache (NBTTagCompound cacheHeaderTag, diff --git a/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRAlloyForgeRecipeHandler.java b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRAlloyForgeRecipeHandler.java index 969ce20..66ce9ef 100644 --- a/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRAlloyForgeRecipeHandler.java +++ b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRAlloyForgeRecipeHandler.java @@ -16,9 +16,12 @@ ******************************************************************************/ package craftedMods.lotr.recipes.internal.recipeHandlers; +import java.util.*; + import craftedMods.lotr.recipes.api.recipeHandlers.AbstractAlloyForgeRecipeHandler; import lotr.common.tileentity.*; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.*; public class LOTRAlloyForgeRecipeHandler extends AbstractAlloyForgeRecipeHandler { @@ -28,6 +31,41 @@ public LOTRAlloyForgeRecipeHandler (String unlocalizedName, AlloyForgeAccess all super ("lotr.alloyForge." + unlocalizedName, alloyForgeDummy); } + @SuppressWarnings("unchecked") + protected Collection getHardcodedRecipes () + { + Collection recipes = new ArrayList<>(); + + try + { + NBTTagCompound data = CompressedStreamTools.readCompressed (getClass ().getResourceAsStream ( + "/craftedMods/lotr/recipes/internal/recipeHandlers/hardcoded_alloy_forge_recipes.dat")); + + if (data.hasKey (getUnlocalizedName ())) + { + + NBTTagCompound recipesTag = data.getCompoundTag (getUnlocalizedName ()).getCompoundTag ("content"); + + for (String key : (Collection) recipesTag.func_150296_c ()) + { + NBTTagCompound recipeTag = recipesTag.getCompoundTag (key); + AbstractAlloyForgeRecipeHandler.AlloyForgeRecipe recipe = AbstractAlloyForgeRecipeHandler.AlloyForgeRecipe + .readRecipeFromNBT (recipeTag); + if (recipe != null) + { + recipes.add (recipe); + } + } + } + } + catch (Exception e) + { + this.logger.error ("Couldn't load the hardcoded recipes for this handler", e); + } + + return recipes; + } + @Override public int getDefaultOrder () { diff --git a/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/hardcoded_alloy_forge_recipes.dat b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/hardcoded_alloy_forge_recipes.dat new file mode 100644 index 0000000..ed17475 Binary files /dev/null and b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/hardcoded_alloy_forge_recipes.dat differ diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index e090b80..baa776b 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -5,7 +5,8 @@ Made by 'Crafted_Mods' or 'The_Ranger_Malvegil' + Updated to v36.3 of the LOTR Mod + Added support for the Bree crafting table and traders * Moved some "Show all recipes" buttons, so they don't interfere with the pouch button -+ The LOTR coin coint indicator is now displayed on the left side instead of the right ++ The LOTR coin count indicator is now displayed on the left side instead of the right ++ Added a configuration option for every alloy forge to use hardcoded recipes, which improves startup performance for the cost of compatibility #2.1.0-ALPHA: + Updated to neiRecipeHandlers-1.1.0-BETA