Search in sources :

Example 1 with CuboidRayTraceResult

use of codechicken.lib.raytracer.CuboidRayTraceResult in project GregTech by GregTechCE.

the class BlockPipe method onBlockClicked.

@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);
    }
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 2 with CuboidRayTraceResult

use of codechicken.lib.raytracer.CuboidRayTraceResult in project GregTech by GregTechCE.

the class MultiblockInfoRecipeWrapper method drawInfo.

@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
    WorldSceneRenderer renderer = getCurrentRenderer();
    int sceneHeight = recipeHeight - PARTS_HEIGHT;
    renderer.render(recipeLayout.getPosX(), recipeLayout.getPosY(), recipeWidth, sceneHeight, 0xC6C6C6);
    drawMultiblockName(recipeWidth);
    // reset colors (so any elements render after this point are not dark)
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    this.infoIcon.draw(minecraft, recipeWidth - (ICON_SIZE + RIGHT_PADDING), 49);
    for (int i = 0; i < MAX_PARTS; ++i) {
        this.slot.draw(minecraft, SLOT_SIZE * i - (SLOTS_PER_ROW * SLOT_SIZE) * (i / SLOTS_PER_ROW), sceneHeight + SLOT_SIZE * (i / SLOTS_PER_ROW));
    }
    // the button by mousing over it, leaks into other gui elements?
    for (GuiButton button : buttons.keySet()) {
        button.drawButton(minecraft, mouseX, mouseY, 0.0f);
    }
    drawHoveringInformationText(minecraft, infoPage.informationText(), mouseX, mouseY);
    this.tooltipBlockStack = null;
    BlockPos pos = renderer.getLastHitBlock();
    boolean insideView = mouseX >= 0 && mouseY >= 0 && mouseX < recipeWidth && mouseY < sceneHeight;
    boolean leftClickHeld = Mouse.isButtonDown(0);
    boolean rightClickHeld = Mouse.isButtonDown(1);
    boolean isHoldingShift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
    if (insideView) {
        if (leftClickHeld) {
            if (isHoldingShift) {
                int mouseDeltaY = mouseY - lastMouseY;
                this.rotationPitch += mouseDeltaY * 2.0f;
            } else {
                int mouseDeltaX = mouseX - lastMouseX;
                this.rotationYaw += mouseDeltaX * 2.0f;
            }
        } else if (rightClickHeld) {
            int mouseDeltaY = mouseY - lastMouseY;
            if (isHoldingShift) {
                this.zoom *= Math.pow(1.05d, -mouseDeltaY);
            } else {
                int mouseDeltaX = mouseX - lastMouseX;
                this.panX -= mouseDeltaX / 2.0f;
                this.panY -= mouseDeltaY / 2.0f;
            }
        }
    }
    if (!(leftClickHeld || rightClickHeld) && pos != null && !renderer.world.isAirBlock(pos)) {
        IBlockState blockState = renderer.world.getBlockState(pos);
        RayTraceResult result = new CuboidRayTraceResult(new Vector3(0.5, 0.5, 0.5).add(pos), pos, EnumFacing.UP, new IndexedCuboid6(null, Cuboid6.full), 1.0);
        ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, result, renderer.world, pos, minecraft.player);
        if (itemStack != null && !itemStack.isEmpty()) {
            this.tooltipBlockStack = itemStack;
        }
    }
    this.lastMouseX = mouseX;
    this.lastMouseY = mouseY;
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) IBlockState(net.minecraft.block.state.IBlockState) GuiButton(net.minecraft.client.gui.GuiButton) IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) RayTraceResult(net.minecraft.util.math.RayTraceResult) CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Vector3(codechicken.lib.vec.Vector3) WorldSceneRenderer(gregtech.api.render.scene.WorldSceneRenderer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CuboidRayTraceResult

use of codechicken.lib.raytracer.CuboidRayTraceResult in project GregTech by GregTechCE.

the class BlockMachine method onBlockClicked.

@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);
    }
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 4 with CuboidRayTraceResult

use of codechicken.lib.raytracer.CuboidRayTraceResult in project GregTech by GregTechCE.

the class BlockMachine method onBlockActivated.

@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_WRENCH, false);
            return true;
        }
        return false;
    }
    return metaTileEntity.onCoverRightClick(playerIn, hand, rayTraceResult);
}
Also used : IScrewdriverItem(gregtech.api.capability.tool.IScrewdriverItem) CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) IWrenchItem(gregtech.api.capability.tool.IWrenchItem) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 5 with CuboidRayTraceResult

use of codechicken.lib.raytracer.CuboidRayTraceResult in project GregTech by GregTechCE.

the class BlockPipe method onBlockActivated.

@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);
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult)

Aggregations

CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)6 CoverBehavior (gregtech.api.cover.CoverBehavior)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 ItemStack (net.minecraft.item.ItemStack)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 Vector3 (codechicken.lib.vec.Vector3)1 IScrewdriverItem (gregtech.api.capability.tool.IScrewdriverItem)1 IWrenchItem (gregtech.api.capability.tool.IWrenchItem)1 CoverSideData (gregtech.api.cover.ICoverable.CoverSideData)1 WorldSceneRenderer (gregtech.api.render.scene.WorldSceneRenderer)1 IBlockState (net.minecraft.block.state.IBlockState)1 GuiButton (net.minecraft.client.gui.GuiButton)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1