Search in sources :

Example 1 with OBJState

use of net.minecraftforge.client.model.obj.OBJModel.OBJState in project ImmersiveEngineering by BluSunrize.

the class TileRenderBelljar method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = tile.getPos();
    if (!quads.containsKey(tile.getFacing())) {
        IBlockState state = getWorld().getBlockState(blockPos);
        if (state.getBlock() != IEContent.blockMetalDevice1)
            return;
        state = state.getActualState(getWorld(), blockPos);
        IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
        if (state instanceof IExtendedBlockState)
            state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
        quads.put(tile.getFacing(), model.getQuads(state, null, 0));
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = Tessellator.getInstance().getBuffer();
    GlStateManager.enableCull();
    IPlantHandler plantHandler = tile.getCurrentPlantHandler();
    if (plantHandler != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 1.0625, 0);
        GlStateManager.color(1, 1, 1, 1);
        float scale = plantHandler.getRenderSize(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
        GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
        GlStateManager.scale(scale, scale, scale);
        if (!plantHandler.overrideRender(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile, blockRenderer)) {
            IBlockState[] states = plantHandler.getRenderedPlant(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
            if (states == null || states.length < 1)
                return;
            for (IBlockState s : states) {
                List<BakedQuad> plantQuadList = plantQuads.get(s);
                if (plantQuadList == null) {
                    IBakedModel plantModel = blockRenderer.getModelForState(s);
                    plantQuadList = plantModel.getQuads(s, null, 0);
                    for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
                    plantQuads.put(s, plantQuadList);
                }
                if (plantQuadList != null) {
                    GlStateManager.pushMatrix();
                    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                    ClientUtils.renderModelTESR(plantQuadList, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
                    Tessellator.getInstance().draw();
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0, 1, 0);
                }
            }
        }
        GlStateManager.popMatrix();
    }
    GlStateManager.depthMask(false);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    ClientUtils.renderModelTESR(quads.get(tile.getFacing()), worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    Tessellator.getInstance().draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 2 with OBJState

use of net.minecraftforge.client.model.obj.OBJModel.OBJState in project ImmersiveEngineering by BluSunrize.

the class TileRenderBottlingMachine method renderModelPart.

public static void renderModelPart(final BlockRendererDispatcher blockRenderer, Tessellator tessellator, VertexBuffer worldRenderer, World world, IBlockState state, IBakedModel model, BlockPos pos, String... parts) {
    if (state instanceof IExtendedBlockState)
        state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList(parts), true));
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    GlStateManager.color(1, 0, 0, 1);
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - pos.getX(), -.5 - pos.getY(), -.5 - pos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 3 with OBJState

use of net.minecraftforge.client.model.obj.OBJModel.OBJState in project ImmersiveEngineering by BluSunrize.

the class TileEntityFluidPipe method getOBJState.

@Override
public OBJState getOBJState() {
    byte connections = getConnectionByte();
    String key = getRenderCacheKey();
    if (!cachedOBJStates.containsKey(key)) {
        ArrayList<String> parts = new ArrayList();
        //new Matrix4();
        Matrix4 rotationMatrix = new Matrix4(TRSRTransformation.identity().getMatrix());
        //			if(pipeCover!=null)
        //				parts.add("cover");
        int totalConnections = Integer.bitCount(connections);
        boolean straightY = (connections & 3) == 3;
        boolean straightZ = (connections & 12) == 12;
        boolean straightX = (connections & 48) == 48;
        switch(totalConnections) {
            case //stub
            0:
                parts.add("center");
                break;
            case //stopper
            1:
                parts.add("stopper");
                //default: y-
                if (//y+
                (connections & 2) != 0)
                    rotationMatrix.rotate(Math.PI, 0, 0, 1);
                else if (//z-
                (connections & 4) != 0)
                    rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                else if (//z+
                (connections & 8) != 0)
                    rotationMatrix.rotate(-Math.PI / 2, 1, 0, 0);
                else if (//x-
                (connections & 16) != 0)
                    rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                else if (//x+
                (connections & 32) != 0)
                    rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                parts.add("con_yMin");
                break;
            case //straight or curve
            2:
                if (straightY) {
                    parts.add("pipe_y");
                    if (getConnectionStyle(0) == 1)
                        parts.add("con_yMin");
                    if (getConnectionStyle(1) == 1)
                        parts.add("con_yMax");
                } else if (straightZ) {
                    parts.add("pipe_z");
                    if (getConnectionStyle(2) == 1)
                        parts.add("con_zMin");
                    if (getConnectionStyle(3) == 1)
                        parts.add("con_zMax");
                } else if (straightX) {
                    parts.add("pipe_x");
                    if (getConnectionStyle(4) == 1)
                        parts.add("con_xMin");
                    if (getConnectionStyle(5) == 1)
                        parts.add("con_xMax");
                } else {
                    parts.add("curve");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    byte connectTo = (byte) (connections & 60);
                    if (//curve to top or bottom
                    (connections & 3) != 0) {
                        if (//x-
                        connectTo == 16)
                            rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        else if (//x+
                        connectTo == 32)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 1, 0);
                        else if (//z+
                        connectTo == 8)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//flip to top
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to z-
                    } else //curve to horizontal
                    {
                        rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        if (//z+ to x+
                        connectTo == 40)
                            rotationMatrix.rotate(Math.PI, 1, 0, 0);
                        else if (//z+ to x-
                        connectTo == 24)
                            rotationMatrix.rotate(-Math.PI / 2, 1, 0, 0);
                        else if (//z- to x+
                        connectTo == 36)
                            rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                    //default: z- to x-
                    }
                }
                break;
            case //tcross or tcurve
            3:
                if (//has straight connect
                straightX || straightZ || straightY) {
                    parts.add("tcross");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    if (straightX) {
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        if (//z-
                        (connections & 4) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to y-
                    } else if (straightY) {
                        rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//x+
                        (connections & 32) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to z-
                    } else //default:z straight
                    {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//x+
                        (connections & 32) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to y-
                    }
                } else //tcurve
                {
                    parts.add("tcurve");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_xMax");
                    //default y-, z-, x+
                    if (//z+
                    (connections & 8) != 0) {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        else
                            rotationMatrix.rotate(-Math.PI / 2, 0, 1, 0);
                    } else //z-
                    {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                    }
                    if (//y+
                    (connections & 2) != 0)
                        rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                }
                break;
            case //cross or complex tcross
            4:
                boolean cross = (straightX && straightZ) || (straightX && straightY) || (straightZ && straightY);
                if (cross) {
                    parts.add("cross");
                    parts.add("con_yMin");
                    parts.add("con_yMax");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    if (//x and z
                    !straightY)
                        rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    else if (//x and y
                    straightX)
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                } else {
                    parts.add("tcross2");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    parts.add("con_xMax");
                    if (straightZ) {
                        //default y- z+- x+
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    } else if (straightY) {
                        rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                        //default y+- z- x+
                        if (//z+
                        (connections & 8) != 0) {
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                            if (//x-
                            (connections & 16) != 0)
                                rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        } else if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                    } else {
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        //default y- z- x+-
                        if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    }
                }
                break;
            case //complete tcross
            5:
                parts.add("tcross3");
                parts.add("con_yMin");
                parts.add("con_yMax");
                parts.add("con_zMin");
                parts.add("con_zMax");
                parts.add("con_xMax");
                //default y+- z+- x+
                if (straightZ) {
                    if (straightY) {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                    } else if (straightX)
                        rotationMatrix.rotate(((connections & 2) != 0) ? (Math.PI / 2) : (-Math.PI / 2), 0, 0, 1);
                } else if (straightX) {
                    rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                    if (//z+
                    (connections & 8) != 0)
                        rotationMatrix.rotate(Math.PI, 0, 1, 0);
                }
                break;
            case //Full Crossing
            6:
                parts.add("con_yMin");
                parts.add("con_yMax");
                parts.add("con_zMin");
                parts.add("con_zMax");
                parts.add("con_xMin");
                parts.add("con_xMax");
                break;
        }
        //			connetionParts
        //			for(int i=0; i<6; i++)
        //				if(((TileEntityFluidPipe)tile).getConnectionStyle(i)==1)
        //					connectionCaps.add(CONNECTIONS[i]);
        Matrix4 tempMatr = new Matrix4();
        tempMatr.m03 = tempMatr.m13 = tempMatr.m23 = .5f;
        rotationMatrix.leftMultiply(tempMatr);
        tempMatr.invert();
        rotationMatrix = rotationMatrix.multiply(tempMatr);
        cachedOBJStates.put(key, new OBJState(parts, true, new TRSRTransformation(rotationMatrix.toMatrix4f())));
    }
    return cachedOBJStates.get(key);
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 4 with OBJState

use of net.minecraftforge.client.model.obj.OBJModel.OBJState in project ImmersiveEngineering by BluSunrize.

the class TileRenderArcFurnace method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityArcFurnace te, double x, double y, double z, float partialTicks, int destroyStage) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
        return;
    List<String> renderedParts = null;
    for (int i = 0; i < 3; i++) if (te.getInventory()[23 + i] != null) {
        if (renderedParts == null)
            renderedParts = Lists.newArrayList("electrode" + (i + 1));
        else
            renderedParts.add("electrode" + (i + 1));
    }
    if (renderedParts == null)
        return;
    if (te.shouldRenderAsActive())
        renderedParts.add("active");
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    if (state instanceof IExtendedBlockState)
        state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(renderedParts, true));
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldRenderer = tessellator.getBuffer();
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.translate(.5, .5, .5);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(te.getWorld(), model, state, blockPos, worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 5 with OBJState

use of net.minecraftforge.client.model.obj.OBJModel.OBJState in project ImmersiveEngineering by BluSunrize.

the class TileRenderSampleDrill method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntitySampleDrill tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile.isDummy() || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    BlockPos blockPos = tile.getPos();
    IBakedModel model = blockRenderer.getModelForState(state);
    //				.getModelFromBlockState(state, getWorld(), blockPos);
    if (state instanceof IExtendedBlockState)
        state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Lists.newArrayList("drill"), true));
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldRenderer = tessellator.getBuffer();
    bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    //		float rot = 360*tile.rotation-(!tile.canTurn||tile.rotation==0||tile.rotation-tile.prevRotation<4?0:tile.facing.getAxis()==Axis.X?-f:f);
    //		GlStateManager.rotate(rot, 0,0,1);
    int max = IEConfig.Machines.coredrill_time;
    if (tile.process > 0 && tile.process < max) {
        GL11.glRotatef(((tile.process + partialTicks) * 22.5f) % 360f, 0, 1, 0);
        float push = tile.process / (float) max;
        if (tile.process > max / 2)
            push = 1 - push;
        GL11.glTranslated(0, -2.8f * push, 0);
    }
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(tile.getWorld(), model, state, tile.getPos(), worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Aggregations

OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 IBlockState (net.minecraft.block.state.IBlockState)10 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)10 BlockPos (net.minecraft.util.math.BlockPos)7 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)6 EnumFacing (net.minecraft.util.EnumFacing)5 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)3 Block (net.minecraft.block.Block)3 TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable)2 IPlantHandler (blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler)2 IESmartObjModel (blusunrize.immersiveengineering.client.models.IESmartObjModel)2 IOBJModelCallback (blusunrize.immersiveengineering.client.models.IOBJModelCallback)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ItemStack (net.minecraft.item.ItemStack)2 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)2 ConveyorHandler (blusunrize.immersiveengineering.api.tool.ConveyorHandler)1 IConveyorTile (blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile)1