Skip to content

Using Followme Events (release 1.1.5)

Smileycorp edited this page Sep 13, 2021 · 7 revisions

FollowUserEvent

All versions after release 1.1.5 include the FollowUserEvent class.

If you are a mod developer and would like to interact with followme this would be the main way of doing so. This event is fired on the FORGE event bus if an entity is in the config file, and before conditions are checked.

Entities:

FollowUserEvent.getEntityLiving() returns the entity that an entity is attempting to get to follow them.

Players:

FollowUserEvent.user is a reference to the entity that initiated the event. This can be changed to change which player the entity follows.

Conditions:

FollowUserEvent.conditions is a map of all conditions added for the entity by the current datapack, with reference to their name, these can be removed or more conditions can be added. Adding conditions this way is generally not the best idea, in favor of either adding them in a datapack, or handling your own conditions in the event itself.

Canceling:

By setting the event to canceled the entity will no longer be scheduled to recieve/remove the following ai.

Examples:

The following example will stop villagers with a career following the user:

@SubscribeEvent
public void onFollow(FollowUserEvent event) {
	if (event.getEntityLiving() instanceof VillagerEntity) {
		if (((VillagerEntity)event.getEntityLiving()).getVillagerData().getProfession() != VillagerProfession.NONE) `
			event.setCanceled(true);
		}
        }
}

The following will stop entities following you at night:

@SubscribeEvent
public void onFollow(FollowUserEvent event) {
	if (event.getEntity().world.isNightTime()) {
		event.setCanceled(true);
	}
}

The following removes all datapack conditions if the entity is a child:

@SubscribeEvent
public void onFollow(FollowUserEvent event) {
	if (event.getEntityLiving() instanceof AgeableEntity) {
		if (((AgeableEntity)event.getEntityLiving()).isChild()) {
			event.conditions.clear();
		}
	}
}

Clone this wiki locally