Search in sources :

Example 1 with IDrillHead

use of blusunrize.immersiveengineering.api.tool.IDrillHead in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method renderAdditionalBlockBounds.

@SubscribeEvent()
public void renderAdditionalBlockBounds(DrawBlockHighlightEvent event) {
    if (event.getSubID() == 0 && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) {
        float f1 = 0.002F;
        double px = -TileEntityRendererDispatcher.staticPlayerX;
        double py = -TileEntityRendererDispatcher.staticPlayerY;
        double pz = -TileEntityRendererDispatcher.staticPlayerZ;
        TileEntity tile = event.getPlayer().worldObj.getTileEntity(event.getTarget().getBlockPos());
        ItemStack stack = event.getPlayer().getHeldItem(EnumHand.MAIN_HAND);
        //			if(event.getPlayer().worldObj.getBlockState(event.getTarget().getBlockPos()).getBlock() instanceof IEBlockInterfaces.ICustomBoundingboxes)
        if (tile instanceof IAdvancedSelectionBounds) {
            //				IEBlockInterfaces.ICustomBoundingboxes block = (IEBlockInterfaces.ICustomBoundingboxes) event.getPlayer().worldObj.getBlockState(event.getTarget().getBlockPos()).getBlock();
            IAdvancedSelectionBounds iasb = (IAdvancedSelectionBounds) tile;
            List<AxisAlignedBB> boxes = iasb.getAdvancedSelectionBounds();
            if (boxes != null && !boxes.isEmpty()) {
                GlStateManager.enableBlend();
                GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
                GlStateManager.glLineWidth(2.0F);
                GlStateManager.disableTexture2D();
                GlStateManager.depthMask(false);
                ArrayList<AxisAlignedBB> additionalBoxes = new ArrayList<AxisAlignedBB>();
                AxisAlignedBB overrideBox = null;
                for (AxisAlignedBB aabb : boxes) if (aabb != null) {
                    if (iasb.isOverrideBox(aabb, event.getPlayer(), event.getTarget(), additionalBoxes))
                        overrideBox = aabb;
                }
                if (overrideBox != null)
                    RenderGlobal.func_189697_a(overrideBox.expand(f1, f1, f1).offset(px, py, pz), 0, 0, 0, 0.4f);
                else
                    for (AxisAlignedBB aabb : additionalBoxes.isEmpty() ? boxes : additionalBoxes) RenderGlobal.func_189697_a(aabb.expand(f1, f1, f1).offset(px, py, pz), 0, 0, 0, 0.4f);
                GlStateManager.depthMask(true);
                GlStateManager.enableTexture2D();
                GlStateManager.disableBlend();
                event.setCanceled(true);
            }
        }
        if (Utils.isHammer(stack) && tile instanceof TileEntityTurntable) {
            BlockPos pos = event.getTarget().getBlockPos();
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.glLineWidth(2.0F);
            GlStateManager.disableTexture2D();
            GlStateManager.depthMask(false);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer vertexbuffer = tessellator.getBuffer();
            EnumFacing f = ((TileEntityTurntable) tile).getFacing();
            double tx = pos.getX() + .5;
            double ty = pos.getY() + .5;
            double tz = pos.getZ() + .5;
            if (!event.getPlayer().worldObj.isAirBlock(pos.offset(f))) {
                tx += f.getFrontOffsetX();
                ty += f.getFrontOffsetY();
                tz += f.getFrontOffsetZ();
            }
            vertexbuffer.setTranslation(tx + px, ty + py, tz + pz);
            double angle = -event.getPlayer().ticksExisted % 80 / 40d * Math.PI;
            drawRotationArrows(tessellator, vertexbuffer, f, angle, ((TileEntityTurntable) tile).invert);
            vertexbuffer.setTranslation(0, 0, 0);
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
        World world = event.getPlayer().worldObj;
        if (stack != null && IEContent.blockConveyor.equals(Block.getBlockFromItem(stack.getItem())) && event.getTarget().sideHit.getAxis() == Axis.Y) {
            EnumFacing side = event.getTarget().sideHit;
            BlockPos pos = event.getTarget().getBlockPos();
            AxisAlignedBB targetedBB = world.getBlockState(pos).getSelectedBoundingBox(world, pos);
            if (targetedBB != null)
                targetedBB = targetedBB.offset(-pos.getX(), -pos.getY(), -pos.getZ());
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.glLineWidth(2.0F);
            GlStateManager.disableTexture2D();
            GlStateManager.depthMask(false);
            Tessellator tessellator = Tessellator.getInstance();
            VertexBuffer vertexbuffer = tessellator.getBuffer();
            vertexbuffer.setTranslation(pos.getX() + px, pos.getY() + py, pos.getZ() + pz);
            double[][] points = new double[4][];
            if (side.getAxis() == Axis.Y) {
                points[0] = new double[] { 0 - f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 0 - f1 };
                points[1] = new double[] { 1 + f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 1 + f1 };
                points[2] = new double[] { 0 - f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 1 + f1 };
                points[3] = new double[] { 1 + f1, side == EnumFacing.DOWN ? ((targetedBB != null ? targetedBB.minY : 0) - f1) : ((targetedBB != null ? targetedBB.maxY : 1) + f1), 0 - f1 };
            } else if (side.getAxis() == Axis.Z) {
                points[0] = new double[] { 1 + f1, 1 + f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
                points[1] = new double[] { 0 - f1, 0 - f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
                points[2] = new double[] { 0 - f1, 1 + f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
                points[3] = new double[] { 1 + f1, 0 - f1, side == EnumFacing.NORTH ? ((targetedBB != null ? targetedBB.minZ : 0) - f1) : ((targetedBB != null ? targetedBB.maxZ : 1) + f1) };
            } else {
                points[0] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 1 + f1, 1 + f1 };
                points[1] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 0 - f1, 0 - f1 };
                points[2] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 1 + f1, 0 - f1 };
                points[3] = new double[] { side == EnumFacing.WEST ? ((targetedBB != null ? targetedBB.minX : 0) - f1) : ((targetedBB != null ? targetedBB.maxX : 1) + f1), 0 - f1, 1 + f1 };
            }
            vertexbuffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
            for (double[] point : points) vertexbuffer.pos(point[0], point[1], point[2]).color(0, 0, 0, 0.4F).endVertex();
            tessellator.draw();
            vertexbuffer.begin(2, DefaultVertexFormats.POSITION_COLOR);
            vertexbuffer.pos(points[0][0], points[0][1], points[0][2]).color(0, 0, 0, 0.4F).endVertex();
            vertexbuffer.pos(points[2][0], points[2][1], points[2][2]).color(0, 0, 0, 0.4F).endVertex();
            vertexbuffer.pos(points[1][0], points[1][1], points[1][2]).color(0, 0, 0, 0.4F).endVertex();
            vertexbuffer.pos(points[3][0], points[3][1], points[3][2]).color(0, 0, 0, 0.4F).endVertex();
            tessellator.draw();
            float xFromMid = side.getAxis() == Axis.X ? 0 : (float) event.getTarget().hitVec.xCoord - pos.getX() - .5f;
            float yFromMid = side.getAxis() == Axis.Y ? 0 : (float) event.getTarget().hitVec.yCoord - pos.getY() - .5f;
            float zFromMid = side.getAxis() == Axis.Z ? 0 : (float) event.getTarget().hitVec.zCoord - pos.getZ() - .5f;
            float max = Math.max(Math.abs(yFromMid), Math.max(Math.abs(xFromMid), Math.abs(zFromMid)));
            Vec3d dir = new Vec3d(max == Math.abs(xFromMid) ? Math.signum(xFromMid) : 0, max == Math.abs(yFromMid) ? Math.signum(yFromMid) : 0, max == Math.abs(zFromMid) ? Math.signum(zFromMid) : 0);
            if (dir != null)
                drawBlockOverlayArrow(tessellator, vertexbuffer, dir, side, targetedBB);
            vertexbuffer.setTranslation(0, 0, 0);
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
        if (stack != null && stack.getItem() instanceof ItemDrill && ((ItemDrill) stack.getItem()).isEffective(world.getBlockState(event.getTarget().getBlockPos()).getMaterial())) {
            ItemStack head = ((ItemDrill) stack.getItem()).getHead(stack);
            if (head != null) {
                ImmutableList<BlockPos> blocks = ((IDrillHead) head.getItem()).getExtraBlocksDug(head, world, event.getPlayer(), event.getTarget());
                drawAdditionalBlockbreak(event.getContext(), event.getPlayer(), event.getPartialTicks(), blocks);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IDrillHead(blusunrize.immersiveengineering.api.tool.IDrillHead) TileEntityTurntable(blusunrize.immersiveengineering.common.blocks.wooden.TileEntityTurntable) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) IAdvancedSelectionBounds(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedSelectionBounds) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IDrillHead

use of blusunrize.immersiveengineering.api.tool.IDrillHead in project ImmersiveEngineering by BluSunrize.

the class ItemDrill method onBlockDestroyed.

@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase living) {
    if ((double) state.getBlockHardness(world, pos) != 0.0D) {
        int dmg = ForgeHooks.isToolEffective(world, pos, stack) ? 1 : 3;
        ItemStack head = getHead(stack);
        if (head != null) {
            if (living instanceof EntityPlayer) {
                if (((EntityPlayer) living).capabilities.isCreativeMode)
                    return true;
                ((IDrillHead) head.getItem()).afterBlockbreak(stack, head, (EntityPlayer) living);
            }
            ((IDrillHead) head.getItem()).damageHead(head, dmg);
            this.setHead(stack, head);
            IFluidHandler handler = FluidUtil.getFluidHandler(stack);
            handler.drain(1, true);
        }
    }
    return true;
}
Also used : IDrillHead(blusunrize.immersiveengineering.api.tool.IDrillHead) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 3 with IDrillHead

use of blusunrize.immersiveengineering.api.tool.IDrillHead in project ImmersiveEngineering by BluSunrize.

the class ItemDrill method onBlockStartBreak.

@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos iPos, EntityPlayer player) {
    World world = player.worldObj;
    if (player.isSneaking() || world.isRemote || !(player instanceof EntityPlayerMP))
        return false;
    RayTraceResult mop = this.rayTrace(world, player, true);
    ItemStack head = getHead(stack);
    if (mop == null || head == null || this.isDrillBroken(stack))
        return false;
    //		EnumFacing side = mop.sideHit;
    //		int diameter = ((IDrillHead)head.getItem()).getMiningSize(head)+getUpgrades(stack).getInteger("size");
    //		int depth = ((IDrillHead)head.getItem()).getMiningDepth(head)+getUpgrades(stack).getInteger("depth");
    //
    //		BlockPos startPos=iPos;
    //		if(diameter%2==0)//even numbers
    //		{
    //			float hx = (float)mop.hitVec.xCoord-iPos.getX();
    //			float hy = (float)mop.hitVec.yCoord-iPos.getY();
    //			float hz = (float)mop.hitVec.zCoord-iPos.getZ();
    //			if((side.getAxis()==Axis.Y&&hx<.5)||(side.getAxis()==Axis.Z&&hx<.5))
    //				startPos.add(-diameter/2,0,0);
    //			if(side.getAxis()!=Axis.Y&&hy<.5)
    //				startPos.add(0,-diameter/2,0);
    //			if((side.getAxis()==Axis.Y&&hz<.5)||(side.getAxis()==Axis.X&&hz<.5))
    //				startPos.add(0,0,-diameter/2);
    //		}
    //		else//odd numbers
    //		{
    //			startPos.add(-(side.getAxis()==Axis.X?0: diameter/2), -(side.getAxis()==Axis.Y?0: diameter/2), -(side.getAxis()==Axis.Z?0: diameter/2));
    //		}
    //
    //		for(int dd=0; dd<depth; dd++)
    //			for(int dw=0; dw<diameter; dw++)
    //				for(int dh=0; dh<diameter; dh++)
    //				{
    //					BlockPos pos = startPos.add((side.getAxis()==Axis.X?dd: dw), (side.getAxis()==Axis.Y?dd: dh), (side.getAxis()==Axis.Y?dh: side.getAxis()==Axis.X?dw: dd));
    //					if(pos.equals(iPos))
    //						continue;
    ImmutableList<BlockPos> additional = ((IDrillHead) head.getItem()).getExtraBlocksDug(head, world, player, mop);
    for (BlockPos pos : additional) {
        if (!world.isBlockLoaded(pos))
            continue;
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        if (block != null && !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) != 0) {
            if (!this.canBreakExtraBlock(world, block, pos, state, player, stack, head, true))
                continue;
            int xpDropEvent = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
            if (xpDropEvent < 0)
                continue;
            if (player.capabilities.isCreativeMode) {
                block.onBlockHarvested(world, pos, state, player);
                if (block.removedByPlayer(state, world, pos, player, false))
                    block.onBlockDestroyedByPlayer(world, pos, state);
            } else {
                block.onBlockHarvested(world, pos, state, player);
                TileEntity te = world.getTileEntity(pos);
                //implicitly damages head
                stack.onBlockDestroyed(world, state, pos, player);
                if (block.removedByPlayer(state, world, pos, player, true)) {
                    block.onBlockDestroyedByPlayer(world, pos, state);
                    block.harvestBlock(world, player, pos, state, te, stack);
                    block.dropXpOnBlockBreak(world, pos, xpDropEvent);
                }
            }
            world.playEvent(2001, pos, Block.getStateId(state));
            ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
        }
    }
    return false;
}
Also used : IDrillHead(blusunrize.immersiveengineering.api.tool.IDrillHead) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

IDrillHead (blusunrize.immersiveengineering.api.tool.IDrillHead)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 IAdvancedSelectionBounds (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedSelectionBounds)1 TileEntityTurntable (blusunrize.immersiveengineering.common.blocks.wooden.TileEntityTurntable)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1