Search in sources :

Example 6 with BlockPipe

use of gregtech.api.pipenet.block.BlockPipe in project GregTech by GregTechCEu.

the class PipeRenderer method renderBlock.

@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);
    BlockPipe<?, ?, ?> blockPipe = (BlockPipe<?, ?, ?>) state.getBlock();
    IPipeTile<?, ?> pipeTile = blockPipe.getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return false;
    }
    IPipeType<?> pipeType = pipeTile.getPipeType();
    Material pipeMaterial = pipeTile instanceof TileEntityMaterialPipeBase ? ((TileEntityMaterialPipeBase<?, ?>) pipeTile).getPipeMaterial() : null;
    int paintingColor = pipeTile.getPaintingColor();
    int connectedSidesMap = pipeTile.getVisualConnections();
    int blockedConnections = pipeTile.getBlockedConnections();
    if (pipeType != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
        boolean[] sideMask = new boolean[EnumFacing.VALUES.length];
        for (EnumFacing side : EnumFacing.VALUES) {
            sideMask[side.getIndex()] = state.shouldSideBeRendered(world, pos, side);
        }
        Textures.RENDER_STATE.set(new CubeRendererState(renderLayer, sideMask, world));
        if (renderLayer == BlockRenderLayer.CUTOUT) {
            renderState.lightMatrix.locate(world, pos);
            PipeRenderContext renderContext = new PipeRenderContext(pos, renderState.lightMatrix, connectedSidesMap, blockedConnections, pipeType.getThickness());
            renderContext.color = GTUtility.convertRGBtoOpaqueRGBA_CL(getPipeColor(pipeMaterial, paintingColor));
            buildRenderer(renderContext, blockPipe, pipeTile, pipeType, pipeMaterial);
            renderPipeBlock(renderState, renderContext);
        }
        ICoverable coverable = pipeTile.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
        Textures.RENDER_STATE.set(null);
    }
    return true;
}
Also used : ICoverable(gregtech.api.cover.ICoverable) EnumFacing(net.minecraft.util.EnumFacing) Material(gregtech.api.unification.material.Material) BlockPipe(gregtech.api.pipenet.block.BlockPipe) ItemBlockPipe(gregtech.api.pipenet.block.ItemBlockPipe) Matrix4(codechicken.lib.vec.Matrix4) CubeRendererState(gregtech.client.renderer.CubeRendererState) TileEntityMaterialPipeBase(gregtech.api.pipenet.block.material.TileEntityMaterialPipeBase) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) CCRenderState(codechicken.lib.render.CCRenderState)

Example 7 with BlockPipe

use of gregtech.api.pipenet.block.BlockPipe in project GregTech by GregTechCEu.

the class PipeRenderer method renderItem.

@Override
public void renderItem(ItemStack rawItemStack, TransformType transformType) {
    ItemStack stack = ModCompatibility.getRealItemStack(rawItemStack);
    if (!(stack.getItem() instanceof ItemBlockPipe)) {
        return;
    }
    CCRenderState renderState = CCRenderState.instance();
    GlStateManager.enableBlend();
    renderState.reset();
    renderState.startDrawing(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
    BlockPipe<?, ?, ?> blockFluidPipe = (BlockPipe<?, ?, ?>) ((ItemBlockPipe<?, ?>) stack.getItem()).getBlock();
    IPipeType<?> pipeType = blockFluidPipe.getItemPipeType(stack);
    Material material = blockFluidPipe instanceof BlockMaterialPipe ? ((BlockMaterialPipe<?, ?, ?>) blockFluidPipe).getItemMaterial(stack) : null;
    if (pipeType != null) {
        // 12 == 0b1100 is North and South connection (index 2 & 3)
        PipeRenderContext renderContext = new PipeRenderContext(12, 0, pipeType.getThickness());
        renderContext.color = GTUtility.convertRGBtoOpaqueRGBA_CL(getPipeColor(material, -1));
        buildRenderer(renderContext, blockFluidPipe, null, pipeType, material);
        renderPipeBlock(renderState, renderContext);
    }
    renderState.draw();
    GlStateManager.disableBlend();
}
Also used : BlockMaterialPipe(gregtech.api.pipenet.block.material.BlockMaterialPipe) ItemBlockPipe(gregtech.api.pipenet.block.ItemBlockPipe) Material(gregtech.api.unification.material.Material) BlockPipe(gregtech.api.pipenet.block.BlockPipe) ItemBlockPipe(gregtech.api.pipenet.block.ItemBlockPipe) ItemStack(net.minecraft.item.ItemStack) CCRenderState(codechicken.lib.render.CCRenderState)

Example 8 with BlockPipe

use of gregtech.api.pipenet.block.BlockPipe in project GregTech by GregTechCEu.

the class PipeRenderer method handleRenderBlockDamage.

@Override
public void handleRenderBlockDamage(IBlockAccess world, BlockPos pos, IBlockState state, TextureAtlasSprite sprite, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
    BlockPipe<?, ?, ?> blockPipe = (BlockPipe<?, ?, ?>) state.getBlock();
    IPipeTile<?, ?> pipeTile = blockPipe.getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return;
    }
    IPipeType<?> pipeType = pipeTile.getPipeType();
    if (pipeType == null) {
        return;
    }
    float thickness = pipeType.getThickness();
    int connectedSidesMask = pipeTile.getConnections();
    Cuboid6 baseBox = BlockItemPipe.getSideBox(null, thickness);
    BlockRenderer.renderCuboid(renderState, baseBox, 0);
    for (EnumFacing renderSide : EnumFacing.VALUES) {
        if ((connectedSidesMask & (1 << renderSide.getIndex())) > 0) {
            Cuboid6 sideBox = BlockItemPipe.getSideBox(renderSide, thickness);
            BlockRenderer.renderCuboid(renderState, sideBox, 0);
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Vector3(codechicken.lib.vec.Vector3) BlockPipe(gregtech.api.pipenet.block.BlockPipe) ItemBlockPipe(gregtech.api.pipenet.block.ItemBlockPipe) CCRenderState(codechicken.lib.render.CCRenderState) Cuboid6(codechicken.lib.vec.Cuboid6) Vec3d(net.minecraft.util.math.Vec3d) IconTransformation(codechicken.lib.vec.uv.IconTransformation)

Aggregations

BlockPipe (gregtech.api.pipenet.block.BlockPipe)8 Block (net.minecraft.block.Block)5 CCRenderState (codechicken.lib.render.CCRenderState)3 ItemBlockPipe (gregtech.api.pipenet.block.ItemBlockPipe)3 Material (gregtech.api.unification.material.Material)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumFacing (net.minecraft.util.EnumFacing)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Matrix4 (codechicken.lib.vec.Matrix4)1 Vector3 (codechicken.lib.vec.Vector3)1 IconTransformation (codechicken.lib.vec.uv.IconTransformation)1 ICoverable (gregtech.api.cover.ICoverable)1 ITieredMetaTileEntity (gregtech.api.metatileentity.ITieredMetaTileEntity)1 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 BlockMaterialPipe (gregtech.api.pipenet.block.material.BlockMaterialPipe)1 TileEntityMaterialPipeBase (gregtech.api.pipenet.block.material.TileEntityMaterialPipeBase)1 IPipeTile (gregtech.api.pipenet.tile.IPipeTile)1 CubeRendererState (gregtech.client.renderer.CubeRendererState)1 ItemBlock (net.minecraft.item.ItemBlock)1