Jump to content

Recommended Posts

Posted

How to override vanilla AI with a modified version of the same AI. I'm making a small mod where it reduces the doors required for villager breeding and I made a class with a slightly edited version of the villager mate AI. However how do I override the vanilla AI?

Posted

I see two ways of doing this

1. Create a new EntityVillager that uses your new AI and replace all vanilla villagers with it.

2. Use AccessTransformer or Reflection to change EntityLiving tasks variable to not be final.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Actually let me correct myself no need to use access transformers or even create your own entity, you may be able to use an event that gets called on entity creation or after that, and change the default mating task since you can call tasks.add(position, new EntityVillagerAI(variables));

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Actually let me correct myself no need to use access transformers or even create your own entity, you may be able to use an event that gets called on entity creation or after that, and change the default mating task since you can call tasks.add(position, new EntityVillagerAI(variables));

 

Alright, I've got the event class, but I cannot find the tasks.add command.

Posted

my solution would to make a custom entity, the same as the villager (but with the custom ai) and whenever a villager spawns naturally (hook onto that with the event system), cancel the spawn and spawn the custom entity instead.

Posted

Have you created a EntityVillager variable if not the event should have an entity variable you can check if it is an EntityVillager, and if so...

 

@SubscribeEvent
public void entityVillagerAIOverride(EventYouAreUsingClass event) {
     if (event.entity != null && event.entity instanceof EntityVillager) {
          EntityVillager villager = (EntityVillager) event.entity;
          villager.tasks.add(number, new VillagerAI());
     }
}[

 

Also don't forget to register your event using

MinecraftForge.EVENT_BUS.register(new EventHandlerClass());

 

my solution would to make a custom entity, the same as the villager (but with the custom ai) and whenever a villager spawns naturally (hook onto that with the event system), cancel the spawn and spawn the custom entity instead.

I did suggest that but if he just Overrides the Mating AI he won't have to create a new Entity, and this way it could still be compatible with other mods that extend EntityVillager assuming he chechs to see if the position he is overriding is an instance of the vanilla AI.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

my solution would to make a custom entity, the same as the villager (but with the custom ai) and whenever a villager spawns naturally (hook onto that with the event system), cancel the spawn and spawn the custom entity instead.

 

Yeah, but that could easily break or make useless other mods that affect the villager.

Posted

Have you created a EntityVillager variable if not the event should have an entity variable you can check if it is an EntityVillager, and if so...

 

@SubscribeEvent
public void entityVillagerAIOverride(EventYouAreUsingClass event) {
     if (event.entity != null && event.entity instanceof EntityVillager) {
          EntityVillager villager = (EntityVillager) event.entity;
          villager.tasks.add(number, new VillagerAI());
     }
}[

 

Also don't forget to register your event using

MinecraftForge.EVENT_BUS.register(new EventHandlerClass());

 

 

 

Okay I used the wrong event apparently, what do I use for EventYouAreUsingClass? LivingSpawnEvent?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.