Package mods.railcraft.client.render

Source Code of mods.railcraft.client.render.RenderIronTank

/*
* Copyright (c) CovertJaguar, 2014 http://railcraft.info
*
* This code is the property of CovertJaguar
* and may only be used with explicit written
* permission unless otherwise specified on the
* license page at http://railcraft.info/wiki/info:license.
*/
package mods.railcraft.client.render;

import mods.railcraft.client.render.RenderFakeBlock.RenderInfo;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.IIcon;
import org.lwjgl.opengl.GL11;
import mods.railcraft.common.blocks.machine.TileMultiBlock;
import mods.railcraft.common.blocks.machine.beta.TileTankBase;
import mods.railcraft.common.blocks.machine.beta.TileTankIronValve;
import mods.railcraft.common.core.RailcraftConfig;
import mods.railcraft.common.fluids.TankManager;
import mods.railcraft.common.fluids.tanks.StandardTank;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;

/**
*
* @author CovertJaguar <http://www.railcraft.info>
*/
public class RenderIronTank extends TileEntitySpecialRenderer {

    private static final RenderInfo fillBlock = new RenderInfo();

    public RenderIronTank() {
        float pix = RenderTools.PIXEL;
        fillBlock.minX = 5 * pix;
        fillBlock.minZ = 5 * pix;

        fillBlock.maxX = 11 * pix;
        fillBlock.maxZ = 11 * pix;

        fillBlock.texture = new IIcon[6];
    }

    private void prepFillTexture(FluidStack fluidStack) {
        ResourceLocation texSheet = FluidRenderer.setupFlowingLiquidTexture(fluidStack, fillBlock.texture);
        if (texSheet != null)
            bindTexture(texSheet);
    }

    private float getVerticalScaleSide(TileMultiBlock tile) {
        int y = tile.getPatternPositionY();
        if (!RailcraftConfig.allowTankStacking())
            y--;
        return y - RenderTools.PIXEL * 5;
    }

    private int getTankHeight(TileMultiBlock tile) {
        int height = tile.getPattern().getPatternHeight();
        if (!RailcraftConfig.allowTankStacking())
            height -= 2;
        return height;
    }

    private void draw(StandardTank tank) {
        preGL();
        FluidRenderer.setColorForTank(tank);
        RenderFakeBlock.renderBlockForEntity(fillBlock, null, 0, 0, 0, false, true);
        postGL();
    }

    private void preGL() {
        GL11.glPushMatrix();
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    }

    private void postGL() {
        GL11.glPopAttrib();
        GL11.glPopMatrix();
    }

    @Override
    public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) {
        if (!((TileMultiBlock) tile).isStructureValid())
            return;

        if (tile instanceof TileTankIronValve) {
            TileTankIronValve valve = (TileTankIronValve) tile;

            if (valve.isFilling()) {
                StandardTank tank = valve.getFillTank();
                FluidStack fluidStack = tank.getFluid();
                if (fluidStack != null && fluidStack.amount > 0 && fluidStack.getFluid() != null) {
                    GL11.glPushMatrix();
                    if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPositionX(), valve.getPatternPositionY() - 1, valve.getPatternPositionZ()) == 'A') {

                        prepFillTexture(fluidStack);

                        int height = getTankHeight(valve);
                        float yOffset = height / 2f;
                        float vScale = height - 2f;
                        GL11.glTranslatef((float) x + 0.5F, (float) y + yOffset - height + 1, (float) z + 0.5F);
                        GL11.glScalef(1f, vScale, 1f);

                        draw(tank);
                    } else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPositionX() - 1, valve.getPatternPositionY(), valve.getPatternPositionZ()) == 'A') {

                        prepFillTexture(fluidStack);

                        float vScale = getVerticalScaleSide(valve);
                        float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                        GL11.glTranslatef((float) x - 0.5F + RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
                        GL11.glScalef(1f, vScale, 1f);

                        draw(tank);
                    } else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPositionX() + 1, valve.getPatternPositionY(), valve.getPatternPositionZ()) == 'A') {

                        prepFillTexture(fluidStack);

                        float vScale = getVerticalScaleSide(valve);
                        float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                        GL11.glTranslatef((float) x + 1.5F - RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
                        GL11.glScalef(1f, vScale, 1f);

                        draw(tank);
                    } else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPositionX(), valve.getPatternPositionY(), valve.getPatternPositionZ() - 1) == 'A') {

                        prepFillTexture(fluidStack);

                        float vScale = getVerticalScaleSide(valve);
                        float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                        GL11.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z - 0.5F + RenderTools.PIXEL * 5);
                        GL11.glScalef(1f, vScale, 1f);

                        draw(tank);
                    } else if (valve.getPattern().getPatternMarkerChecked(valve.getPatternPositionX(), valve.getPatternPositionY(), valve.getPatternPositionZ() + 1) == 'A') {

                        prepFillTexture(fluidStack);

                        float vScale = getVerticalScaleSide(valve);
                        float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                        GL11.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z + 1.5F - RenderTools.PIXEL * 5);
                        GL11.glScalef(1f, vScale, 1f);

                        draw(tank);
                    }
                    GL11.glPopMatrix();
                }
            }
        }

        TileTankBase ironTank = (TileTankBase) tile;
        if (!ironTank.isMaster() || ironTank.isInvalid())
            return;
        int height = getTankHeight(ironTank);
        float yOffset = height / 2f;
        float vScale = height - 2;
        float hScale = ironTank.getPattern().getPatternWidthX() - 2;

        TankManager tankManager = ironTank.getTankManager();
        if (tankManager == null)
            return;
        StandardTank tank = tankManager.get(0);
        if (tank == null)
            return;

        FluidStack fluidStack = tank.getFluid();
        if (fluidStack != null && fluidStack.amount > 0 && fluidStack.getFluid() != null) {
            preGL();
            GL11.glTranslatef((float) x + 0.5F, (float) y + yOffset + 0.01f, (float) z + 0.5F);
            GL11.glScalef(hScale, vScale, hScale);

//        GL11.glScalef(0.999f, 1, 0.999f);
            int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack);
            if (displayLists != null) {
                GL11.glPushMatrix();

                float cap = tank.getCapacity();
                float level = (float) Math.min(fluidStack.amount, cap) / cap;

                bindTexture(FluidRenderer.getFluidSheet(fluidStack));
                FluidRenderer.setColorForTank(tank);
                GL11.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]);

                GL11.glPopMatrix();
            }

            postGL();
        }

    }

}
TOP

Related Classes of mods.railcraft.client.render.RenderIronTank

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.