[Solved] Modifying Entities (AI and Invulnerability)

Hello everyone,

i’d like to know how some could modify the AI of an entity (in my case a villager). I want this villager to just stay where he is and optionally look at the nearest Player around. I looked through the avaiable data manipulators and found something that should fit my needs: AgentData

I just have the huge problem that i don’t even think of how i could work with it. It just accepts DataHolders and i found absolutely no documentation on how i should be able to modify his behaviour then.

Second:

InvulnerabilityData javadoc says:

Signifies that an Entity is "invulnerable" to any sort of damage for an expiring period of "tick"s. Usually applicable to all Entity.

So far so good, but when i look at the javadoc for the function setInvulnerableTicks it says:

Sets the amount of ticks that the Wither should stay invulnerable for. Note: This causes an explosion when the time runs out.

Okay, neat feature, but i don’t want to sacrifice my villager when he isn’t god anymore…

Also, is there anyways a magic number to make him invulnerable forever?

Thank you very much!

Lol, the javadocs probably need to be updated. While most entities can be invulnurable, the explosion is only created for Withers.

3 Likes

You could give a slowness effect to the villager. (if this is already implemented)

How about noai?

Currently, all we can support is disabling/enabling entity AI.

To disable AI:

entity.remove(AgentData.class);

To enable AI:

entity.offer(entity.getOrCreate(AgentData.class).get());

That is the simplest I can make it.

Re the wither javadocs, that’s specific to withers, I’ll make a note of it for the next sweep of javadoc cleanups.

entity.offer(entity.getOrCreate(InvulnerabilityData.class).get().setValue(Integer.MAX_VALUE));

Unfortunately, Minecraft doesn’t persist this type of information, but I’m planning on writing a workaround with storing sponge specific data for entities to retain their invulnerability.

1 Like

Disabling/Removing the AI fits my needs, so thats fine, never thought of removing the AgentData.

Im gonna write a small helper that refreshs the invulnerability until the workaround is out.

Thank you very much sir.