Jump to content

Detecting a neutal mob


BinaryCrafter

Recommended Posts

I'm iterating through mobs that are spawned within a specific range of each player, and am trying to identify which of the mobs are neutral mobs (i.e. those will that are normally passive, but will turn aggressive towards a player if provoked, e.g. Wolf, Zombie Pigman). I've looked at the class definitions of those mobs hoping to find an interface or property that I could check for, but haven't managed to find a fool-proof way of identifying neutral mobs.

Can anyone offer any advice? I'll resort to hard coding if I really must, but I'd much prefer to do it properly.

Link to comment
Share on other sites

1 hour ago, BinaryCrafter said:

I'm iterating through mobs that are spawned within a specific range of each player, and am trying to identify which of the mobs are neutral mobs (i.e. those will that are normally passive, but will turn aggressive towards a player if provoked, e.g. Wolf, Zombie Pigman). I've looked at the class definitions of those mobs hoping to find an interface or property that I could check for, but haven't managed to find a fool-proof way of identifying neutral mobs.

Can anyone offer any advice? I'll resort to hard coding if I really must, but I'd much prefer to do it properly.

I think there is an AI that is attached to those mobs that handles that so you could iterate through the AI list and check for an instance of that particular ai class.

  • Thanks 1

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

One thing you'll find when modding is that, unfortunately, Minecraft original code isn't written well in many respects including the use of type hierarchy and inheritance. There are two schools of thought about inheritance: (a) parent classes should embody all functionality and child classes restrict it, (b) parent classes embody the common functionality and child classes expand it. But Minecraft mixes it all up -- sometimes they fully override functions in ways which simply change the functionality without specifically restricting or expanding it. In some cases they use abstract classes for common stuff, sometimes not. And to top it all off it is not well encapsulated so there is a mix of private, protected and public fields and methods.

 

So, with that being said, while it would be nice if they used interfaces to group common functionalities, they don't do that much and it is likely also inconsistent.

 

I think it would be easiest to handle vanilla things by simply hardcoding the list, and handle other mods by hoping modders use the type hierarchy better or alternatively providing an API that they can hook into to identify themselves.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.