Posted July 30, 20169 yr 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?
July 30, 20169 yr 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.
July 30, 20169 yr 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.
July 30, 20169 yr Author 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.
July 30, 20169 yr 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.
July 30, 20169 yr 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.
July 30, 20169 yr Author 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.
July 30, 20169 yr Author 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?
July 30, 20169 yr LivingSpawnEvent should work, what were you using? 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.
July 30, 20169 yr Author LivingSpawnEvent should work, what were you using? I was using EntityJoinWorld event and then I saw LivingSpawnEvent so I got confused.
July 30, 20169 yr Author Alright I got it to work . But one last question: is the AI handled completely server side?
July 30, 20169 yr I believe so, considering almost if not everything except rendering is handled server side. 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.
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.