@SubscribeEvent public void onBlockHilight(DrawBlockHighlightEvent event) { if (!TombManyGravesConfigs.DISPLAY_GRAVE_NAME) { return; } RayTraceResult trace = event.getTarget(); if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) { World world = mc.theWorld; IBlockState state = world.getBlockState(trace.getBlockPos()); if (state.getBlock() == ModBlocks.blockDeath) { TileEntity tileEntity = world.getTileEntity(trace.getBlockPos()); if (tileEntity != null && tileEntity instanceof TileDeathBlock) { String name = ((TileDeathBlock) tileEntity).getPlayerName(); boolean giveGravePriority = ((TileDeathBlock) tileEntity).areGraveItemsForced(); this.renderPlayerName(trace.getBlockPos(), event.getPartialTicks(), name, giveGravePriority); } } } }
@SubscribeEvent public void highlight( DrawBlockHighlightEvent event ) { ItemStack held = event.player.getHeldItem(); if ( held == null || held.getItem() != BiomeWandMod.items.wand ) { return; } NBTTagCompound tag = held.getTagCompound(); if ( tag == null ) tag = new NBTTagCompound(); if ( !tag.hasKey( WandItem.SAMPLED_BIOME_TAG ) ) { return; } int size = tag.hasKey( WandItem.ACTION_SIZE_TAG ) ? tag.getInteger( WandItem.ACTION_SIZE_TAG ) : 7; drawSelectionBox( size, event.context, event.player, event.target, 0, event.partialTicks ); //event.setCanceled( true ); }
@SubscribeEvent public void onBlockHighlight(DrawBlockHighlightEvent e) { GL11.glPushMatrix(); if (e.player.getCurrentEquippedItem() != null) { Item i = e.player.getCurrentEquippedItem().getItem(); if (Block.getBlockFromItem(i) instanceof RLMBlockContainer && e.target.getBlockPos() != null) { if (e.player.worldObj.getBlockState(e.target.getBlockPos()).getBlock() != Blocks.air) { if (TileEntityRendererDispatcher.instance != null) { RLMBlockContainer b = (RLMBlockContainer) Block.getBlockFromItem(i); if (b != null) { BlockPos p = e.target.getBlockPos(); GL11.glTranslated(p.getX(), p.getY(), p.getZ()); // if // (b.createNewTileEntity(Minecraft.getMinecraft().theWorld, // 0) != null); // TileEntityRendererDispatcher.instance.renderTileEntity(b.createNewTileEntity(Minecraft.getMinecraft().theWorld, // 0),0.0f,1); } } } } } GL11.glPopMatrix(); }
/** * Check for blocks that need a custom block highlight and draw if checked. * Adapted from the vanilla highlight code. */ public static void handleDrawBlockHighlightEvent(DrawBlockHighlightEvent event) { BlockPos pos = event.getTarget().getBlockPos(); if(pos != null && event.getPlayer() != null) { World world = event.getPlayer().world; IBlockState bs = world.getBlockState(pos); if (bs != null && bs.getBlock() instanceof SuperBlock) { SuperBlock block = (SuperBlock) bs.getBlock(); ModelState modelState = block.getModelStateAssumeStateIsCurrent(bs, world, pos, true); drawBlockHighlight(modelState, pos, event.getPlayer(), event.getPartialTicks(), false); event.setCanceled(true); } } }
@SubscribeEvent public void onBlockHighlightEvent(DrawBlockHighlightEvent highlightEvent) { MovingObjectPosition target = highlightEvent.target; //We're only interested in blocks... if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { World world = highlightEvent.player.worldObj; TileEntity tileEntity = world.getTileEntity(target.blockX, target.blockY, target.blockZ); //...From my mod if (tileEntity instanceof BaseRobotPlatesTileEntity) { //TODO: Recalculate the vector used to intersect the block so I can be more accurate with SubBlock detection. BaseRobotPlatesTileEntity rpTileEntity = (BaseRobotPlatesTileEntity)tileEntity; Vec3 targetBlockVec = Vec3.createVectorHelper(target.blockX, target.blockY, target.blockZ); Vec3 vec = targetBlockVec.subtract(target.hitVec); SubObject subObject = rpTileEntity.getSubObject(vec); //... and we're hovering over one of my Sub-Objects. if (subObject != null) { subObject.RenderBoundingBox(highlightEvent.player, rpTileEntity, highlightEvent.partialTicks); //Don't draw the block's highlight. highlightEvent.setCanceled(true); } } } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onDrawBlockhightlight(DrawBlockHighlightEvent event){ ItemStack is = event.player.getCurrentEquippedItem(); if(is == null || !(is.getItem() instanceof ChiselItem))return; int x = event.target.blockX, y = event.target.blockY,z = event.target.blockZ; Block sculpture = event.player.worldObj.getBlock(x,y,z); int[] pos = Operations.raytrace(x,y,z, event.player); if(pos[0] == -1)return; ChiselItem ci = Utils.getItem(is); int flags = ci.getChiselFlags(event.player); if(!Operations.validOperation(event.player.worldObj, x,y,z, pos, flags))return; Operations.setBlockBoundsFromRaytrace(pos, sculpture, flags); event.context.drawSelectionBox(event.player, event.target, 0, event.partialTicks); sculpture.setBlockBounds(0, 0, 0, 1, 1, 1); // event.setCanceled(true); }
@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()); } } }
@SubscribeEvent(priority = EventPriority.HIGHEST) @SideOnly(Side.CLIENT) public void onDrawHighlight(DrawBlockHighlightEvent event) { try { if (!(event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) instanceof BlockMultipart)) return; QMovingObjectPosition mop = retrace(event.player.worldObj, event.target.blockX, event.target.blockY, event.target.blockZ, RayTracer.instance().getStartVector(event.player), RayTracer.instance().getEndVector(event.player)); if (mop == null) return; if (mop.getPart() == null || !(mop.getPart() instanceof IPartSelectableCustom)) return; if (((IPartSelectableCustom) mop.getPart()).drawHighlight(mop, event.player, event.partialTicks)) event.setCanceled(true); } catch (Exception ex) { } }
@SubscribeEvent public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { int x = event.target.blockX; int y = event.target.blockY; int z = event.target.blockZ; World world = event.player.worldObj; if (world != null) { Block block = world.getBlock(x, y, z); if (block == Blocks.jukebox) { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof BlockJukebox.TileEntityJukebox) { //BlockJukebox.TileEntityJukebox jb = (BlockJukebox.TileEntityJukebox) te; Physis.logger.info("test"); } } } }
@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); } } }
@SubscribeEvent public void BuildersWandRender(final DrawBlockHighlightEvent event) { if (event.currentItem != null && event.currentItem.getItem() instanceof ItemBuildersWand) { final List<ChunkPos> blocks = ((ItemBuildersWand)event.currentItem.getItem()).getPotentialBlocks(event.player, event.player.worldObj, event.target.blockX, event.target.blockY, event.target.blockZ, event.target.sideHit); final Block blockId = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ); if (blockId != Blocks.air & blocks.size() > 0) { GL11.glEnable(3042); GL11.glBlendFunc(770, 771); GL11.glColor4f(1.0f, 1.0f, 1.0f, 0.35f); GL11.glLineWidth(3.0f); GL11.glDisable(3553); GL11.glDisable(2929); GL11.glDepthMask(false); final double px = event.player.lastTickPosX + (event.player.posX - event.player.lastTickPosX) * event.partialTicks; final double py = event.player.lastTickPosY + (event.player.posY - event.player.lastTickPosY) * event.partialTicks; final double pz = event.player.lastTickPosZ + (event.player.posZ - event.player.lastTickPosZ) * event.partialTicks; GL11.glTranslated(-px, -py, -pz); for (final ChunkPos temp : blocks) { this.drawOutlinedBoundingBox(AxisAlignedBB.getBoundingBox((double)temp.x, (double)temp.y, (double)temp.z, (double)(temp.x + 1), (double)(temp.y + 1), (double)(temp.z + 1))); } GL11.glDepthMask(true); GL11.glEnable(3553); GL11.glDisable(3042); GL11.glEnable(2929); GL11.glTranslated(px, py, pz); event.setCanceled(true); } } }
@SideOnly (Side.CLIENT) @SubscribeEvent (priority = EventPriority.LOW) public void onBlockHighlight(DrawBlockHighlightEvent event) { BlockPos pos = event.getTarget().getBlockPos(); //We have found a CuboidRayTraceResult, Lets render it properly.. RayTraceResult hit = event.getTarget(); if (hit.typeOfHit == Type.BLOCK && hit instanceof CuboidRayTraceResult) { event.setCanceled(true); RenderUtils.renderHitBox(event.getPlayer(), ((CuboidRayTraceResult) event.getTarget()).cuboid6.copy().add(pos), event.getPartialTicks()); } }
@SubscribeEvent public void highlight(DrawBlockHighlightEvent event) { if (event.getTarget() != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos hit = event.getTarget().getBlockPos(); IBlockState target = event.getPlayer().getEntityWorld().getBlockState(hit); if (target.getBlock() instanceof IPrecision) { highlighting = hit; } else highlighting = null; } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onBlockHighlight(DrawBlockHighlightEvent event) { if (event.target.typeOfHit == MovingObjectType.BLOCK) { Block b = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ); if (b == BlockStation.instance || b == BlockStationHorizontal.instance || b == BlockTube.instance) RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ); ItemStack stack = event.player.inventory.mainInventory[event.player.inventory.currentItem]; if (stack != null && stack.getItem() == ItemTube.instance) proxy.lastSideHit = event.target.sideHit; } }
@SubscribeEvent public void onDrawBlockhightlight(DrawBlockHighlightEvent event) { final ItemStack is = event.player.getCurrentEquippedItem(); if (is == null) { return; } final Item item = is.getItem(); if ((item == null) || !(item instanceof ChiselItem)) { return; } final ChiselItem ci = (ChiselItem) item; final int x = event.target.blockX; final int y = event.target.blockY; final int z = event.target.blockZ; final Block sculpture = event.player.worldObj.getBlock(x, y, z); final int[] pos = Operations.raytrace(x, y, z, event.player); if (pos[0] == -1) { return; } int flags = ci.getChiselFlags(event.player); if (!Operations.validOperation(event.player.worldObj, x, y, z, pos, flags)) { return; } Operations.setBlockBoundsFromRaytrace(pos, sculpture, flags); event.context.drawSelectionBox(event.player, event.target, 0, event.partialTicks); sculpture.setBlockBounds(0, 0, 0, 1, 1, 1); // event.setCanceled(true); }
@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); }
@SubscribeEvent public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event) { final ItemStack stack = event.getPlayer().inventory.getCurrentItem(); if (stack != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) { if (stack.getItem() instanceof IWorldDrawable) { drawSelectionBoxQuad((IWorldDrawable) stack.getItem(), event.getContext(), event.getPlayer(), event.getTarget(), 0, event.getPartialTicks()); } } }
@SubscribeEvent public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event) { final ItemStack stack = event.getPlayer().inventory.getCurrentItem(); if (stack != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) { if (stack.getItem() instanceof IItemAdjustableRadii) drawSelectionBoxQuad(event.getContext(), event.getPlayer(), event.getTarget(), 0, event.getPartialTicks()); } }
@SubscribeEvent public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event){ pulseTransparency = getPulseValue() * 0.5F / 3000f; for(int i = 0; i < renderPositions.size(); i++) { try { highlightTile(event.player, renderPositions.get(i)[0], renderPositions.get(i)[1], renderPositions.get(i)[2], event.partialTicks, i); } catch(Exception e) { } } }
@Override public boolean onSelected(World world, BlockPos pos, DrawBlockHighlightEvent evt) { if (areButtonsActive(evt.getPlayer())) { final Vec3d hitVec = evt.getTarget().hitVec; final Orientation orientation = getOrientation(world, pos); final Vec3d localHit = BlockSpaceTransform.instance.mapWorldToBlock(orientation, hitVec.x - pos.getX(), hitVec.y - pos.getY(), hitVec.z - pos.getZ()); final Hitbox clickBox = findClickBox(localHit); selection = clickBox != null? BlockSpaceTransform.instance.mapBlockToWorld(orientation, clickBox.aabb()).offset(pos.getX(), pos.getY(), pos.getZ()) : null; } else selection = null; return false; }
@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; }
@SubscribeEvent public static void onPipeBoundingBoxRender(DrawBlockHighlightEvent event) { if (event.getTarget() != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos pos = event.getTarget().getBlockPos(); EntityPlayer player = event.getPlayer(); EnumFacing side = event.getTarget().sideHit; if (player.world.getBlockState(pos).getBlock() == RegistryManager.pipe && player.world.getTileEntity(pos) != null) { TileEntityPipe te = (TileEntityPipe) player.world.getTileEntity(pos); float hitX = 0, hitY = 0, hitZ = 0; if (side.getAxis() != EnumFacing.Axis.X) { hitX = (float) event.getTarget().hitVec.x - pos.getX(); } if (side.getAxis() != EnumFacing.Axis.Y) { hitY = (float) event.getTarget().hitVec.y - pos.getY(); } if (side.getAxis() != EnumFacing.Axis.Z) { hitZ = (float) event.getTarget().hitVec.z - pos.getZ(); } EnumFacing connection = te.viewedConnection(player, side, hitX, hitY, hitZ); event.setCanceled(true); 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); double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) event.getPartialTicks(); double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) event.getPartialTicks(); double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) event.getPartialTicks(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder vertexbuffer = tessellator.getBuffer(); vertexbuffer.begin(3, DefaultVertexFormats.POSITION_COLOR); vertexbuffer.setTranslation(-d0, -d1, -d2); if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == RegistryManager.tuning_fork || player.getHeldItem(EnumHand.OFF_HAND).getItem() == RegistryManager.tuning_fork) { drawPipeConnectionAABB(vertexbuffer, connection, pos); } else { IBlockState blockstate = player.world.getBlockState(pos); IExtendedBlockState state = (IExtendedBlockState) blockstate.getBlock().getExtendedState(blockstate, player.world, pos); drawFullPipeAABB(vertexbuffer, state, pos, player.world); } tessellator.draw(); vertexbuffer.setTranslation(0D, 0D, 0D); GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void drawHammerBlockBoundsEvent(DrawBlockHighlightEvent event) { if (event.getPlayer() == null) { return; } if (event.getSubID() == 0 && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) { ItemStack stack = event.getPlayer().getHeldItemMainhand(); if (stack.getItem() == ModItems.hammer) { World world = event.getPlayer().getEntityWorld(); List<BlockPos> positions = ModItems.hammer.getExtraBlocks(world, event.getTarget(), event.getPlayer()); for (BlockPos pos : positions) { event.getContext().drawSelectionBox(event.getPlayer(), new RayTraceResult(new Vec3d(0, 0, 0), null, pos), 0, event.getPartialTicks()); } } } }
public static boolean onDrawBlockHighlight(RenderGlobal context, EntityPlayer player, RayTraceResult target, int subID, float partialTicks) { return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, player, target, subID, partialTicks)); }
public static boolean onDrawBlockHighlight(RenderGlobal context, EntityPlayer player, MovingObjectPosition target, int subID, ItemStack currentItem, float partialTicks) { return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, player, target, subID, currentItem, partialTicks)); }
@SubscribeEvent public void renderSelection(DrawBlockHighlightEvent event) { if (!(event.target.entityHit instanceof DseRayTarget)) { return; } AxisAlignedBB box = _selectionBlockBounds; MovingObjectPosition shadowSelected = _shadowSelected; if (box == null || shadowSelected.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) { return; } if (event.isCanceled()) { return; } Coord here = new Coord(DeltaChunk.getClientShadowWorld(), shadowSelected.getBlockPos()); Block hereBlock = FzUtil.getTraceHelper(); hereBlock.setBlockBounds( (float) (box.minX - here.x), (float) (box.minY - here.y), (float) (box.minZ - here.z), (float) (box.maxX - here.x), (float) (box.maxY - here.y), (float) (box.maxZ - here.z) ); EntityPlayer player = event.player; //RenderGlobal rg = event.context; ItemStack is = event.currentItem; float partialTicks = event.partialTicks; DimensionSliceEntity dse = _hitSlice; Coord corner = dse.getMinCorner(); Quaternion rotation = dse.transformPrevTick.getRot().slerp(dse.transform.getRot(), event.partialTicks); NORELEASE.fixme("dse.getTransform(partial)?"); rotation.incrNormalize(); try { GL11.glPushMatrix(); setShadowWorld(); RenderGlobal rg = mc.renderGlobal; GL11.glDisable(GL11.GL_ALPHA_TEST); /*if (Core.dev_environ) { GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glColorMask(false, true, true, true); }*/ GL11.glTranslated( NumUtil.interp(dse.lastTickPosX - player.lastTickPosX, dse.posX - player.posX, partialTicks), NumUtil.interp(dse.lastTickPosY - player.lastTickPosY, dse.posY - player.posY, partialTicks), NumUtil.interp(dse.lastTickPosZ - player.lastTickPosZ, dse.posZ - player.posZ, partialTicks)); rotation.glRotate(); Vec3 centerOffset = dse.getTransform().getOffset(); GL11.glTranslated( -centerOffset.xCoord - corner.x, -centerOffset.yCoord - corner.y, -centerOffset.zCoord - corner.z); double savePlayerX = player.posX; double savePlayerY = player.posY; double savePlayerZ = player.posZ; partialTicks = 1; player.posX = player.posY = player.posZ = 0; if (!ForgeHooksClient.onDrawBlockHighlight(rg, player, shadowSelected, shadowSelected.subHit, is, partialTicks)) { rg.drawSelectionBox(player, shadowSelected, 0, partialTicks); } player.posX = savePlayerX; player.posY = savePlayerY; player.posZ = savePlayerZ; } finally { GL11.glEnable(GL11.GL_ALPHA_TEST); restoreRealWorld(); GL11.glPopMatrix(); /*if (Core.dev_environ) { GL11.glColorMask(true, true, true, true); GL11.glEnable(GL11.GL_DEPTH_TEST); }*/ } }
@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(); }
@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(); } }
@SideOnly(Side.CLIENT) @SubscribeEvent public void onBlockHighlight(DrawBlockHighlightEvent event) { RayTraceResult mop = event.getTarget(); if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { EntityPlayer player = event.getPlayer(); World world = player.worldObj; BlockPos pos = mop.getBlockPos(); if (world.getBlockState(pos).getBlock() == NordBloks.energyCableBlock2) { IBlockState state = world.getBlockState(pos); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(1.0F, 0.0F, 0.0F, 0.4F); GL11.glLineWidth(2.0F); GlStateManager.disableTexture2D(); GlStateManager.depthMask(false); float f1 = 0.002F; BlockPos blockpos = mop.getBlockPos(); if (state.getMaterial() != Material.air && event.getPlayer().worldObj.getWorldBorder().contains(blockpos)) { double hitX = mop.hitVec.xCoord - blockpos.getX(); double hitY = mop.hitVec.yCoord - blockpos.getY(); double hitZ = mop.hitVec.zCoord - blockpos.getZ(); double sho = 0.125; double sx = blockpos.getX(); double sy = blockpos.getY(); double sz = blockpos.getZ(); double fx = blockpos.getX(); double fy = blockpos.getY(); double fz = blockpos.getZ(); if ( hitX>=sho*3 && hitX<=sho*5 && hitY>=sho*3 && hitY<=sho*5 && hitZ>=sho*3 && hitY<=sho*5 ){ sx +=sho*3; sy +=sho*3; sz +=sho*3; fx+=sho*5; fy+=sho*5; fz+=sho*5; }else if(hitX>sho*5 && hitY>=sho*3 && hitY<=sho*5 && hitZ>=sho*3 && hitY<=sho*5 ){ sx +=sho*5; sy +=sho*3; sz +=sho*3; fx+=sho*8; fy+=sho*5; fz+=sho*5; }else{ fx+=1; fy+=1; fz+=1; } AxisAlignedBB aabb = new AxisAlignedBB(sx,sy,sz,fx,fy,fz); // block.setBlockBoundsBasedOnState(event.player.worldObj, blockpos); double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)event.getPartialTicks(); double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)event.getPartialTicks(); double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)event.getPartialTicks(); //todo test it event.getContext().drawSelectionBoundingBox( // block.getSelectedBoundingBox(event.player.worldObj, blockpos) aabb .expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D) .offset(-d0, -d1, -d2) ); } GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); event.setCanceled(true); } } }
@SubscribeEvent public void onDrawPaintingPixel(DrawBlockHighlightEvent event) { ItemStack is = event.player.getCurrentEquippedItem(); if (is == null || !(is.getItem() instanceof PaintTool)) { return; } final int x = event.target.blockX; final int y = event.target.blockY; final int z = event.target.blockZ; final World world = event.player.worldObj; final Block block = world.getBlock(x, y, z); if (block instanceof PaintingBlock) { final PaintingBlock painting = (PaintingBlock) block; PaintingPlacement pp = PaintingPlacement.of(world.getBlockMetadata(x, y, z)); Vec3 pos = event.player.getPosition(1.0f); Vec3 look = event.player.getLookVec(); look = pos.addVector(look.xCoord * 5, look.yCoord * 5, look.zCoord * 5); MovingObjectPosition mop = painting.collisionRayTrace(world, x, y, z, pos, look); if (mop == null) { return; } float[] point = pp.block2painting((float) (mop.hitVec.xCoord - mop.blockX), (float) (mop.hitVec.yCoord - mop.blockY), (float) (mop.hitVec.zCoord - mop.blockZ)); point[0] = (int) (point[0] * 16) / 16f; point[1] = (int) (point[1] * 16) / 16f; float[] bound1 = pp.painting2block(point[0], point[1], 0.002f); float[] bound2 = pp.painting2block(point[0] + 1 / 16f, point[1] + 1 / 16f, 0.002f); painting.setBlockBounds(Math.min(bound1[0], bound2[0]), Math.min(bound1[1], bound2[1]), Math.min(bound1[2], bound2[2]), Math.max(bound1[0], bound2[0]), Math.max(bound1[1], bound2[1]), Math.max(bound1[2], bound2[2])); painting.ignore_bounds_on_state = true; event.context.drawSelectionBox(event.player, event.target, 0, event.partialTicks); painting.ignore_bounds_on_state = false; } }
@SubscribeEvent public void onDrawBlockSelectionBox(DrawBlockHighlightEvent e) { drawSelectionBox(e.player, e.target, e.subID, e.currentItem, e.partialTicks); e.setCanceled(true); }
@SubscribeEvent public void blockHighlightEvent(DrawBlockHighlightEvent e) { if (e.target.entityHit instanceof EntityPlayer) { } }
/** * Check for blocks that need a custom block highlight and draw if checked. * Adapted from the vanilla highlight code. */ @SubscribeEvent public static void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event) { BlockHighlighter.handleDrawBlockHighlightEvent(event); }
public static void preBlockHighlight(DrawBlockHighlightEvent event) { addGoggles(event.player); }
public static void postBlockHighlight(DrawBlockHighlightEvent event) { removeGoggles(event.player); }
@SubscribeEvent public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event) { ItemStack held = event.getPlayer().getHeldItemMainhand(); if (held == null || Item.getItemFromBlock(ModBlocks.blockMarker) != held.getItem()) return; if (event.getTarget().getBlockPos() == null) return; EntityPlayer entityPlayer = event.getPlayer(); World world = event.getPlayer().getEntityWorld(); BlockPos blockpos = BlockUtils.getSelectedBlock(entityPlayer); if (blockpos == null) return; /** * Dont highlight if we are actually targetting a non-air block */ IBlockState state = world.getBlockState(event.getTarget().getBlockPos()); if (!state.getBlock().isAir(state, world, event.getTarget().getBlockPos())) return; /** * Vanilla block outline code * But works on air */ 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); IBlockState iblockstate = world.getBlockState(blockpos); if (world.getWorldBorder().contains(blockpos)) { double d0 = entityPlayer.lastTickPosX + (entityPlayer.posX - entityPlayer.lastTickPosX) * (double)event.getPartialTicks(); double d1 = entityPlayer.lastTickPosY + (entityPlayer.posY - entityPlayer.lastTickPosY) * (double)event.getPartialTicks(); double d2 = entityPlayer.lastTickPosZ + (entityPlayer.posZ - entityPlayer.lastTickPosZ) * (double)event.getPartialTicks(); drawSelectionBoundingBox(iblockstate.getSelectedBoundingBox(world, blockpos).expandXyz(0.0020000000949949026D).offset(-d0, -d1, -d2), 0.0F, 0.0F, 0.0F, 0.4F); } GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); event.setCanceled(true); }