use of com.builtbroken.mc.core.registry.implement.IRegistryInit 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);
}
}
}
use of com.builtbroken.mc.core.registry.implement.IRegistryInit 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;
}
Aggregations