use of com.builtbroken.mc.client.json.imp.IRenderState 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;
}
use of com.builtbroken.mc.client.json.imp.IRenderState in project Engine by VoltzEngine-Project.
the class RenderJsonProcessor method handle.
protected void handle(JsonObject renderStateObject, RenderData data, String overAllRenderType) {
IRenderState renderState = null;
//Data
ensureValuesExist(renderStateObject, "id");
//State ID
JsonPrimitive stateIDElement = renderStateObject.getAsJsonPrimitive("id");
String stateID = stateIDElement.getAsString();
//Type override
String subType = overAllRenderType;
if (renderStateObject.has("renderType")) {
subType = renderStateObject.get("renderType").getAsString();
}
//Check sub processors in order to get state
for (RenderJsonSubProcessor processor : stateProcessors) {
if (processor.canProcess(subType)) {
renderState = processor.process(renderStateObject, stateID, overAllRenderType, subType);
if (renderState != null) {
stateToProcessor.put(renderState, processor);
processor.process(renderState, renderStateObject);
break;
}
}
}
//No state, crash TODO add config to ignore broken states
if (renderState == null) {
throw new RuntimeException("Failed to process render state for StateID[" + stateID + "] SubRenderType[" + subType + "] RenderType[" + overAllRenderType + "]");
}
//Add state to map
data.add(stateID, renderState);
}
use of com.builtbroken.mc.client.json.imp.IRenderState in project Engine by VoltzEngine-Project.
the class TileRenderHandler method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) {
GL11.glPushMatrix();
try {
GL11.glTranslated(x + 0.5, y, z + 0.5);
RenderData data = getRenderData(tile);
if (data != null && data.renderType.equalsIgnoreCase("tile")) {
//Try to get tile specific state
String key = getRenderStateKey(tile);
//Loop default keys
for (String de : new String[] { key, "tile", "entity", "item.entity" }) {
if (de != null) {
IRenderState state = data.getState(de);
if (state instanceof IModelState && ((IModelState) state).render(false)) {
break;
}
}
}
}
} catch (Exception e) {
Engine.logger().error("TileRenderHandler: Error rendering " + tile, e);
}
GL11.glPopMatrix();
//If BlockBase, iterate listeners
if (tile.getBlockType() instanceof BlockBase) {
ListenerIterator it = new ListenerIterator(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, (BlockBase) tile.getBlockType(), "tilerender");
while (it.hasNext()) {
ITileEventListener next = it.next();
if (next instanceof ITileRenderListener) {
GL11.glPushMatrix();
try {
((ITileRenderListener) next).renderDynamic(tile, x, y, z, f);
} catch (Exception e) {
Engine.logger().error("TileRenderHandler: Error calling listener[" + next + "] for Tile[" + tile + "]", e);
}
GL11.glPopMatrix();
}
}
}
}
use of com.builtbroken.mc.client.json.imp.IRenderState in project Engine by VoltzEngine-Project.
the class ItemBase method getIconFromState.
/**
* Called to get the icon from the state
*
* @param data - render data
* @param meta - metadata or damage of the item
* @param pass - render pass, 0 by default
* @return icon, can not be null or will crash
*/
protected IIcon getIconFromState(RenderData data, int meta, int pass) {
if (data != null) {
//Attempt to get meta
IRenderState state = data.getState(RenderData.INVENTORY_RENDER_KEY + "." + meta);
if (state != null) {
state = data.getState(RenderData.INVENTORY_RENDER_KEY);
if (state != null) {
IIcon icon = state.getIcon(pass);
if (icon != null) {
return icon;
}
}
}
//Attempt to do non-meta
state = data.getState(RenderData.INVENTORY_RENDER_KEY);
if (state != null) {
IIcon icon = state.getIcon(0);
if (icon != null) {
return icon;
}
}
}
return getFallBackIcon();
}
Aggregations