Search in sources :

Example 1 with FluidLogic

use of mods.railcraft.common.blocks.logic.FluidLogic in project Railcraft by Railcraft.

the class TESRHollowTank method render.

@Override
public void render(TileTank tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    tile.getLogic(StructureLogic.class).filter(StructureLogic::isStructureValid).ifPresent(structure -> {
        structure.getLogic(ValveLogic.class).ifPresent(valve -> {
            StandardTank fillTank = valve.getFillTank();
            FluidStack fillStack = fillTank.getFluid();
            if (fillStack != null && fillStack.amount > 0) {
                OpenGL.glPushMatrix();
                if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().down()) == 'A') {
                    // prepFillTexture(fillStack);
                    int height = getTankHeight(structure);
                    float yOffset = height / 2f;
                    float vScale = height;
                    OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset - height + 1, (float) z + 0.5F);
                    OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
                    draw(fillStack, tile.getPos().down());
                } else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().west()) == 'A') {
                    // prepFillTexture(fillStack);
                    float vScale = getVerticalScaleSide(structure);
                    float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                    OpenGL.glTranslatef((float) x - 0.5F + RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
                    OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
                    draw(fillStack, tile.getPos().west());
                } else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().east()) == 'A') {
                    // prepFillTexture(fillStack);
                    float vScale = getVerticalScaleSide(structure);
                    float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                    OpenGL.glTranslatef((float) x + 1.5F - RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
                    OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
                    draw(fillStack, tile.getPos().east());
                } else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().north()) == 'A') {
                    // prepFillTexture(fillStack);
                    float vScale = getVerticalScaleSide(structure);
                    float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                    OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z - 0.5F + RenderTools.PIXEL * 5);
                    OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
                    draw(fillStack, tile.getPos().north());
                } else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().south()) == 'A') {
                    // prepFillTexture(fillStack);
                    float vScale = getVerticalScaleSide(structure);
                    float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
                    OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z + 1.5F - RenderTools.PIXEL * 5);
                    OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
                    draw(fillStack, tile.getPos().south());
                }
                OpenGL.glPopMatrix();
            }
        });
        if (!structure.isValidMaster() || tile.isInvalid())
            return;
        int height = getTankHeight(structure);
        float yOffset = height / 2f;
        float vScale = height - 2;
        float hScale = structure.getPattern().getPatternWidthX() - 2;
        structure.getFunctionalLogic(FluidLogic.class).map(fluidLogic -> fluidLogic.getTankManager().get(0)).ifPresent(tank -> {
            FluidStack fluidStack = tank.getFluid();
            if (fluidStack != null && fluidStack.amount > 0) {
                preGL(fluidStack, tile.getPos().up());
                OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset + 0.01f, (float) z + 0.5F);
                OpenGL.glScalef(hScale, vScale, hScale);
                OpenGL.glScalef(0.999f, 1, 0.999f);
                // int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack); this broke
                // OpenGL.glPushMatrix();
                // 
                OpenGL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                float cap = tank.getCapacity();
                OpenGL.glTranslatef(-0.5F, -0.501F, -0.5F);
                float level = Math.min(fluidStack.amount / cap, 1.0F);
                FluidModelRenderer.INSTANCE.renderFluid(fluidStack, Math.min(16, (int) Math.ceil(level * 16F)));
                // 
                // bindTexture(FluidRenderer.getFluidSheet(fluidStack));
                // FluidRenderer.setColorForFluid(fluidStack);
                // OpenGL.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]);
                postGL();
            // OpenGL.glPopMatrix();
            }
        });
    });
}
Also used : OpenGlHelper(net.minecraft.client.renderer.OpenGlHelper) GlStateManager(net.minecraft.client.renderer.GlStateManager) TileEntitySpecialRenderer(net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer) FluidModelRenderer(mods.railcraft.client.render.models.resource.FluidModelRenderer) BlockPos(net.minecraft.util.math.BlockPos) StructureLogic(mods.railcraft.common.blocks.logic.StructureLogic) RenderTools(mods.railcraft.client.render.tools.RenderTools) TileTank(mods.railcraft.common.blocks.structures.TileTank) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) ValveLogic(mods.railcraft.common.blocks.logic.ValveLogic) FluidStack(net.minecraftforge.fluids.FluidStack) OpenGL(mods.railcraft.client.render.tools.OpenGL) RailcraftConfig(mods.railcraft.common.core.RailcraftConfig) GL11(org.lwjgl.opengl.GL11) FluidLogic(mods.railcraft.common.blocks.logic.FluidLogic) StandardTank(mods.railcraft.common.fluids.tanks.StandardTank) FluidStack(net.minecraftforge.fluids.FluidStack) ValveLogic(mods.railcraft.common.blocks.logic.ValveLogic) StandardTank(mods.railcraft.common.fluids.tanks.StandardTank)

Aggregations

FluidModelRenderer (mods.railcraft.client.render.models.resource.FluidModelRenderer)1 OpenGL (mods.railcraft.client.render.tools.OpenGL)1 RenderTools (mods.railcraft.client.render.tools.RenderTools)1 FluidLogic (mods.railcraft.common.blocks.logic.FluidLogic)1 StructureLogic (mods.railcraft.common.blocks.logic.StructureLogic)1 ValveLogic (mods.railcraft.common.blocks.logic.ValveLogic)1 TileTank (mods.railcraft.common.blocks.structures.TileTank)1 RailcraftConfig (mods.railcraft.common.core.RailcraftConfig)1 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)1 GlStateManager (net.minecraft.client.renderer.GlStateManager)1 OpenGlHelper (net.minecraft.client.renderer.OpenGlHelper)1 TileEntitySpecialRenderer (net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer)1 BlockPos (net.minecraft.util.math.BlockPos)1 EnumSkyBlock (net.minecraft.world.EnumSkyBlock)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 GL11 (org.lwjgl.opengl.GL11)1