Search in sources :

Example 1 with FluidCuboid

use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.

the class CisternTileEntityRenderer method render.

@Override
public void render(CisternTileEntity tileEntity, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int light, int combinedOverlay) {
    FluidStack fluid = tileEntity.getPublicHandler().orElse(EmptyFluidHandler.INSTANCE).getFluidInTank(0);
    if (!fluid.isEmpty()) {
        int renderIndex = tileEntity.getRenderIndex();
        // capacity for gives us the minimum amount to start rendering in this segement
        // render nothing beyond the base capacity
        int amount = fluid.getAmount() - tileEntity.capacityFor(renderIndex);
        if (amount > 0) {
            // get the model pair, if the capacity is above the capacity per cistern, use the overfull model (no top face)
            BlockState state = tileEntity.getBlockState();
            CisternModel.BakedModel model = ModelHelper.getBakedModel(state, CisternModel.BakedModel.class);
            if (model != null) {
                // fetch textures and attributes
                FluidAttributes attributes = fluid.getFluid().getAttributes();
                TextureAtlasSprite still = FluidRenderer.getBlockSprite(attributes.getStillTexture(fluid));
                TextureAtlasSprite flowing = FluidRenderer.getBlockSprite(attributes.getFlowingTexture(fluid));
                IVertexBuilder builder = buffer.getBuffer(FluidRenderer.RENDER_TYPE);
                int color = attributes.getColor(fluid);
                light = FluidRenderer.withBlockLight(light, attributes.getLuminosity(fluid));
                // if full, just render all full sides
                int capacityPerLayer = tileEntity.capacityPerLayer();
                if (amount > capacityPerLayer) {
                    for (Direction direction : Plane.HORIZONTAL) {
                        // state and model must contain that direction
                        FluidCuboid cuboid = model.getFluid(direction);
                        if (cuboid != null && state.get(CisternBlock.CONNECTIONS.get(direction))) {
                            FluidRenderer.renderCuboid(matrices, builder, cuboid, still, flowing, cuboid.getFromScaled(), cuboid.getToScaled(), color, light, false);
                        }
                    }
                } else {
                    // determine the relevant height of the center
                    FluidCuboid center = model.getCenterFluid(state.get(CisternBlock.EXTENSION));
                    Vector3f from = center.getFromScaled();
                    Vector3f to = center.getToScaled().copy();
                    float minY = from.getY();
                    to.setY(minY + amount * (to.getY() - minY) / (float) capacityPerLayer);
                    // render the center using Mantle's logic
                    FluidRenderer.renderCuboid(matrices, builder, center, still, still, from, to, color, light, false);
                    // scale the sides based on the center
                    for (Direction direction : Plane.HORIZONTAL) {
                        // state and model must contain that direction
                        FluidCuboid cuboid = model.getFluid(direction);
                        if (cuboid != null && state.get(CisternBlock.CONNECTIONS.get(direction))) {
                            // bottom of the side must be smaller than the height to consider
                            Vector3f sFrom = cuboid.getFromScaled();
                            if (sFrom.getY() < to.getY()) {
                                // if the side end is larger than the center, clamp it down
                                Vector3f sTo = cuboid.getToScaled();
                                if (sTo.getY() > to.getY()) {
                                    sTo = sTo.copy();
                                    sTo.setY(to.getY());
                                }
                                FluidRenderer.renderCuboid(matrices, builder, cuboid, still, still, sFrom, sTo, color, light, false);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : CisternModel(knightminer.ceramics.client.model.CisternModel) BlockState(net.minecraft.block.BlockState) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) FluidStack(net.minecraftforge.fluids.FluidStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(net.minecraft.util.math.vector.Vector3f) Direction(net.minecraft.util.Direction) FluidCuboid(slimeknights.mantle.client.model.fluid.FluidCuboid) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 2 with FluidCuboid

use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.

the class ChannelTileEntityRenderer method render.

@Override
public void render(ChannelTileEntity te, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int light, int combinedOverlayIn) {
    FluidStack fluid = te.getFluid();
    if (fluid.isEmpty()) {
        return;
    }
    // fetch model properties
    World world = te.getWorld();
    if (world == null) {
        return;
    }
    BlockPos pos = te.getPos();
    BlockState state = te.getBlockState();
    ChannelModel.BakedModel model = ModelHelper.getBakedModel(state, ChannelModel.BakedModel.class);
    if (model == null) {
        return;
    }
    // fluid attributes
    FluidAttributes attributes = fluid.getFluid().getAttributes();
    TextureAtlasSprite still = FluidRenderer.getBlockSprite(attributes.getStillTexture(fluid));
    TextureAtlasSprite flowing = FluidRenderer.getBlockSprite(attributes.getFlowingTexture(fluid));
    IVertexBuilder builder = buffer.getBuffer(FluidRenderer.RENDER_TYPE);
    int color = attributes.getColor(fluid);
    light = FluidRenderer.withBlockLight(light, attributes.getLuminosity(fluid));
    // render sides first, while doing so we will determine center "flow"
    FluidCuboid cube;
    boolean isRotated;
    Direction centerFlow = Direction.UP;
    for (Direction direction : Plane.HORIZONTAL) {
        // check if we have that side on the block
        ChannelConnection connection = state.get(ChannelBlock.DIRECTION_MAP.get(direction));
        if (connection.canFlow()) {
            // apply rotation for the side
            isRotated = RenderingHelper.applyRotation(matrices, direction);
            // get the relevant fluid model, render it
            if (te.isFlowing(direction)) {
                cube = model.getSideFlow(connection == ChannelConnection.OUT);
                // add to center direction
                if (connection == ChannelConnection.OUT) {
                    // if unset (up), use this direction
                    if (centerFlow == Direction.UP) {
                        centerFlow = direction;
                    // if set and it disagrees, set the fail state (down)
                    } else if (centerFlow != direction) {
                        centerFlow = Direction.DOWN;
                    }
                }
                // render the extra edge against other blocks
                if (!world.getBlockState(pos.offset(direction)).isIn(state.getBlock())) {
                    FluidRenderer.renderCuboid(matrices, builder, model.getSideEdge(), 0, still, flowing, color, light, false);
                }
            } else {
                cube = model.getSideStill();
            }
            FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
            // undo rotation
            if (isRotated) {
                matrices.pop();
            }
        }
    }
    // render center
    isRotated = false;
    if (centerFlow.getAxis().isVertical()) {
        cube = model.getCenterFluid(false);
    } else {
        cube = model.getCenterFluid(true);
        isRotated = RenderingHelper.applyRotation(matrices, centerFlow);
    }
    // render the cube and pop back
    FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
    if (isRotated) {
        matrices.pop();
    }
    // render flow downwards
    if (state.get(ChannelBlock.DOWN) && te.isFlowing(Direction.DOWN)) {
        cube = model.getDownFluid();
        FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
        // render into the block(s) below
        FaucetFluidLoader.renderFaucetFluids(world, pos, Direction.DOWN, matrices, builder, still, flowing, color, light);
    }
}
Also used : FluidAttributes(net.minecraftforge.fluids.FluidAttributes) FluidStack(net.minecraftforge.fluids.FluidStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) World(net.minecraft.world.World) FluidCuboid(slimeknights.mantle.client.model.fluid.FluidCuboid) Direction(net.minecraft.util.Direction) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) BlockState(net.minecraft.block.BlockState) ChannelModel(knightminer.ceramics.client.model.ChannelModel) BlockPos(net.minecraft.util.math.BlockPos) ChannelConnection(knightminer.ceramics.blocks.ChannelBlock.ChannelConnection)

Example 3 with FluidCuboid

use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.

the class FaucetTileEntityRenderer method render.

@Override
public void render(FaucetTileEntity tileEntity, float partialTicks, MatrixStack matrices, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
    FluidStack renderFluid = tileEntity.getRenderFluid();
    if (!tileEntity.isPouring() || renderFluid.isEmpty()) {
        return;
    }
    // safety
    World world = tileEntity.getWorld();
    if (world == null) {
        return;
    }
    // fetch faucet model to determine where to render fluids
    BlockState state = tileEntity.getBlockState();
    FluidsModel.BakedModel model = ModelHelper.getBakedModel(state, FluidsModel.BakedModel.class);
    if (model != null) {
        // if side, rotate fluid model
        Direction direction = state.get(FaucetBlock.FACING);
        boolean isRotated = RenderingHelper.applyRotation(matrices, direction);
        // fluid props
        FluidAttributes attributes = renderFluid.getFluid().getAttributes();
        int color = attributes.getColor(renderFluid);
        Function<ResourceLocation, TextureAtlasSprite> spriteGetter = Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
        TextureAtlasSprite still = spriteGetter.apply(attributes.getStillTexture(renderFluid));
        TextureAtlasSprite flowing = spriteGetter.apply(attributes.getFlowingTexture(renderFluid));
        boolean isGas = attributes.isGaseous(renderFluid);
        combinedLightIn = FluidRenderer.withBlockLight(combinedLightIn, attributes.getLuminosity(renderFluid));
        // render all cubes in the model
        IVertexBuilder buffer = bufferIn.getBuffer(FluidRenderer.RENDER_TYPE);
        for (FluidCuboid cube : model.getFluids()) {
            FluidRenderer.renderCuboid(matrices, buffer, cube, 0, still, flowing, color, combinedLightIn, isGas);
        }
        // render into the block(s) below
        FaucetFluidLoader.renderFaucetFluids(world, tileEntity.getPos(), direction, matrices, buffer, still, flowing, color, combinedLightIn);
        // if rotated, pop back rotation
        if (isRotated) {
            matrices.pop();
        }
    }
}
Also used : FluidsModel(slimeknights.mantle.client.model.fluid.FluidsModel) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) FluidStack(net.minecraftforge.fluids.FluidStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) FluidCuboid(slimeknights.mantle.client.model.fluid.FluidCuboid) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) BlockState(net.minecraft.block.BlockState) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)3 BlockState (net.minecraft.block.BlockState)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 Direction (net.minecraft.util.Direction)3 FluidAttributes (net.minecraftforge.fluids.FluidAttributes)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 FluidCuboid (slimeknights.mantle.client.model.fluid.FluidCuboid)3 World (net.minecraft.world.World)2 ChannelConnection (knightminer.ceramics.blocks.ChannelBlock.ChannelConnection)1 ChannelModel (knightminer.ceramics.client.model.ChannelModel)1 CisternModel (knightminer.ceramics.client.model.CisternModel)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3f (net.minecraft.util.math.vector.Vector3f)1 FluidsModel (slimeknights.mantle.client.model.fluid.FluidsModel)1