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();
}
}
}
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);
}
}
}
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...");
}
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;
}
}
}
}
}
}
}
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);
}
}
}
Aggregations