Fix NEI Plugin to work with new Recipe Setup.

Added Config option to not show colored cables in recipes.
Fortify Recipe System vs OreDicionary Late entries.
This commit is contained in:
AlgorithmX2 2014-07-25 19:31:12 -05:00
parent 31cb594f4d
commit 99f15f36b7
9 changed files with 132 additions and 47 deletions

View file

@ -114,6 +114,8 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
public int colorapplicator_battery = 20000;
public int staff_battery = 8000;
public boolean disableColoredCableRecipesInNEI = true;
public boolean updateable = false;
final private File myPath;
@ -128,6 +130,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
private void clientSync()
{
disableColoredCableRecipesInNEI = get( "Client", "disableColoredCableRecipesInNEI", true ).getBoolean( true );
enableEffects = get( "Client", "enableEffects", true ).getBoolean( true );
useLargeFonts = get( "Client", "useTerminalUseLargeFont", false ).getBoolean( false );
@ -152,6 +155,11 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
}
public boolean disableColoredCableRecipesInNEI()
{
return disableColoredCableRecipesInNEI;
}
public String getFilePath()
{
return myPath.toString();

View file

@ -140,7 +140,6 @@ import appeng.parts.PartPlacement;
import appeng.recipes.AEItemResolver;
import appeng.recipes.RecipeHandler;
import appeng.recipes.game.FacadeRecipe;
import appeng.recipes.game.IRecipeBakeable;
import appeng.recipes.game.ShapedRecipe;
import appeng.recipes.game.ShapelessRecipe;
import appeng.recipes.handlers.Crusher;
@ -195,7 +194,6 @@ public class Registration
IRecipeHandlerRegistry recipeRegistery = AEApi.instance().registries().recipes();
recipeRegistery.addNewSubItemResolver( new AEItemResolver() );
recipeRegistery.addNewCraftHandler( "hccrusher", HCCrusher.class );
recipeRegistery.addNewCraftHandler( "mekcrusher", MekCrusher.class );
recipeRegistery.addNewCraftHandler( "mekechamber", MekEnrichment.class );
@ -693,26 +691,11 @@ public class Registration
* Whitelist AE2
*/
mr.whiteListTileEntity( AEBaseTile.class );
bakeRecipes();
}
private void bakeRecipes()
{
for ( Object o : CraftingManager.getInstance().getRecipeList() )
{
if ( o instanceof IRecipeBakeable )
{
try
{
( (IRecipeBakeable) o ).bake();
}
catch (Throwable e)
{
AELog.error( e );
}
}
}
/**
* initial recipe bake, if ore dictionary changes after this it re-bakes.
*/
OreDictionaryHandler.instance.bakeRecipes();
}
private void registerSpatial(boolean force)

View file

@ -10,7 +10,12 @@ import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
import appeng.core.AEConfig;
import appeng.recipes.game.ShapedRecipe;
import appeng.util.Platform;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@ -87,7 +92,7 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
if ( (irecipe instanceof ShapedRecipe) )
{
CachedShapedRecipe recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe );
if ( recipe.contains( recipe.ingredients, ingredient.getItem() ) )
{
recipe.computeVisuals();
@ -123,11 +128,11 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
IRecipeOverlayRenderer renderer = super.getOverlayRenderer( gui, recipe );
if ( renderer != null )
return renderer;
IStackPositioner positioner = RecipeInfo.getStackPositioner( gui, "crafting2x2" );
if ( positioner == null )
return null;
return new DefaultOverlayRenderer( getIngredientStacks( recipe ), positioner );
}
@ -137,7 +142,7 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
IOverlayHandler handler = super.getOverlayHandler( gui, recipe );
if ( handler != null )
return handler;
return RecipeInfo.getOverlayHandler( gui, "crafting2x2" );
}
@ -165,15 +170,31 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
public void setIngredients(int width, int height, Object[] items)
{
boolean useSingleItems = AEConfig.instance.disableColoredCableRecipesInNEI();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
if ( items[(y * width + x)] != null )
{
PositionedStack stack = new PositionedStack( items[(y * width + x)], 25 + x * 18, 6 + y * 18, false );
stack.setMaxSize( 1 );
this.ingredients.add( stack );
IIngredient ing = (IIngredient) items[(y * width + x)];
try
{
ItemStack[] is = ing.getItemStackSet();
PositionedStack stack = new PositionedStack( useSingleItems ? Platform.findPrefered( is ) : is, 25 + x * 18, 6 + y * 18, false );
stack.setMaxSize( 1 );
this.ingredients.add( stack );
}
catch (RegistrationError e)
{
}
catch (MissingIngredientError e)
{
}
}
}
}

View file

@ -10,7 +10,12 @@ import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import appeng.api.exceptions.MissingIngredientError;
import appeng.api.exceptions.RegistrationError;
import appeng.api.recipes.IIngredient;
import appeng.core.AEConfig;
import appeng.recipes.game.ShapelessRecipe;
import appeng.util.Platform;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@ -87,7 +92,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
if ( (irecipe instanceof ShapelessRecipe) )
{
CachedShapelessRecipe recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe );
if ( recipe.contains( recipe.ingredients, ingredient.getItem() ) )
{
recipe.computeVisuals();
@ -123,11 +128,11 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
IRecipeOverlayRenderer renderer = super.getOverlayRenderer( gui, recipe );
if ( renderer != null )
return renderer;
IStackPositioner positioner = RecipeInfo.getStackPositioner( gui, "crafting2x2" );
if ( positioner == null )
return null;
return new DefaultOverlayRenderer( getIngredientStacks( recipe ), positioner );
}
@ -137,7 +142,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
IOverlayHandler handler = super.getOverlayHandler( gui, recipe );
if ( handler != null )
return handler;
return RecipeInfo.getOverlayHandler( gui, "crafting2x2" );
}
@ -165,15 +170,32 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
public void setIngredients(Object[] items)
{
boolean useSingleItems = AEConfig.instance.disableColoredCableRecipesInNEI();
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
if ( items.length > (y * 3 + x) )
{
PositionedStack stack = new PositionedStack( items[(y * 3 + x)], 25 + x * 18, 6 + y * 18, false );
stack.setMaxSize( 1 );
this.ingredients.add( stack );
IIngredient ing = (IIngredient) items[(y * 3 + x)];
try
{
ItemStack[] is = ing.getItemStackSet();
PositionedStack stack = new PositionedStack( useSingleItems ? Platform.findPrefered( is ) : ing.getItemStackSet(), 25 + x * 18,
6 + y * 18, false );
stack.setMaxSize( 1 );
this.ingredients.add( stack );
}
catch (RegistrationError e)
{
}
catch (MissingIngredientError e)
{
}
}
}
}
@ -195,7 +217,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
{
for (PositionedStack p : this.ingredients)
p.generatePermutations();
this.result.generatePermutations();
}
}

View file

@ -60,7 +60,7 @@ public class GroupIngredient implements IIngredient
{
if ( baked != null )
return baked;
if ( isInside )
return new ItemStack[0];
@ -114,6 +114,7 @@ public class GroupIngredient implements IIngredient
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}

View file

@ -27,7 +27,7 @@ public class Ingredient implements IIngredient
final public int qty;
ItemStack[] baked;
public Ingredient(RecipeHandler handler, String input, int qty) throws RecipeError, MissedIngredientSet {
// works no matter wat!
@ -105,8 +105,8 @@ public class Ingredient implements IIngredient
}
else
throw new RecipeError( input + " : Needs at least Namespace and Name." );
handler.data.knownItem.add( toString() );
handler.data.knownItem.add( toString() );
}
@Override
@ -163,7 +163,7 @@ public class Ingredient implements IIngredient
{
if ( baked != null )
return baked;
if ( nameSpace.equalsIgnoreCase( "oreDictionary" ) )
{
List<ItemStack> ores = OreDictionary.getOres( itemName );
@ -219,7 +219,8 @@ public class Ingredient implements IIngredient
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}
}

View file

@ -17,7 +17,7 @@ public class IngredientSet implements IIngredient
final String name;
final List<ItemStack> items;
ItemStack[] baked;
public IngredientSet(ResolverResultSet rr) {
name = rr.name;
items = rr.results;
@ -47,7 +47,7 @@ public class IngredientSet implements IIngredient
{
if ( baked != null )
return baked;
if ( isInside )
return new ItemStack[0];
@ -79,11 +79,12 @@ public class IngredientSet implements IIngredient
{
return false;
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
baked = null;
baked = getItemStackSet();
}
}

View file

@ -4,7 +4,10 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.oredict.OreDictionary;
import appeng.core.AELog;
import appeng.recipes.game.IRecipeBakeable;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class OreDictionaryHandler
@ -14,6 +17,8 @@ public class OreDictionaryHandler
private List<IOreListener> ol = new ArrayList<IOreListener>();
private boolean enableRebaking = false;
/**
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
*
@ -33,6 +38,9 @@ public class OreDictionaryHandler
for (IOreListener v : ol)
v.oreRegistered( event.Name, event.Ore );
}
if ( enableRebaking )
bakeRecipes();
}
/**
@ -58,4 +66,24 @@ public class OreDictionaryHandler
}
}
public void bakeRecipes()
{
enableRebaking = true;
for (Object o : CraftingManager.getInstance().getRecipeList())
{
if ( o instanceof IRecipeBakeable )
{
try
{
((IRecipeBakeable) o).bake();
}
catch (Throwable e)
{
AELog.error( e );
}
}
}
}
}

View file

@ -80,6 +80,7 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IAETagCompound;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEColor;
import appeng.api.util.AEItemDefinition;
import appeng.core.AEConfig;
import appeng.core.AELog;
@ -1412,7 +1413,7 @@ public class Platform
if ( myFluids != null )
{
for (IAEFluidStack is : myFluids.getAvailableItems( AEApi.instance().storage().createFluidList() ) )
for (IAEFluidStack is : myFluids.getAvailableItems( AEApi.instance().storage().createFluidList() ))
{
gs.postAlterationOfStoredItems( StorageChannel.FLUIDS, is, src );
}
@ -1692,4 +1693,23 @@ public class Platform
return false;
}
public static Object findPrefered(ItemStack[] is)
{
for (ItemStack stack : is)
{
if ( AEApi.instance().parts().partCableGlass.sameAs( AEColor.Transparent, stack ) )
return stack;
if ( AEApi.instance().parts().partCableCovered.sameAs( AEColor.Transparent, stack ) )
return stack;
if ( AEApi.instance().parts().partCableSmart.sameAs( AEColor.Transparent, stack ) )
return stack;
if ( AEApi.instance().parts().partCableDense.sameAs( AEColor.Transparent, stack ) )
return stack;
}
return is;
}
}