Java Code Examples for net.minecraftforge.client.event.DrawBlockHighlightEvent#getPlayer()
The following examples show how to use
net.minecraftforge.client.event.DrawBlockHighlightEvent#getPlayer() .
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: AnvilHighlightHandler.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@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 4
Source File: SmallVesselHighlightHandler.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@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(); } }