Jump to content

Register EntityAIBase to entities


billythegoat101

Recommended Posts

Hello there,

 

I'd like to suggest that you add a way to add EntityAIBase instances to the AI lists for EntityCreatures

 

As it is right now, Entities create new instances of these classes at their initialization for them to use later on when needed. Their existence doesn't save over sessions and makes it quite easy to just add them yourself to individual entities.

 

However, if you want to assign a EntityAIBase controller to entities in bulk, like say for example, every single wolf on the entire planet should look up to the sky if there is full moon or something.

Without a way to add AI controllers to all entities of a type, my only options right now if I were to do such a project would be to either overwrite the Wolf class, or (as I am doing right now for something similar and hating) put a routine in the onTick function in the mod_ class that checks every single loaded entity in the world to see if they match the criteria (is a wolf), checks if they do not already have an instance of this AI controller in their list, then adds the AI controller if it doesn't.

As you might expect, that is quite cumbersome and intensive, though I have yet to come up with a better solution.... (please do tell me if you can)

The only other idea I have would be to have a hook that is called every time an entity is spawned anywhere on the map so that and AI controller can be given to it. I don't exactly have an in-depth knowledge of forge, but I have yet to see any evidence saying that this already exists, however that would still be pretty bad.

 

So, my suggestion summarized:

Please add a way to register EntityAIBase instances to entity types. Perhaps even just the EntityCreature class and let the AI controller sort it out and determine if it should be called based on it's entity's class type (is wolf).

Also, since some entities don't take advantage of the new system yet, it would be very helpful if you could also have some sorta mod-flag that says "if this type of entity does not have AI tasks to handle standard movement and actions, however still has modded AI tasks, still update the tasks"

A couple of uses I have thought of (not all the most efficient, but still ideas):

 

-Splitting up the work of certain blocks that need to control mobs and giving the work to the mobs themselves. For example, a bait block, instead of AABB checking for all mobs within a distance and then attracting them to it, have the mobs check every few hundred ticks to see if that block is nearby and having him walk to it.

(also gets rid of the hassle of fighting with the mob's existing AI which may want to go to another direction. Since EntityAIBase controllers have a concurrency manager (MutexBit) and a priority order, the AI trying to get a zombie under the tree will give up if an AI ranked above it tries to get it to the block.)

 

-Giving some sort of visual effect to all entities: Entities start throwing off particles of a certain color depending on their health or something

 

-Making wolves howl to the moon

 

-All endermen automatically get pissed when the enderdragon is dead

 

Helpful things to note:

-Mobs handle themselves: You don't have to constantly tell all the mobs what to do like "Hey wolf, look up into the sky" every single tick

-Your commands can overrule orders given by other, vanilla AI controllers

-Isn't restricted to nearby entities: You could just check every tick for all Endermen within 64blocks of the player to get pissed, but again, checking every tick would be rather costly when compared to an AI controller which will run with the entity and only need to check if the Enderdragon is dead or not.

-If an instance is added at initialization, like if it were registered, then there would be no need to check to see if there already was one in the entity's list, which is costly when you are constantly checking for nearby entities to add the AI to and may see an entity more than once.

 

Bad things to note:

-Not all entities use the new AI template :[

 

Just an idea, personally it would help me a lot and I think it would help others once they consider the possibility too.

Thank you for your time :)

Link to comment
Share on other sites

What would be more useful is a generic entity-added-to-world hook, then you could add it there, and do many other useful things too.

 

I was thinking about that too, but wasn't very sure about that because when a world is just loaded, it will either have to have a massive spike in hook calls when it is spawning in all the existing mobs or will have to ignore them because they already do exist.

 

Mods that require things to be added to entities at every runtime (like adding AI because it is not saved across sessions) would prefer the first option and hate the second, while other mods that would do something to entities that would save, like maybe moving all entities into the ground or making all mobs in love would prefer the second while the first would be unnecessarily heafty.

 

I really don't know which would be happen or be better, but it would still be more helpful either way.

Link to comment
Share on other sites

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.