Skip to content

Commit

Permalink
Added support for hardcoded alloy forge recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftedMods committed Jun 23, 2020
1 parent 50977fd commit 2d73e80
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ jar {

from('src/main/java') {
include 'lang/**'
}
from('./') {
include '**/*.dat'
}
from('./') {
include 'LICENSE'
}
}
}

processResources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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);
Expand All @@ -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<AlloyForgeRecipe> staticRecipes)
{
super.onPostLoad (staticRecipes);

if (this.useHardcodedRecipes)
{
Collection<AlloyForgeRecipe> 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<AlloyForgeRecipe> getHardcodedRecipes ()
{
return Arrays.asList ();
}

@Override
public String getDisplayName ()
{
Expand Down Expand Up @@ -89,7 +126,7 @@ public List<RecipeItemSlot> getSlotsForRecipeItems (AlloyForgeRecipe recipe, Enu
@Override
public int getComplicatedStaticRecipeDepth ()
{
return wasCacheLoaded ? 0 : 2;
return (this.useHardcodedRecipes || this.wasCacheLoaded) ? 0 : 2;
}

@Override
Expand Down Expand Up @@ -142,6 +179,11 @@ public AlloyForgeRecipeHandlerCacheManager (AbstractAlloyForgeRecipeHandler hand
super (handler);
}

public boolean isCacheEnabled ()
{
return ! ((AbstractAlloyForgeRecipeHandler) this.handler).useHardcodedRecipes;
}

@Override
@SuppressWarnings("unchecked")
public Collection<AlloyForgeRecipe> readRecipesFromCache (NBTTagCompound cacheHeaderTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -28,6 +31,41 @@ public LOTRAlloyForgeRecipeHandler (String unlocalizedName, AlloyForgeAccess all
super ("lotr.alloyForge." + unlocalizedName, alloyForgeDummy);
}

@SuppressWarnings("unchecked")
protected Collection<AbstractAlloyForgeRecipeHandler.AlloyForgeRecipe> getHardcodedRecipes ()
{
Collection<AlloyForgeRecipe> 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<String>) 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 ()
{
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d73e80

Please sign in to comment.