Search in sources :

Example 6 with IJsonGenObject

use of com.builtbroken.mc.lib.json.imp.IJsonGenObject in project Engine by VoltzEngine-Project.

the class JsonContentLoader method process.

/**
 * Called to process a json element entry into a
 * generated object
 *
 * @param key     - json processor key
 * @param element - data
 * @return true if it was processed and added to the generated object list
 */
public boolean process(String key, JsonElement element) {
    final JsonProcessor processor = processors.get(key);
    if (processor != null) {
        if (processor.canProcess(key, element)) {
            IJsonGenObject data = processor.process(element);
            data.register();
            if (data instanceof IRegistryInit) {
                ((IRegistryInit) data).onRegistered();
            }
            return generatedObjects.add(data);
        } else {
        // TODO add error handling
        }
    }
    return false;
}
Also used : IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) JsonProcessor(com.builtbroken.mc.lib.json.processors.JsonProcessor) IRegistryInit(com.builtbroken.mc.core.registry.implement.IRegistryInit)

Example 7 with IJsonGenObject

use of com.builtbroken.mc.lib.json.imp.IJsonGenObject in project Engine by VoltzEngine-Project.

the class JsonContentLoader method postInit.

@Override
public void postInit() {
    processEntries();
    for (IJsonGenObject obj : generatedObjects) {
        if (obj instanceof IPostInit) {
            ((IPostInit) obj).onPostInit();
        }
        if (obj instanceof IRecipeContainer) {
            List<IRecipe> recipes = new ArrayList();
            ((IRecipeContainer) obj).genRecipes(recipes);
            for (IRecipe recipe : recipes) {
                if (recipe != null && recipe.getRecipeOutput() != null) {
                    GameRegistry.addRecipe(recipe);
                }
            }
        }
    }
}
Also used : IPostInit(com.builtbroken.mc.core.registry.implement.IPostInit) IRecipe(net.minecraft.item.crafting.IRecipe) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) IRecipeContainer(com.builtbroken.mc.core.registry.implement.IRecipeContainer)

Aggregations

IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)7 IRecipe (net.minecraft.item.crafting.IRecipe)3 IPostInit (com.builtbroken.mc.core.registry.implement.IPostInit)2 IRecipeContainer (com.builtbroken.mc.core.registry.implement.IRecipeContainer)2 IRegistryInit (com.builtbroken.mc.core.registry.implement.IRegistryInit)2 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 ItemJsonRenderer (com.builtbroken.mc.client.json.render.item.ItemJsonRenderer)1 RotatableIconListener (com.builtbroken.mc.client.listeners.blocks.RotatableIconListener)1 ILoadComplete (com.builtbroken.mc.core.registry.implement.ILoadComplete)1 BlockBase (com.builtbroken.mc.framework.block.BlockBase)1 JsonEntry (com.builtbroken.mc.lib.json.loading.JsonEntry)1 JsonProcessor (com.builtbroken.mc.lib.json.processors.JsonProcessor)1 RotatableListener (com.builtbroken.mc.prefab.tile.listeners.RotatableListener)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ItemStack (net.minecraft.item.ItemStack)1