Tutorials/Hitboxes

This tutorial seeks to teach you how to make use of hitboxes.

What They Are
Hitboxes are regions that describe how much space an entity takes up. They can be found by pressing the F3+B keys. When you open them, you will see a white outline showing the location of the entity and the space it takes up. There is also a flat red rectangle near its "eyes". This is the "line of sight", which is where its in-game eyes are, which could be independent of where they appear to be. Notice how the line of sight wraps all the way around the entity. This explains how it is impossible to sneak up behind a mob without it seeing the player. There is also a straight blue line that extends away from the line of sight. This line points in the direction the mob is facing.

How to Use Them
Hitboxes are crucially important for a lot of purposes.

Damage
The area shown by the white boxes are areas where the mob can be damaged. This includes all types of damage, except for void, fall, and status effect-related damage. It is important because it can help the player shoot a mob such as a ghast. The hitbox of a ghast does not include the tentacles, so shooting a ghast there does nothing. Even though the tentacles appear to be part of the mob, they technically are not, so the mob doesn't care where the tentacles go.

The Ender Dragon
The ender dragon has a unique hitbox. It has green boxes around its different body parts, but there is also a giant white box and the line of sight lines. The green boxes are places where you can deal damage against the dragon.

Suffocation
The mechanics of suffocation is best explained using hitboxes. If a solid block enters the "head" of the mob, then it begins to suffocate. The location of the "head" is marked with its own white line, so that is where a mob can be suffocated. If the mob does not have a separate outline for its head, such as a ghast, then it is assumed that the entire mob is a head. Therefore, a player can easily suffocate a ghast by pushing a block anywhere into its hitbox.

Farms
Sizes of hitboxes can be used for farms. For example, the hitbox of a baby chicken is shorter than the hitbox of an adult chicken. If you wanted to build an automatic chicken farm, you must ensure that only the adult chicken will be killed, since baby chickens don't drop anything.

Blocks that are shorter than a block are best to use for building a farm. These include enchanting tables, slabs, daylight sensors, and snow layers. These can be used to manipulate the line of sight, as was used in Tango Tek's wither skeleton farm:

They can also be used to manipulate when mobs can see other mobs, which can help make vindicator-powered passive mob farms, as Docm77 has done:

Ejecting Mobs
Since every entity has a visible hitbox, it can be used to more easily break a minecart or boat that is carrying another mob. By making hitboxes appear, you can see where the mob's hitbox starts. So, you can break a minecart or boat with a passenger without harming the passenger.

Line of Sight
Have you ever heard somebody telling you to "break line of sight"? They are referring to making it so the mob can no longer see the player. The player has their own line of sight (red rectangle). The "line of sight" between mobs exists when the red rectangle of the player is visible from the red rectangle of the mob, and they are in range. This range varies from 20 blocks for most hostile mobs to a hundred blocks for ghasts and blazes, and is affected by factors like the blindness effect and wearing skulls.

Line of sight affects how mobs attack the player. If a hostile mob has a line of sight, it will begin attacking. For guardians, the player must maintain line of sight for the entire charge-up of the attacking beam for it to do any damage. If the player's blue line is aiming towards an enderman's red rectangle and not wearing a pumpkin, the enderman will get angry at the player.

Breaking Line Of Sight
Breaking this line of sight can be done in a variety of ways. The first way is to place blocks between the player and the mob, thus preventing you from seeing the other mob's red rectangle. Most mobs cannot see through glass, so it can be used for these purposes. Another solution is to get out of range of the mob, so that it does not attack you. This is difficult to do for long-distance attackers, such as blazes. Another solution is to kill the mob or unload the chunks that contain it.