Jump to content

Recommended Posts

Posted (edited)

I have a very basic AI class where if the player gets within a certain area of the entity, then the player takes damage.

 

So I did the usual; get the bounding box, scale it, offset it, and iterate the list for valid entities. The thing is, it works, other mobs take damage without any issue. However, I can't seem to get hit. It's in the AI class so it's not a server-client issue, plus when I print the list of entities in the AABB it does detect the server's player class. What am I missing here? This is all there is in my update method:

 

            List<LivingEntity> swipeEnemies = this.entity.world.getEntitiesWithinAABBExcludingEntity(entity,  entity.getEntityBoundingBox().expand(5.0,1.0,5.0).offset(-2.5D,0D,-2.5D));
            if (!swipeEnemies.isEmpty())
            {
                for (LivingEntity targ : swipeEnemies)
                {
                    targ.attackEntityFrom(DamageSource.causeMobDamage(entity),12.0F);
                }

 

Edited by Turtledove
Posted
2 hours ago, Turtledove said:

...huh, rebuilding the project got it to work. The heck?

Were you in creative mode when you were trying it? Just curious, since I would imagine you wouldn't take damage in creative.

Posted
10 hours ago, Ugdhar said:

Were you in creative mode when you were trying it? Just curious, since I would imagine you wouldn't take damage in creative.

Haha nah I was in survival. Just one of those times where you can't figure out why something finally works, so you just accept it and move on lol.

Posted

It appears that the damage source is the issue, when I set my custom entity as the damage source it causes attackEntityFrom to return false most of the time. But when I instead set the source as a generic type, it works 100%. Strange. Looking through the multiplayer class's attackEntityFrom (or its parent class) there's nothing there to indicate there'd be a problem.

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.