OrangeVillager61 Posted July 30, 2016 Share Posted July 30, 2016 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? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 30, 2016 Share Posted July 30, 2016 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. Quote 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. Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 30, 2016 Share Posted July 30, 2016 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)); Quote 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. Link to comment Share on other sites More sharing options...
OrangeVillager61 Posted July 30, 2016 Author Share Posted July 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
FokC Posted July 30, 2016 Share Posted July 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 30, 2016 Share Posted July 30, 2016 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. Quote 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. Link to comment Share on other sites More sharing options...
OrangeVillager61 Posted July 30, 2016 Author Share Posted July 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
OrangeVillager61 Posted July 30, 2016 Author Share Posted July 30, 2016 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? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 30, 2016 Share Posted July 30, 2016 LivingSpawnEvent should work, what were you using? Quote 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. Link to comment Share on other sites More sharing options...
OrangeVillager61 Posted July 30, 2016 Author Share Posted July 30, 2016 LivingSpawnEvent should work, what were you using? I was using EntityJoinWorld event and then I saw LivingSpawnEvent so I got confused. Quote Link to comment Share on other sites More sharing options...
OrangeVillager61 Posted July 30, 2016 Author Share Posted July 30, 2016 Alright I got it to work . But one last question: is the AI handled completely server side? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 30, 2016 Share Posted July 30, 2016 I believe so, considering almost if not everything except rendering is handled server side. Quote 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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.