Jump to content

[1.8] Manipulating attacks.


Ernio

Recommended Posts

My actions go like this:

1. Attack (swing) -> 2. Check if hit (miss % of attacker) -> 3. Check dodge (dodge % of target) -> 4. Hit (knockback) -> 5. Check if block (shield system - target's) -> 6. Modify damage taken by blocking factors (target's) -> 7. Land damage on target -> 8. Apply armour factors -> 9. Do final damage (lower target's health).

 

Now - all that is easy peasy for EntityPlayer attacks - there is nice AttackEntityEvent that allows to do 1,2,3,4,5,6; then event.target.attackEntityFrom to do 7, and finally LivingHurtEvent to do 8 and 9.

 

Now with other entities (mobs) it's kinda harder. While 7,8,9 are easy (same as above), the 1-6 are not - there is no event "EntityAttackEntityEvent", since those actions are handled by AI.

 

Question arises:

What is correct way to hook into moment when ANY (vanilla too) entityLiving performs EntityLivingBase#attackEntityAsMob(Entity target).

 

I was looking deeply in those codes and might missed something easy, but if not - only thing that comes to mind is to replace attackAI when mob joins world with extending class that will be my hook for 1-6 operations.

 

Is this only way?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Damn, I actually did miss it.

 

Not really what I expected (#rewrite), but will do nice since it goes before almost everything - only Player's AttackEntityEvent fires first, even knockback can be nicely altered here :D

 

Thx.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

WHOOP

 

onAttack(LivingAttackEvent event)

 

[17:06:29] [server thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:52] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:53] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:54] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:55] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:56] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:57] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:58] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:09:59] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Zombie inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Bat inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall
[17:10:00] [Client thread/INFO] [sTDOUT]: [.ForgeEvents:onAttack:52]: Squid inWall

 

I am lost as to - what are reasons of those?

I mean - my guess is probably failed mob spawn location (inWall), but why does is happen mostly on client, and why 1st log (1st on I posted) happened on server (it's not only one).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Well, I guess nothing to worry about (just annoying fact that is happens only client or only server side).

 

The problem with solution proposed is the fact that it happens after attack is done. It is logically weird to code it this way: Entity attacks -> Apply attack on target -> go back to attacker -> count again -> change damage.

 

I know that it WILL cause issues in my future coding (since it might not be possible to always go back to attacker), so got to re-design "alot".

I will probably handle Player separately (like 1st post describes) since it's a very unique entity.

 

Thanks.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

The problem with solution proposed is the fact that it happens after attack is done.

 

Why do you say that? The forge hook onLivingAttack() is called as very first line in the attackEntityFrom() method. The attackeEntityFrom() returns a boolean that is used as a flag in attackEntityAsMob() and will prevent all the attack stuff like knockback.

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

Link to comment
Share on other sites

Yes, ideed, that's what I wrote before:

even knockback can be nicely altered here :D

 

What I ment by damaging is the fact that while Player's AttackEntityEvent happens on PLAYER himself, the LivingAttackEvent happens on entity HIT.

 

That's what I "don't like" about it.

 

For AttackEntityEvent you can cancel everything, calculate on your own and perform:

targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), DAMAGE);

 

For LivingAttackEvent you have the ENTITY that was HIT by something and the DamageSource/Damage of that HIT.

Problem here is that in this case I have to get Source, check it and only then HOPEFULLY get the attacker entity.

Then only after I got attacker, I can start calculating like I do in AttackEntityEvent.

Main problem here are a lot more checks, and most of all - problem of attacker.

"Problem of attacker" is fact that attacker's Object MIGHT dissappear while attack is being performed, thus if that happens i am unable to calculate ANYTHING (I have no attacker's stats) and I have to totally cancel event to avoid NullPointers.

 

This is REALLY critical case, but CAN happen. And I like to know there is no possible way of breaking code.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I agree that the fact that much of the attack code runs on the entity hit (the attackEntityFrom() method) does sometimes seem a bit obtuse. However, that is the way the code works and the events hook in as early as they can.

 

I am not sure about your comment that the attacking entity might disappear while you're processing the attack -- the attackEntityFrom() which invokes the event is called from the attacking entity. I don't think there is a chance of the attacker going null due to timing of when the code executes. In other words, all this is really code executing from the attacker (even though the method called is in the target entity's class).

 

To put it another way -- the events exactly match the way the vanilla methods work, so your concern would be a problem in vanilla too if it could happen.

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.