Search in sources :

Example 1 with IJsonGenObject

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

the class JsonContentLoader method handlePostCalls.

/**
     * Called to handle post call code on generated objects.
     * <p>
     * Separated from {@link #postInit()} due to other processors
     * having special handling.
     *
     * @param generatedObjects
     */
public void handlePostCalls(List<IJsonGenObject> generatedObjects) {
    if (generatedObjects != null && !generatedObjects.isEmpty()) {
        for (IJsonGenObject obj : generatedObjects) {
            debug.start("Handling: " + obj);
            if (obj instanceof IPostInit) {
                ((IPostInit) obj).onPostInit();
            }
            if (obj instanceof IRecipeContainer) {
                List<IRecipe> recipes = new ArrayList();
                ((IRecipeContainer) obj).genRecipes(recipes);
                if (recipes.size() > 0) {
                    debug.start("Adding recipes from gen object:");
                    for (IRecipe recipe : recipes) {
                        if (recipe != null) {
                            if (recipe.getRecipeOutput() != null) {
                                GameRegistry.addRecipe(recipe);
                            } else {
                                debug.log("Null recipe output detected");
                            }
                        } else {
                            debug.log("Null recipe detected");
                        }
                    }
                    debug.end();
                }
            }
            debug.end();
        }
    }
}
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)

Example 2 with IJsonGenObject

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

the class JsonContentLoader method process.

/**
     * Called to processe a single set of content
     * <p>
     * This is normally called outside of this class
     * when content needs to load before a set time
     * in order for minecraft to handle the content
     * correctly. Examples of this are item/block
     * textures that load before init() when most
     * content is actually loaded.
     *
     * @param processorKey
     */
public void process(String processorKey) {
    if (jsonEntries.containsKey(processorKey)) {
        final List<JsonEntry> entries = jsonEntries.get(processorKey);
        if (entries != null) {
            final Iterator<JsonEntry> it = entries.iterator();
            //Process all loaded elements
            while (it.hasNext()) {
                final JsonEntry entry = it.next();
                try {
                    List<IJsonGenObject> objects = new ArrayList();
                    //Call to process
                    boolean handled = process(entry.jsonKey, entry.element, objects);
                    //Register and add generated objects
                    for (IJsonGenObject data : objects) {
                        if (data != null) {
                            //Set author
                            if (entry.author != null && !entry.author.isEmpty()) {
                                data.setAuthor(entry.author);
                            }
                            //Add gen data to list
                            List<IJsonGenObject> list = generatedObjects.get(processorKey);
                            if (list == null) {
                                list = new ArrayList();
                            }
                            list.add(data);
                            generatedObjects.put(processorKey, list);
                            //validate data, can crash
                            data.validate();
                            //Call registry methods
                            data.register();
                            if (data instanceof IRegistryInit) {
                                ((IRegistryInit) data).onRegistered();
                            }
                        }
                    }
                    //If handled remove from list
                    if (handled) {
                        it.remove();
                    }
                } catch (Exception e) {
                    //Crash as the file may be important
                    throw new RuntimeException("Failed to process entry from file " + entry.fileReadFrom + ". Make corrections to the file or contact the file's creator for the issue to be fixed.\n  Entry = " + entry, e);
                }
            }
        }
        if (entries.size() <= 0) {
            jsonEntries.remove(processorKey);
        } else {
            jsonEntries.put(processorKey, entries);
        }
    }
}
Also used : JsonEntry(com.builtbroken.mc.lib.json.loading.JsonEntry) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) IRegistryInit(com.builtbroken.mc.core.registry.implement.IRegistryInit) IOException(java.io.IOException)

Example 3 with IJsonGenObject

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

the class JsonContentLoader method loadComplete.

@Override
public void loadComplete() {
    debug.start("Phase: Load-Complete");
    final List<String> sortingProcessorList = getSortedProcessorList();
    for (String proccessorKey : sortingProcessorList) {
        if (generatedObjects.get(proccessorKey) != null && !generatedObjects.get(proccessorKey).isEmpty()) {
            for (IJsonGenObject obj : generatedObjects.get(proccessorKey)) {
                if (obj instanceof ILoadComplete) {
                    ((ILoadComplete) obj).onLoadCompleted();
                }
            }
        }
    }
    debug.log("Clearing data");
    clear();
    debug.end("Done...");
}
Also used : IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ILoadComplete(com.builtbroken.mc.core.registry.implement.ILoadComplete)

Example 4 with IJsonGenObject

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

the class ClientProxy method postInit.

@Override
public void postInit() {
    super.postInit();
    //Item that uses a model for all states
    registerItemJsonRenders(new ItemJsonRenderer(), "VE-Item", "item", "tile", "block");
    List<IJsonGenObject> objects = JsonContentLoader.INSTANCE.generatedObjects.get(JsonBlockProcessor.KEY);
    if (objects != null && !objects.isEmpty()) {
        for (IJsonGenObject object : objects) {
            if (object instanceof BlockBase) {
                List<ITileEventListener> listeners = ((BlockBase) object).listeners.get("placement");
                if (listeners != null && !listeners.isEmpty()) {
                    for (ITileEventListener listener : listeners) {
                        if (listener instanceof RotatableListener) {
                            ((BlockBase) object).addListener(new RotatableIconListener((BlockBase) object));
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : RotatableListener(com.builtbroken.mc.prefab.tile.listeners.RotatableListener) BlockBase(com.builtbroken.mc.framework.block.BlockBase) RotatableIconListener(com.builtbroken.mc.client.listeners.blocks.RotatableIconListener) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) ItemJsonRenderer(com.builtbroken.mc.client.json.render.item.ItemJsonRenderer)

Example 5 with IJsonGenObject

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

the class JsonRecipeReplacementProcessor method loadComplete.

@Override
public void loadComplete() {
    //Init replacement data
    Iterator it = replacementData.iterator();
    while (it.hasNext()) {
        JsonRecipeReplacementData data = (JsonRecipeReplacementData) it.next();
        if (data.output == null) {
            data.output = data.convertItemEntry(data.outputValue);
        }
        if (data.output == null) {
            Engine.logger().error("JsonRecipeReplacementProcessor: Failed to locate item entry for '" + data.outputValue + "' ignoring value.");
            it.remove();
        }
    }
    //Loop recipes and remove entries
    it = CraftingManager.getInstance().getRecipeList().iterator();
    while (it.hasNext()) {
        Object r = it.next();
        if (r instanceof IRecipe) {
            final ItemStack result = ((IRecipe) r).getRecipeOutput();
            if (result != null) {
                //Loop replacement data checking for match
                for (JsonRecipeReplacementData data : replacementData) {
                    if ("grid".equalsIgnoreCase(data.craftingType) && data.doesMatchForReplacement(result)) {
                        Engine.logger().info("JsonRecipeReplacementProcessor: Removed recipe -> " + r);
                        //Remove and exit loop
                        it.remove();
                        break;
                    }
                }
            } else //Error to note broken recipe might exist
            {
                Engine.logger().error("JsonRecipeReplacementProcessor: Potential broken recipe with no output -> " + r);
            }
        }
    }
    //Loop to finalize data
    for (JsonRecipeReplacementData data : replacementData) {
        if (!data.subProcessingData.isEmpty()) {
            final List<IJsonGenObject> objects = new ArrayList();
            for (Map.Entry<String, JsonElement> entry : data.subProcessingData.entrySet()) {
                JsonContentLoader.INSTANCE.process(entry.getKey(), entry.getValue(), objects);
            }
            JsonContentLoader.INSTANCE.handlePostCalls(objects);
        }
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) JsonElement(com.google.gson.JsonElement) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

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