net.minecraftforge.client.event.DrawBlockHighlightEvent Java Examples

The following examples show how to use net.minecraftforge.client.event.DrawBlockHighlightEvent. 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: EventsClient.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onDrawBlockHighlightEventFirst(DrawBlockHighlightEvent event) {
    GL11.glPushMatrix();
    BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils
        .getPhysicsObject(Minecraft.getMinecraft().world, pos);
    if (physicsObject.isPresent()) {
        RayTraceResult objectOver = Minecraft.getMinecraft().objectMouseOver;
        if (objectOver != null && objectOver.hitVec != null) {
            BufferBuilder buffer = Tessellator.getInstance().getBuffer();
            oldXOff = buffer.xOffset;
            oldYOff = buffer.yOffset;
            oldZOff = buffer.zOffset;

            buffer.setTranslation(-physicsObject.get()
                .getShipRenderer().offsetPos.getX(), -physicsObject.get()
                .getShipRenderer().offsetPos.getY(), -physicsObject.get()
                .getShipRenderer().offsetPos.getZ());
            physicsObject.get()
                .getShipRenderer()
                .applyRenderTransform(event.getPartialTicks());
        }
    }
}
 
Example #2
Source File: EventsClient.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void onDrawBlockHighlightEventLast(DrawBlockHighlightEvent event) {
    BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
    Optional<PhysicsObject> physicsObject = ValkyrienUtils
        .getPhysicsObject(Minecraft.getMinecraft().world, pos);
    if (physicsObject.isPresent()) {
        RayTraceResult objectOver = Minecraft.getMinecraft().objectMouseOver;
        if (objectOver != null && objectOver.hitVec != null) {
            BufferBuilder buffer = Tessellator.getInstance().getBuffer();
            buffer.xOffset = oldXOff;
            buffer.yOffset = oldYOff;
            buffer.zOffset = oldZOff;
            // wrapper.wrapping.renderer.inverseTransform(event.getPartialTicks());
            // objectOver.hitVec = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, objectOver.hitVec);
        }
    }
    GL11.glPopMatrix();
}
 
Example #3
Source File: RenderEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onBlockHilight(DrawBlockHighlightEvent event)
{
    RayTraceResult trace = event.getTarget();

    if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK)
    {
        World world = this.mc.world;
        BlockPos pos = trace.getBlockPos();
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();

        if (block == EnderUtilitiesBlocks.PORTAL_PANEL || block == EnderUtilitiesBlocks.INSERTER)
        {
            state = state.getActualState(world, pos);
            this.updatePointedBlockHilight(world, trace.getBlockPos(), state, (BlockEnderUtilities) block, event.getPartialTicks());
        }

        if (block == EnderUtilitiesBlocks.PORTAL_PANEL)
        {
            this.renderPortalPanelText(this.mc.world, trace.getBlockPos(), (BlockEnderUtilities) block, this.mc.player, event.getPartialTicks());
        }
    }
}
 
Example #4
Source File: BlockSelectionHandler.java    From OpenModsLib with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onHighlightDraw(DrawBlockHighlightEvent evt) {
	final RayTraceResult mop = evt.getTarget();

	if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {

		final World world = evt.getPlayer().world;
		final BlockPos blockPos = mop.getBlockPos();
		final Block block = world.getBlockState(blockPos).getBlock();

		if (block instanceof ISelectionAware) {
			final boolean result = ((ISelectionAware)block).onSelected(world, blockPos, evt);
			evt.setCanceled(result);
		}
	}
}
 
Example #5
Source File: WrenchOverlayRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
    EntityPlayer player = event.getPlayer();
    World world = player.world;
    RayTraceResult target = event.getTarget();

    if (target.typeOfHit != RayTraceResult.Type.BLOCK) {
        return; //magically, draw block highlight is called not only for blocks (see forge issues)
    }

    BlockPos pos = target.getBlockPos();
    IBlockState blockState = world.getBlockState(pos);
    TileEntity tileEntity = world.getTileEntity(pos);
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);

    if (tileEntity != null && shouldDrawOverlayForItem(heldItem, tileEntity) && useGridForRayTraceResult(target)) {
        EnumFacing facing = target.sideHit;
        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);

        if (world.getWorldBorder().contains(pos)) {
            double d3 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) event.getPartialTicks();
            double d4 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) event.getPartialTicks();
            double d5 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) event.getPartialTicks();
            AxisAlignedBB box = blockState.getSelectedBoundingBox(world, pos).grow(0.002D).offset(-d3, -d4, -d5);
            RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 0.0F, 0.0F, 0.4F);
            drawOverlayLines(facing, box);
        }

        GlStateManager.depthMask(true);
        GlStateManager.enableTexture2D();
        GlStateManager.disableBlend();

        event.setCanceled(true);
    }
}
 
Example #6
Source File: MOPHelper.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRenderHighlight(DrawBlockHighlightEvent event) {

    if (!(event.target instanceof ExtendedMOP)
            && event.player.worldObj.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ) instanceof TileMultipart)
        event.setCanceled(true);
}
 
Example #7
Source File: BlockSelector.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
public boolean onSelected(World world, int x, int y, int z, DrawBlockHighlightEvent evt) {
	final TileEntitySelector selector = getTileEntity(world, x, y, z, TileEntitySelector.class);

	if (selector != null) {
		final MovingObjectPosition mop = evt.target;
		this.selectorAABB = selector.getSelection(mop.hitVec, mop.sideHit);
	} else this.selectorAABB = null;

	return false;
}
 
Example #8
Source File: EventHandlerRedirect.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void preBlockHighlight(DrawBlockHighlightEvent event) {
    addGoggles(event.player);
}
 
Example #9
Source File: EventHandlerRedirect.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void postBlockHighlight(DrawBlockHighlightEvent event) {
    removeGoggles(event.player);
}
 
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: BlockMoving.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawHighlight(DrawBlockHighlightEvent event) {

    if (event == null || event.context == null || event.currentItem == null || event.player == null || event.target == null
            || event.target.typeOfHit != MovingObjectType.BLOCK)
        return;

    if (drawingHighlight)
        return;

    drawingHighlight = true;

    try {
        TileMoving te = get(event.player.worldObj, event.target.blockX, event.target.blockY, event.target.blockZ);
        if (te != null) {
            MovingObjectPosition mop = te.rayTrace(event.player);

            if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
                DrawBlockHighlightEvent ev = new DrawBlockHighlightEvent(event.context, event.player, mop, mop.subHit,
                        event.currentItem, event.partialTicks);
                World world = event.player.worldObj;
                World w = null;
                MovingBlock a = te.getBlockA();
                MovingBlock b = te.getBlockB();

                Vec3i pos = null;
                MovingStructure structure = null;
                if (a != null) {
                    w = a.getRenderList() > 0 ? FakeWorld.getFakeWorld(a) : null;
                    pos = new Vec3i(a);
                    structure = a.getStructure();
                } else if (b != null) {
                    w = b.getRenderList() > 0 ? FakeWorld.getFakeWorld(b) : null;
                    pos = new Vec3i(a);
                    structure = b.getStructure();
                }

                if (w != null) {
                    event.player.worldObj = w;

                    GL11.glPushMatrix();
                    {
                        GL11.glTranslated(-pos.getX(), -pos.getY(), -pos.getZ());
                        Vec3d t = structure.getMovement().transform(new Vec3d(pos.getX(), pos.getY(), pos.getZ()),
                                structure.getInterpolatedProgress(Framez.proxy.getFrame() - 1));
                        GL11.glTranslated(t.getX(), t.getY(), t.getZ());
                        MinecraftForge.EVENT_BUS.post(ev);
                    }
                    GL11.glPopMatrix();

                    if (ev.isCanceled())
                        event.setCanceled(true);

                    event.player.worldObj = world;
                }
            }
        }
    } catch (Exception ex) {
        event.setCanceled(false);
    }

    drawingHighlight = false;
}
 
Example #12
Source File: AnvilHighlightHandler.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void drawBlockHighlightEvent(DrawBlockHighlightEvent evt) 
{
	if(evt.getTarget().typeOfHit != RayTraceResult.Type.BLOCK)
		return;

	if(evt.getTarget().sideHit != EnumFacing.UP)
		return;

	World world = evt.getPlayer().world;

	if(world.getBlockState(evt.getTarget().getBlockPos()).getBlock() != TFCBlocks.Anvil)
		return;

	double posX = evt.getPlayer().lastTickPosX + (evt.getPlayer().posX - evt.getPlayer().lastTickPosX) * evt.getPartialTicks();
	double posY = evt.getPlayer().lastTickPosY + (evt.getPlayer().posY - evt.getPlayer().lastTickPosY) * evt.getPartialTicks();
	double posZ = evt.getPlayer().lastTickPosZ + (evt.getPlayer().posZ - evt.getPlayer().lastTickPosZ) * evt.getPartialTicks();

	double hitX = Math.round((evt.getTarget().hitVec.xCoord - evt.getTarget().getBlockPos().getX())*100)/100.0d;
	double hitY = Math.round((evt.getTarget().hitVec.yCoord - evt.getTarget().getBlockPos().getY())*100)/100.0d;
	double hitZ = Math.round((evt.getTarget().hitVec.zCoord - evt.getTarget().getBlockPos().getZ())*100)/100.0d;

	int divX = (int) Math.floor(hitX * 8);
	int divY = (int) Math.floor(hitY * 8);
	int divZ = (int) Math.floor(hitZ * 8);

	//get the targeted sub block coords
	double subX = divX/8D;
	double subY = divY/8D;
	double subZ = divZ/8D;

	TileAnvil te = (TileAnvil) world.getTileEntity(evt.getTarget().getBlockPos());
	EnumFacing facing = world.getBlockState(evt.getTarget().getBlockPos()).getValue(BlockAnvil.FACING);
	if(facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH)
	{
		if(divX == 0 || divX == 7 || divZ < 2 || divZ > 5)
			return;

		divX -= 1; divZ -= 2;

		if(te.getStrikePoint(divX, divZ) == null)
			return;
	}

	if(facing == EnumFacing.EAST || facing == EnumFacing.WEST)
	{

		if(divZ == 0 || divZ == 7 || divX < 2 || divX > 5)
			return;

		divX -= 2; divZ -= 1;

		if(te.getStrikePoint(divZ, divX) == null)
			return;
	}

	//create the box size
	double minX = evt.getTarget().getBlockPos().getX() + subX;
	double minY = evt.getTarget().getBlockPos().getY() + subY;
	double minZ = evt.getTarget().getBlockPos().getZ() + subZ;
	double maxX = minX + 0.125;
	double maxY = minY + 0.07;
	double maxZ = minZ + 0.125;

	GlStateManager.enableBlend();
	GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
	GlStateManager.disableCull();
	GlStateManager.disableTexture2D();

	//Draw the mini Box
	drawBox(new AxisAlignedBB(minX,minY,minZ,maxX,maxY,maxZ).expand(0.002F, 0.002F, 0.002F).offset(-posX, -posY, -posZ), new float[]{1,0.5f,0, 0.5f});

	GlStateManager.enableTexture2D();
	GlStateManager.enableCull();
	GlStateManager.disableBlend();
}
 
Example #13
Source File: SmallVesselHighlightHandler.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void drawBlockHighlightEvent(DrawBlockHighlightEvent evt) 
{
	RayTraceResult target = evt.getTarget();
	if(target.typeOfHit != RayTraceResult.Type.BLOCK)
		return;

	World world = evt.getPlayer().world;
	EntityPlayer player = evt.getPlayer();
	IBlockState state = world.getBlockState(target.getBlockPos());

	double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * evt.getPartialTicks();
	double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * evt.getPartialTicks();
	double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * evt.getPartialTicks();

	double hitX = Math.round((target.hitVec.xCoord - target.getBlockPos().getX())*100)/100.0d;
	double hitY = Math.round((target.hitVec.yCoord - target.getBlockPos().getY())*100)/100.0d;
	double hitZ = Math.round((target.hitVec.zCoord - target.getBlockPos().getZ())*100)/100.0d;

	AxisAlignedBB box = null;
	int index = getIndex(hitX, hitZ);

	if((state.getBlock() == TFCBlocks.SmallVessel) || (target.sideHit == EnumFacing.UP && player.getHeldItemMainhand().getItem() == TFCItems.PotteryVessel && 
			state.getBlock().isSideSolid(state, world, target.getBlockPos(), EnumFacing.UP) && player.isSneaking() && player.getHeldItemMainhand().getItemDamage() == 1))
	{

		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
		GlStateManager.disableCull();

		if(index == 0)
			box = aabb0.offset(target.getBlockPos());
		else if(index == 1)
			box = aabb1.offset(target.getBlockPos());
		else if(index == 2)
			box = aabb2.offset(target.getBlockPos());
		else
			box = aabb3.offset(target.getBlockPos());

		if(state.getBlock() != TFCBlocks.SmallVessel)
			box = box.offset(0, 1, 0);

		GlStateManager.enableTexture2D();
		Core.bindTexture(selectTex);
		drawFace(box.expand(0.002F, 0.002F, 0.002F).offset(-posX, -posY, -posZ), new float[]{1f,1f,1f, 1f}, EnumFacing.UP);

		GlStateManager.disableTexture2D();
		GlStateManager.enableCull();
		GlStateManager.disableBlend();
	}
}
 
Example #14
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 #15
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);
}
 
Example #16
Source File: ISelectionAware.java    From OpenModsLib with MIT License votes vote down vote up
boolean onSelected(World world, BlockPos blockPos, DrawBlockHighlightEvent evt);