How to make villagers run from the player? (Willing to learn how to code)

Started by Dezbro1 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make villagers run from the player? (Willing to learn how to code)

I want to make the villagers run from the player similar to how they do from zombies. How could I do this? I'm willing to learn how to code, but I've never written a line of code in my life so I don't know where to start. Thanks!

Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I know I'm way too late, but…
Tue, 08/20/2024 - 01:37

I know I'm way too late, but this is what I've seen most mods do (I think you need custom code unless MCreator supports EventBusSubscribers):

  1. Make an EventBusSubscriber class and annotate it as such with @Mod.EventBusSubscriber
  2. make a @SubscribeEvent method that takes EntityJoinLevelEvent as its event
  3. Check if event.getEntity() is an instance of AbstractVillager (Or just Villager if you only want villagers to run and not other non-villager villagers like Wandering Traders)
  4. If the entity is an AbstractVillager, add an AvoidEntityGoal to the entity which avoids your custom one