Search in sources :

Example 1 with JsonEntry

use of com.builtbroken.mc.lib.json.loading.JsonEntry 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)

Aggregations

IRegistryInit (com.builtbroken.mc.core.registry.implement.IRegistryInit)1 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)1 JsonEntry (com.builtbroken.mc.lib.json.loading.JsonEntry)1 IOException (java.io.IOException)1