Search in sources :

Example 1 with ICoverable

use of gregtech.api.cover.ICoverable in project GregTech by GregTechCE.

the class CableRenderer 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);
    IVertexOperation[] pipeline = { new Translation(pos) };
    BlockCable blockCable = (BlockCable) state.getBlock();
    TileEntityCable tileEntityCable = (TileEntityCable) blockCable.getPipeTileEntity(world, pos);
    if (tileEntityCable == null)
        return false;
    int paintingColor = tileEntityCable.getInsulationColor();
    int connectedSidesMask = blockCable.getActualConnections(tileEntityCable, world);
    Insulation insulation = tileEntityCable.getPipeType();
    Material material = tileEntityCable.getPipeMaterial();
    if (insulation != null && material != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
        if (renderLayer == BlockRenderLayer.CUTOUT) {
            renderCableBlock(material, insulation, paintingColor, renderState, pipeline, connectedSidesMask);
        }
        ICoverable coverable = tileEntityCable.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
Also used : IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) Insulation(gregtech.common.pipelike.cable.Insulation) ICoverable(gregtech.api.cover.ICoverable) Translation(codechicken.lib.vec.Translation) TileEntityCable(gregtech.common.pipelike.cable.tile.TileEntityCable) Material(gregtech.api.unification.material.type.Material) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) CCRenderState(codechicken.lib.render.CCRenderState) ItemBlockCable(gregtech.common.pipelike.cable.ItemBlockCable) BlockCable(gregtech.common.pipelike.cable.BlockCable) Matrix4(codechicken.lib.vec.Matrix4)

Example 2 with ICoverable

use of gregtech.api.cover.ICoverable in project GregTech by GregTechCE.

the class FluidPipeRenderer 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);
    BlockFluidPipe blockPipe = ((BlockFluidPipe) state.getBlock());
    TileEntityFluidPipe tileEntityPipe = (TileEntityFluidPipe) blockPipe.getPipeTileEntity(world, pos);
    if (tileEntityPipe == null) {
        return false;
    }
    FluidPipeType fluidPipeType = tileEntityPipe.getPipeType();
    Material pipeMaterial = tileEntityPipe.getPipeMaterial();
    int paintingColor = tileEntityPipe.getInsulationColor();
    if (fluidPipeType != null && pipeMaterial != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
        if (renderLayer == BlockRenderLayer.CUTOUT) {
            int connectedSidesMask = blockPipe.getActualConnections(tileEntityPipe, world);
            IVertexOperation[] pipeline = new IVertexOperation[] { new Translation(pos) };
            renderPipeBlock(pipeMaterial, fluidPipeType, paintingColor, renderState, pipeline, connectedSidesMask);
        }
        ICoverable coverable = tileEntityPipe.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
Also used : IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) ICoverable(gregtech.api.cover.ICoverable) Translation(codechicken.lib.vec.Translation) ItemBlockFluidPipe(gregtech.common.pipelike.fluidpipe.ItemBlockFluidPipe) BlockFluidPipe(gregtech.common.pipelike.fluidpipe.BlockFluidPipe) FluidPipeType(gregtech.common.pipelike.fluidpipe.FluidPipeType) Material(gregtech.api.unification.material.type.Material) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) CCRenderState(codechicken.lib.render.CCRenderState) TileEntityFluidPipe(gregtech.common.pipelike.fluidpipe.tile.TileEntityFluidPipe) Matrix4(codechicken.lib.vec.Matrix4)

Example 3 with ICoverable

use of gregtech.api.cover.ICoverable in project GregTech by GregTechCE.

the class CoverPlaceBehavior method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
    if (coverable == null) {
        return EnumActionResult.PASS;
    }
    EnumFacing coverSide = ICoverable.rayTraceCoverableSide(coverable, player);
    if (coverable.getCoverAtSide(coverSide) != null || !coverable.canPlaceCoverOnSide(coverSide)) {
        return EnumActionResult.PASS;
    }
    if (!world.isRemote) {
        ItemStack itemStack = player.getHeldItem(hand);
        boolean result = coverable.placeCoverOnSide(coverSide, itemStack, coverDefinition);
        if (result && !player.capabilities.isCreativeMode) {
            itemStack.shrink(1);
        }
        return result ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ICoverable(gregtech.api.cover.ICoverable) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ICoverable

use of gregtech.api.cover.ICoverable in project GregTech by GregTechCE.

the class CrowbarBehaviour method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    IBlockState blockState = world.getBlockState(blockPos);
    if (GTUtility.doDamageItem(stack, cost, true)) {
        if (blockState.getBlock() instanceof BlockRailBase) {
            if (world.isRemote) {
                // always return success on client side
                return EnumActionResult.SUCCESS;
            } else if (player.isSneaking()) {
                if (tryBreakRailBlock(blockState, world, blockPos, player)) {
                    GTUtility.doDamageItem(stack, cost, false);
                    return EnumActionResult.SUCCESS;
                }
                return EnumActionResult.FAIL;
            } else {
                if (tryRotateRailBlock(blockState, world, blockPos)) {
                    GTUtility.doDamageItem(stack, cost, false);
                    return EnumActionResult.SUCCESS;
                }
                return EnumActionResult.FAIL;
            }
        }
        TileEntity tileEntity = world.getTileEntity(blockPos);
        ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
        EnumFacing coverSide = coverable == null ? null : ICoverable.rayTraceCoverableSide(coverable, player);
        if (coverSide != null && coverable.getCoverAtSide(coverSide) != null) {
            if (world.isRemote) {
                // always return success on client side
                return EnumActionResult.SUCCESS;
            }
            boolean result = coverable.removeCover(coverSide);
            GTUtility.doDamageItem(stack, cost, false);
            return result ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ICoverable(gregtech.api.cover.ICoverable) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 5 with ICoverable

use of gregtech.api.cover.ICoverable in project GregTech by GregTechCE.

the class BlockPipe method getCollisionBox.

private List<IndexedCuboid6> getCollisionBox(IBlockAccess world, BlockPos pos) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return Collections.emptyList();
    }
    PipeType pipeType = pipeTile.getPipeType();
    if (pipeType == null) {
        return Collections.emptyList();
    }
    int actualConnections = getActualConnections(pipeTile, world);
    float thickness = pipeType.getThickness();
    ArrayList<IndexedCuboid6> result = new ArrayList<>();
    result.add(new IndexedCuboid6(new PrimaryBoxData(false), getSideBox(null, thickness)));
    ICoverable coverable = pipeTile.getCoverableImplementation();
    for (EnumFacing side : EnumFacing.VALUES) {
        if ((actualConnections & 1 << side.getIndex()) > 0) {
            result.add(new IndexedCuboid6(new PipeConnectionData(side), getSideBox(side, thickness)));
        }
    }
    coverable.addCoverCollisionBoundingBox(result);
    return result;
}
Also used : ICoverable(gregtech.api.cover.ICoverable) PrimaryBoxData(gregtech.api.cover.ICoverable.PrimaryBoxData) IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) ArrayList(java.util.ArrayList)

Aggregations

ICoverable (gregtech.api.cover.ICoverable)6 CCRenderState (codechicken.lib.render.CCRenderState)3 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)3 Matrix4 (codechicken.lib.vec.Matrix4)3 Translation (codechicken.lib.vec.Translation)3 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)3 Material (gregtech.api.unification.material.type.Material)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 PrimaryBoxData (gregtech.api.cover.ICoverable.PrimaryBoxData)1 BlockCable (gregtech.common.pipelike.cable.BlockCable)1 Insulation (gregtech.common.pipelike.cable.Insulation)1 ItemBlockCable (gregtech.common.pipelike.cable.ItemBlockCable)1 TileEntityCable (gregtech.common.pipelike.cable.tile.TileEntityCable)1 BlockFluidPipe (gregtech.common.pipelike.fluidpipe.BlockFluidPipe)1 FluidPipeType (gregtech.common.pipelike.fluidpipe.FluidPipeType)1 ItemBlockFluidPipe (gregtech.common.pipelike.fluidpipe.ItemBlockFluidPipe)1 TileEntityFluidPipe (gregtech.common.pipelike.fluidpipe.tile.TileEntityFluidPipe)1