Field of view and name tags

Two client hooks change what the local player sees without drawing anything yourself, and a world draw hook can add labels of its own.

From Sunrise's modding bookead8a1e

On this page

Field of view

compute_fov_modifier runs on the client once per tick while there is a local player, after vanilla's effects (sprinting, a drawn bow) and before zoom and camera easing. It is NeoForge's ComputeFovModifierEvent.

ComputeFovModifierEvent fieldMeaning
playerThe inputs of the calculation (FovPlayer)
baseThe scale before any mod ran
modifierThe scale to use; write it to change the field of view

A value that is not finite, or lies outside 0.01..=10, falls back to base. The hook does not affect a spectator camera attached to a mob.

Name tags

render_name_tag runs when the game decides whether to show the name tag of a player, mob, armor stand or item frame, before the tag is drawn. It is NeoForge's RenderNameTagEvent.

RenderNameTagEvent fieldMeaning
entity_id, kindThe entity and its type id
vanilla_visibleWhat vanilla decided
visibleSet it to show or hide the tag
textSet it to Some(text) to replace the tag's text

Distance and the entity's availability still apply. The local player's own tag is considered only when its camera and settings would show it.

Labels in the world

A world draw hook (render_level_stage, submit_custom_geometry, a debug renderer) draws a label of its own with draw.name_tag, as vanilla draws a name tag: half a block above the position, facing the camera.

rust
let options = NameTagOptions::new(false, true, 0xF0);
let _ = event.draw.name_tag([x + 0.5, y + 1.0, z + 0.5], &Text::literal("Furnace"), options);
NameTagOptions fieldMeaning
see_throughOff: drawn once, faded and translucent, hidden behind walls (a sneaking name). On: opaque in the world and a faded copy over everything, walls included
backgroundThe black backdrop behind the faded text, at the player's text background opacity
lightThe light at the label: sky light in the high four bits, block light in the low four (0xF0 full sky, 0x0F full block)

Without see_through the label is drawn in exactly light. With it, the copy in the world raises the sky and block levels to at least 2 each, and the copy over everything is unlit. The backdrop's alpha is 255 times the player's text background opacity (0.25 when the background is for chat only), and the faded text's is 255 times the larger of (opacity + 0.75) / 2 and 0.5: 0x3F and 0x7F at the defaults. Labels are drawn with the world's name tags, far to near.

A label is 0.025 blocks a font pixel, so it shrinks with distance; scale by distance yourself for a constant size. Its quads share the view's 4,096 with quads. A position that is not finite, text deeper than 512 component nodes and a label past the quads left are refused by name (DrawError) and draw nothing. The hook notes give the details.

The client session

For a HUD that shows session information, read ClientHost::client_session(), and the local PlayerRef's block_breaking and ambient_mood. Values that may be missing (a session, an external display name) are Options, and every counter stays on the client. The hook notes give their exact availability and timing.

Edit this page on GitHub · Spotted something wrong? Open an issue or ask on Discord.