Java Code Examples for net.minecraftforge.client.event.DrawBlockHighlightEvent#setCanceled()
The following examples show how to use
net.minecraftforge.client.event.DrawBlockHighlightEvent#setCanceled() .
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: BlockSelectionHandler.java From OpenModsLib with MIT License | 6 votes |
@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 2
Source File: WrenchOverlayRenderer.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@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 3
Source File: MOPHelper.java From Framez with GNU General Public License v3.0 | 5 votes |
@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 4
Source File: BlockMoving.java From Framez with GNU General Public License v3.0 | 4 votes |
@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; }