use of com.builtbroken.mc.client.json.render.tile.TileRenderData in project Engine by VoltzEngine-Project.
the class RenderJsonProcessor method process.
@Override
public RenderData process(JsonElement element) {
final JsonObject object = element.getAsJsonObject();
ensureValuesExist(object, "contentID", "states", "type");
String contentID = object.get("contentID").getAsString();
String overAllRenderType = object.get("type").getAsString();
RenderData data;
if (overAllRenderType.equalsIgnoreCase("tile")) {
data = new TileRenderData(this, contentID, overAllRenderType);
if (object.has("tileClass")) {
try {
((TileRenderData) data).tileClass = (Class<? extends TileEntity>) Class.forName(object.get("tileClass").getAsString());
} catch (Exception e) {
throw new IllegalArgumentException("Failed to load class for name '" + object.get("tileClass").getAsString() + "'");
}
}
} else {
data = new RenderData(this, contentID, overAllRenderType);
}
JsonArray array = object.get("states").getAsJsonArray();
for (JsonElement arrayElement : array) {
if (arrayElement instanceof JsonObject) {
JsonObject renderStateObject = arrayElement.getAsJsonObject();
//For loop handling for the lazy
if (renderStateObject.has("for")) {
renderStateObject = renderStateObject.getAsJsonObject("for");
ensureValuesExist(renderStateObject, "start", "end", "state");
int start = renderStateObject.getAsJsonPrimitive("start").getAsInt();
int end = renderStateObject.getAsJsonPrimitive("end").getAsInt();
if (start >= end) {
throw new IllegalArgumentException("Start can not be greater than or equal to end for a for loop.");
}
JsonObject template = renderStateObject.getAsJsonObject("state");
for (int i = start; i <= end; i++) {
JsonObject state = new JsonObject();
//Copy template and rename values as needed
for (Map.Entry<String, JsonElement> entry : template.entrySet()) {
if (entry.getValue() instanceof JsonPrimitive && ((JsonPrimitive) entry.getValue()).isString()) {
String s = entry.getValue().getAsString();
s = s.replace("%number%", "" + i);
state.add(entry.getKey(), new JsonPrimitive(s));
} else {
state.add(entry.getKey(), entry.getValue());
}
}
//Load state
handle(state, data, overAllRenderType);
}
} else {
handle(renderStateObject, data, overAllRenderType);
}
}
}
//Handle post calls
for (IRenderState state : data.renderStatesByName.values()) {
//Handles post processor actions
if (stateToProcessor.containsKey(state)) {
stateToProcessor.get(state).postHandle(state, data);
}
}
//Clear run data
stateToProcessor.clear();
//TODO ensure modelID exists if model state
return data;
}
Aggregations