Search in sources :

Example 1 with IModelState

use of com.builtbroken.mc.client.json.imp.IModelState 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)

Example 2 with IModelState

use of com.builtbroken.mc.client.json.imp.IModelState in project Engine by VoltzEngine-Project.

the class ModelState method render.

@Override
public boolean render(boolean subRender) {
    TextureData textureData = getTexture();
    ModelData data = getModel();
    if (data != null && data.getModel() != null) {
        //Starts rendering by storing previous matrix
        GL11.glPushMatrix();
        if (!subRender) {
            //Scales object by value
            if (scale != null) {
                GL11.glScaled(scale.x(), scale.y(), scale.z());
            } else if (parentState instanceof IModelState && ((IModelState) parentState).getScale() != null) {
                GL11.glScaled(((IModelState) parentState).getScale().x(), ((IModelState) parentState).getScale().y(), ((IModelState) parentState).getScale().z());
            }
            //Rotates object, needs to be handled after scaling
            if (rotation != null) {
                GL11.glRotated(rotation.pitch(), 1, 0, 0);
                GL11.glRotated(rotation.yaw(), 0, 1, 0);
                GL11.glRotated(rotation.roll(), 0, 0, 1);
            } else if (parentState instanceof IModelState && ((IModelState) parentState).getRotation() != null) {
                GL11.glRotated(((IModelState) parentState).getRotation().pitch(), 1, 0, 0);
                GL11.glRotated(((IModelState) parentState).getRotation().yaw(), 0, 1, 0);
                GL11.glRotated(((IModelState) parentState).getRotation().roll(), 0, 0, 1);
            }
            //Moves the object
            if (offset != null) {
                GL11.glTranslated(offset.x(), offset.y(), offset.z());
            } else if (parentState instanceof IModelState && ((IModelState) parentState).getOffset() != null) {
                GL11.glTranslated(((IModelState) parentState).getOffset().x(), ((IModelState) parentState).getOffset().y(), ((IModelState) parentState).getOffset().z());
            }
        }
        //Render parent
        GL11.glPushMatrix();
        if (parentState instanceof IModelState) {
            if (renderParent) {
                ((IModelState) parentState).render(true);
            } else if (parts == null && parentState instanceof ModelState && ((ModelState) parentState).renderParent) {
                if (((ModelState) parentState).parentState instanceof IModelState) {
                    ((IModelState) ((ModelState) parentState).parentState).render(true);
                }
            }
        }
        GL11.glPopMatrix();
        //Binds texture
        if (textureData != null) {
            FMLClientHandler.instance().getClient().renderEngine.bindTexture(textureData.getLocation());
        } else {
            //Backup texture bind, if no texture
            FMLClientHandler.instance().getClient().renderEngine.bindTexture(SharedAssets.GREY_TEXTURE);
        }
        //Render model
        data.render(renderOnlyParts, getPartsToRender());
        //Ends render by restoring previous matrix(rotation, position, etc)
        GL11.glPopMatrix();
        return true;
    }
    return false;
}
Also used : ModelData(com.builtbroken.mc.client.json.models.ModelData) TextureData(com.builtbroken.mc.client.json.texture.TextureData) IModelState(com.builtbroken.mc.client.json.imp.IModelState) IModelState(com.builtbroken.mc.client.json.imp.IModelState)

Aggregations

IModelState (com.builtbroken.mc.client.json.imp.IModelState)2 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 ITileRenderListener (com.builtbroken.mc.api.tile.listeners.client.ITileRenderListener)1 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)1 ModelData (com.builtbroken.mc.client.json.models.ModelData)1 RenderData (com.builtbroken.mc.client.json.render.RenderData)1 TextureData (com.builtbroken.mc.client.json.texture.TextureData)1 BlockBase (com.builtbroken.mc.framework.block.BlockBase)1 ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)1