2013-12-27 23:59:59 +01:00
|
|
|
package appeng.recipes.ores;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-07-26 02:31:12 +02:00
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-07-26 02:31:12 +02:00
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.recipes.game.IRecipeBakeable;
|
2014-02-09 02:34:52 +01:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class OreDictionaryHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public static final OreDictionaryHandler instance = new OreDictionaryHandler();
|
|
|
|
|
2014-02-20 00:33:36 +01:00
|
|
|
private List<IOreListener> ol = new ArrayList<IOreListener>();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-07-26 02:31:12 +02:00
|
|
|
private boolean enableRebaking = false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/**
|
|
|
|
* Just limit what items are sent to the final listeners, I got sick of strange items showing up...
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private boolean shouldCare(String name)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
@SubscribeEvent
|
2013-12-27 23:59:59 +01:00
|
|
|
public void onOreDictionaryRegister(OreDictionary.OreRegisterEvent event)
|
|
|
|
{
|
2014-07-29 03:57:46 +02:00
|
|
|
if ( event.Name == null || event.Ore == null )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( shouldCare( event.Name ) )
|
|
|
|
{
|
|
|
|
for (IOreListener v : ol)
|
|
|
|
v.oreRegistered( event.Name, event.Ore );
|
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
|
|
|
if ( enableRebaking )
|
|
|
|
bakeRecipes();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at
|
|
|
|
* that point.
|
|
|
|
*
|
|
|
|
* @param n
|
|
|
|
*/
|
|
|
|
public void observe(IOreListener n)
|
|
|
|
{
|
|
|
|
ol.add( n );
|
|
|
|
|
|
|
|
// notify the listener of any ore already in existance.
|
|
|
|
for (String name : OreDictionary.getOreNames())
|
|
|
|
{
|
2014-07-29 03:57:46 +02:00
|
|
|
if ( name != null && shouldCare( name ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
for (ItemStack item : OreDictionary.getOres( name ))
|
|
|
|
{
|
2014-07-29 03:57:46 +02:00
|
|
|
if ( item != null )
|
|
|
|
n.oreRegistered( name, item );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 02:31:12 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|