Search in sources :

Example 1 with CoverSideData

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

the class BlockPipe method onPipeActivated.

public boolean onPipeActivated(EntityPlayer entityPlayer, EnumHand hand, CuboidRayTraceResult hit, IPipeTile<PipeType, NodeDataType> pipeTile) {
    ItemStack itemStack = entityPlayer.getHeldItem(hand);
    EnumFacing coverSide = ICoverable.traceCoverSide(hit);
    if (coverSide == null)
        return false;
    if (!(hit.cuboid6.data instanceof CoverSideData)) {
        IWrenchItem wrenchItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_WRENCH, null);
        if (wrenchItem != null) {
            if (wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true)) {
                if (!entityPlayer.world.isRemote) {
                    boolean isBlocked = pipeTile.isConnectionBlocked(AttachmentType.PIPE, coverSide);
                    pipeTile.setConnectionBlocked(AttachmentType.PIPE, coverSide, !isBlocked);
                    wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, false);
                }
                return true;
            }
            return false;
        }
    }
    CoverBehavior coverBehavior = pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);
    if (coverBehavior == null)
        return false;
    IScrewdriverItem screwdriver = itemStack.getCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null);
    if (screwdriver != null) {
        if (screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) && coverBehavior.onScrewdriverClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS) {
            screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
            return true;
        }
        return false;
    }
    return coverBehavior.onRightClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS;
}
Also used : IScrewdriverItem(gregtech.api.capability.tool.IScrewdriverItem) IWrenchItem(gregtech.api.capability.tool.IWrenchItem) CoverSideData(gregtech.api.cover.ICoverable.CoverSideData) ItemStack(net.minecraft.item.ItemStack) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 2 with CoverSideData

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

the class BlockPipe method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return ItemStack.EMPTY;
    }
    if (target instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult result = (CuboidRayTraceResult) target;
        if (result.cuboid6.data instanceof CoverSideData) {
            EnumFacing coverSide = ((CoverSideData) result.cuboid6.data).side;
            CoverBehavior coverBehavior = pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);
            return coverBehavior == null ? ItemStack.EMPTY : coverBehavior.getPickItem();
        }
    }
    return getDropItem(pipeTile);
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) CoverSideData(gregtech.api.cover.ICoverable.CoverSideData) CoverBehavior(gregtech.api.cover.CoverBehavior)

Aggregations

CoverBehavior (gregtech.api.cover.CoverBehavior)2 CoverSideData (gregtech.api.cover.ICoverable.CoverSideData)2 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)1 IScrewdriverItem (gregtech.api.capability.tool.IScrewdriverItem)1 IWrenchItem (gregtech.api.capability.tool.IWrenchItem)1 ItemStack (net.minecraft.item.ItemStack)1