use of com.builtbroken.mc.client.json.render.RenderData in project Engine by VoltzEngine-Project.
the class ClientProxy method init.
@Override
public void init() {
super.init();
RenderingRegistry.registerEntityRenderingHandler(EntityExCreeper.class, new RenderExCreeper());
if (Engine.multiBlock != null) {
RenderingRegistry.registerBlockHandler(MultiBlockRenderHelper.INSTANCE);
}
TileRenderHandler tileRenderHandler = new TileRenderHandler();
for (RenderData data : ClientDataHandler.INSTANCE.renderData.values()) {
if (data instanceof TileRenderData && ((TileRenderData) data).tileClass != null) {
ClientRegistry.bindTileEntitySpecialRenderer(((TileRenderData) data).tileClass, tileRenderHandler);
}
}
}
use of com.builtbroken.mc.client.json.render.RenderData in project Engine by VoltzEngine-Project.
the class ItemJsonRenderer method renderItem.
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... dataArray) {
RenderData data = getRenderData(type, item, dataArray);
GL11.glPushMatrix();
//Attempt to render extra render states
if (data != null) {
List<String> renderStates = getRenderStatesToTry(type, item, dataArray);
if (renderStates != null) {
for (String s : renderStates) {
if (s != null && data.render(type, s, item)) {
GL11.glPopMatrix();
return;
}
}
}
}
//Else attempt to render default
if (data == null || !data.render(type, null, item)) {
//If default is null or didn't render, do backup
doBackupRender(type);
}
GL11.glPopMatrix();
}
use of com.builtbroken.mc.client.json.render.RenderData 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.render.RenderData 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();
}
}
}
}
Aggregations