Search in sources :

Example 1 with RenderData

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);
        }
    }
}
Also used : RenderExCreeper(com.builtbroken.mc.core.content.entity.RenderExCreeper) RenderData(com.builtbroken.mc.client.json.render.RenderData) TileRenderData(com.builtbroken.mc.client.json.render.tile.TileRenderData) TileRenderData(com.builtbroken.mc.client.json.render.tile.TileRenderData) TileRenderHandler(com.builtbroken.mc.client.json.render.tile.TileRenderHandler)

Example 2 with RenderData

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();
}
Also used : RenderData(com.builtbroken.mc.client.json.render.RenderData)

Example 3 with RenderData

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;
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) TileRenderData(com.builtbroken.mc.client.json.render.tile.TileRenderData) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) RenderData(com.builtbroken.mc.client.json.render.RenderData) TileRenderData(com.builtbroken.mc.client.json.render.tile.TileRenderData) JsonElement(com.google.gson.JsonElement) IRenderState(com.builtbroken.mc.client.json.imp.IRenderState) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RenderData

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();
            }
        }
    }
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) BlockBase(com.builtbroken.mc.framework.block.BlockBase) RenderData(com.builtbroken.mc.client.json.render.RenderData) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) IRenderState(com.builtbroken.mc.client.json.imp.IRenderState) IModelState(com.builtbroken.mc.client.json.imp.IModelState) ITileRenderListener(com.builtbroken.mc.api.tile.listeners.client.ITileRenderListener)

Aggregations

RenderData (com.builtbroken.mc.client.json.render.RenderData)4 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)2 TileRenderData (com.builtbroken.mc.client.json.render.tile.TileRenderData)2 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 ITileRenderListener (com.builtbroken.mc.api.tile.listeners.client.ITileRenderListener)1 IModelState (com.builtbroken.mc.client.json.imp.IModelState)1 TileRenderHandler (com.builtbroken.mc.client.json.render.tile.TileRenderHandler)1 RenderExCreeper (com.builtbroken.mc.core.content.entity.RenderExCreeper)1 BlockBase (com.builtbroken.mc.framework.block.BlockBase)1 ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1