Credits to Owen1212055 for their NMS guide, please read it as this is just a simple port!
public class NametagEntity extends Entity {
public static final Tag<NametagEntity> NAMETAG_TAG = Tag.Transient("nametag"); // for deleting the entity on leave