Search in sources :

Example 1 with ChannelConnection

use of knightminer.ceramics.blocks.ChannelBlock.ChannelConnection 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 2 with ChannelConnection

use of knightminer.ceramics.blocks.ChannelBlock.ChannelConnection in project Ceramics by KnightMiner.

the class CisternBlock method isConnected.

/**
 * Check if the given block is something the barrel should connect to
 * @param facing       Side to check
 * @param facingState  Block on side
 * @return  True if connected, false otherwise
 */
protected boolean isConnected(Direction facing, BlockState facingState) {
    // must be in tag
    if (!facingState.isIn(CeramicsTags.Blocks.CISTERN_CONNECTIONS)) {
        return false;
    }
    // if the block has a side property, use that
    Direction opposite = facing.getOpposite();
    BooleanProperty sideProp = CONNECTIONS.get(opposite);
    if (facingState.hasProperty(sideProp)) {
        return facingState.get(sideProp);
    }
    // channel connections
    EnumProperty<ChannelConnection> channelProp = ChannelBlock.DIRECTION_MAP.get(opposite);
    if (facingState.hasProperty(channelProp)) {
        return facingState.get(channelProp) == ChannelConnection.OUT;
    }
    // if there is a face property and it is not wall, not connected
    if (facingState.hasProperty(BlockStateProperties.FACE) && facingState.get(BlockStateProperties.FACE) != AttachFace.WALL) {
        return false;
    }
    // try relevant facing properties, if any are present must be facing this
    return facingConnected(facing, facingState, BlockStateProperties.HORIZONTAL_FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING) && facingConnected(facing, facingState, BlockStateProperties.FACING_EXCEPT_UP);
}
Also used : BooleanProperty(net.minecraft.state.BooleanProperty) ChannelConnection(knightminer.ceramics.blocks.ChannelBlock.ChannelConnection) Direction(net.minecraft.util.Direction)

Aggregations

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