Java Code Examples for codechicken.lib.raytracer.RayTracer#retraceBlock()

The following examples show how to use codechicken.lib.raytracer.RayTracer#retraceBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockTranslocator.java    From Translocators with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (world.isRemote)
        return true;

    MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
    TileTranslocator ttrans = (TileTranslocator) world.getTileEntity(x, y, z);

    if (hit != null) {
        if (hit.subHit < 6) {
            Vector3 vhit = new Vector3(hit.hitVec);
            vhit.add(-x - 0.5, -y - 0.5, -z - 0.5);
            vhit.apply(sideRotations[hit.subHit % 6].inverse());
            if (MathHelper.between(-2 / 16D, vhit.x, 2 / 16D) && MathHelper.between(-2 / 16D, vhit.z, 2 / 16D))
                hit.subHit += 6;
        }

        return ttrans.attachments[hit.subHit % 6].activate(player, hit.subHit / 6);
    }

    return false;
}
 
Example 2
Source File: BlockMachine.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    ItemStack itemStack = playerIn.getHeldItem(hand);
    if (metaTileEntity == null || rayTraceResult == null) {
        return false;
    }

    if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null)) {
        IScrewdriverItem screwdriver = itemStack.getCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null);

        if (screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) &&
            metaTileEntity.onCoverScrewdriverClick(playerIn, hand, rayTraceResult)) {
            screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
            return true;
        }
        return false;
    }

    if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_WRENCH, null)) {
        IWrenchItem wrenchItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_WRENCH, null);
        EnumFacing wrenchDirection = ICoverable.determineGridSideHit(rayTraceResult);

        if (wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true) &&
            metaTileEntity.onWrenchClick(playerIn, hand, wrenchDirection, rayTraceResult)) {
            wrenchItem.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
            return true;
        }
        return false;
    }

    return metaTileEntity.onCoverRightClick(playerIn, hand, rayTraceResult);
}
 
Example 3
Source File: BlockMachine.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    if (metaTileEntity == null) return;
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    if (rayTraceResult != null) {
        metaTileEntity.onCoverLeftClick(playerIn, rayTraceResult);
    }
}
 
Example 4
Source File: ICoverable.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
static EnumFacing rayTraceCoverableSide(ICoverable coverable, EntityPlayer player) {
    RayTraceResult result = RayTracer.retraceBlock(coverable.getWorld(), player, coverable.getPos());
    if (result == null || result.typeOfHit != Type.BLOCK) {
        return null;
    }
    return traceCoverSide(result);
}
 
Example 5
Source File: BlockPipe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(worldIn, pos);
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    if (rayTraceResult == null || pipeTile == null) {
        return false;
    }
    return onPipeActivated(playerIn, hand, rayTraceResult, pipeTile);
}
 
Example 6
Source File: BlockPipe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(worldIn, pos);
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    if (pipeTile == null || rayTraceResult == null) {
        return;
    }
    EnumFacing coverSide = ICoverable.traceCoverSide(rayTraceResult);
    CoverBehavior coverBehavior = coverSide == null ? null : pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);

    if (coverBehavior != null) {
        coverBehavior.onLeftClick(playerIn, rayTraceResult);
    }
}
 
Example 7
Source File: BlockCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (world.isRemote)
        return true;

    MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
    TileCraftingGrid tcraft = (TileCraftingGrid) world.getTileEntity(x, y, z);

    if (hit != null) {
        if (hit.subHit > 0)
            tcraft.activate(hit.subHit - 1, player);
        return true;
    }
    return false;
}
 
Example 8
Source File: BlockTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willharvest) {
    MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
    if (hit == null)
        return false;

    TileTranslocator ttrans = (TileTranslocator) world.getTileEntity(x, y, z);
    return ttrans.harvestPart(hit.subHit % 6, !player.capabilities.isCreativeMode);
}
 
Example 9
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static EnumFacing getSideHit(World world, BlockPos blockPos, EntityPlayer harvester) {
    RayTraceResult result = RayTracer.retraceBlock(world, harvester, blockPos);
    return result == null ? harvester.getHorizontalFacing() : result.sideHit;
}
 
Example 10
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}
 
Example 11
Source File: BlockCraftingGrid.java    From Translocators with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}
 
Example 12
Source File: BlockTranslocator.java    From Translocators with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}