Added a recipe load method to mod prefab

This commit is contained in:
DarkGuardsman 2013-10-20 17:10:04 -04:00
parent 0d87f91c70
commit 24257c0c99
3 changed files with 72 additions and 26 deletions

View file

@ -116,11 +116,6 @@ public class DarkMain extends ModPrefab
instance = this;
super.preInit(event);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new FluidHelper());
UniversalElectricity.initiate();
Compatibility.initiate();
NetworkRegistry.instance().registerGuiHandler(this, proxy);
proxy.preInit();
}
@ -129,9 +124,7 @@ public class DarkMain extends ModPrefab
@Override
public void init(FMLInitializationEvent event)
{
ExternalModHandler.init();
super.init(event);
ProcessorRecipes.parseOreNames();
if (CoreRecipeLoader.blockOre != null)
{
for (OreData data : OreData.values())
@ -169,9 +162,6 @@ public class DarkMain extends ModPrefab
public void postInit(FMLPostInitializationEvent event)
{
super.postInit(event);
//TODO load langs
recipeLoader.loadRecipes();
proxy.postInit();
}
@ -265,4 +255,14 @@ public class DarkMain extends ModPrefab
return "dark";
}
@Override
public void loadRecipes()
{
if (recipeLoader == null)
{
recipeLoader = new CoreRecipeLoader();
}
recipeLoader.loadRecipes();
}
}

View file

@ -11,6 +11,9 @@ import com.builtbroken.common.Triple;
import cpw.mods.fml.common.registry.GameRegistry;
/** Recipe system to make it easier to load recipes for a mod
*
* @author DarkGuardsman */
public abstract class RecipeLoader
{
protected static Object circuit;
@ -38,7 +41,7 @@ public abstract class RecipeLoader
motor = Block.pistonBase;
bronze = Item.ingotIron;
bronzePlate = Item.ingotGold;
/* Ore directory items load over teh vinalla ones if they are present */
/* Ore directory items load over the vinalla ones if they are present */
if (OreDictionary.getOres("basicCircuit").size() > 0)
{
circuit = "basicCircuit";
@ -74,11 +77,16 @@ public abstract class RecipeLoader
{
if (stack != null)
{
return new ItemStack(stack.itemID, amount, stack.getItemDamage());
ItemStack itemStack = stack.copy();
itemStack.stackSize = amount;
return itemStack;
}
return stack;
}
/** An easier to read recipe system for the basic minecraft recipes
*
* @author DarkGaurdsman */
public static class RecipeGrid
{
Object[] rl = new Object[9];
@ -86,11 +94,15 @@ public abstract class RecipeLoader
int width = 3;
int hight = 3;
/** @param stack - output item */
public RecipeGrid(Object stack)
{
out = stack;
}
/** @param stack - output item
* @param w - width of grid
* @param h - height of grid */
public RecipeGrid(Object stack, int w, int h)
{
this(stack);
@ -99,7 +111,7 @@ public abstract class RecipeLoader
/** 3x3 Crafting grid. Each Triple is a row. Input for the triples should be any of { Item,
* Block, ItemStack, String}
*
*
* @param one - top row
* @param two - middle row
* @param three - bottom row */
@ -113,7 +125,7 @@ public abstract class RecipeLoader
/** 2x2 Crafting grid. Each Pair is a row. Input for the pairs should be any of { Item,
* Block, ItemStack, String}
*
*
* @param one - top row
* @param two - middle row */
public RecipeGrid(Object stack, Pair one, Pair two)
@ -218,13 +230,14 @@ public abstract class RecipeLoader
for (int i = 0; i < r.length; i++)
{
if (this.rl[i] == null)
if (this.rl[i] == null || this.rl[i] instanceof String && ((String) this.rl[i]).isEmpty())
{
r[i] = " ";
this.rl[i] = "";
}
else if (this.rl[i] instanceof ItemStack)
{
//Automatically converts an itemstack to its orename so that recipes are more mod compatible
String s = OreDictionary.getOreName(OreDictionary.getOreID((ItemStack) this.rl[i]));
if (s != null)
{

View file

@ -1,15 +1,23 @@
package dark.core.prefab;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import org.modstats.Modstats;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.UniversalElectricity;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.Side;
import dark.api.ProcessorRecipes;
import dark.core.common.ExternalModHandler;
import dark.core.prefab.helpers.FluidHelper;
import dark.core.registration.ModObjectRegistry;
public abstract class ModPrefab
@ -41,7 +49,7 @@ public abstract class ModPrefab
{
int id = BLOCK_ID_PRE;
while (id > 255 && id < 4048)
while (id > 255 && id < (Block.blocksList.length - 1))
{
Block block = Block.blocksList[id];
if (block == null)
@ -54,26 +62,50 @@ public abstract class ModPrefab
return id;
}
/** Gets the next unused ID in the item list. Does not prevent config file issues after the file
* has been made */
public static int getNextItemId()
{
int id = BLOCK_ID_PRE;
while (id > 255 && id < (Item.itemsList.length - 1))
{
Item item = Item.itemsList[id];
if (item == null)
{
break;
}
id++;
}
BLOCK_ID_PRE = id + 1;
return id;
}
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
this.loadModMeta();
Modstats.instance().getReporter().registerMod(this);
ModObjectRegistry.masterBlockConfig.load();
this.registerObjects();
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new FluidHelper());
UniversalElectricity.initiate();
Compatibility.initiate();
}
@EventHandler
public void init(FMLInitializationEvent event)
{
ExternalModHandler.init();
ModObjectRegistry.masterBlockConfig.load();
this.registerObjects();
ModObjectRegistry.masterBlockConfig.save();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
ProcessorRecipes.parseOreNames();
this.loadRecipes();
}
public static void printSidedData(String data)
@ -82,12 +114,13 @@ public abstract class ModPrefab
System.out.println(" " + data);
}
/** Grabs a list of all the mods block Data used to register the block, tileEntities, and extra
* configs
*
* @return */
public abstract void registerObjects();
/** Loads the settings that tell what this mod is named, about, and other info to the user */
public abstract void loadModMeta();
/** Tells the mod to start registering its items and blocks */
public abstract void registerObjects();
/** Tells the mod to start registering its recipes */
public abstract void loadRecipes();
}