Jump to content

Recommended Posts

Posted

My handler for preventing fall attack sources when a certain potion is active is not cancelling the event. Can confirm potion is active at time of event (impact).

 

 

	@SubscribeEvent
public void onLivingAttack(LivingAttackEvent event) {
	if (event.entityLiving != null) {
		if(event.entityLiving instanceof EntityPlayer) {    
			EntityPlayer player = ((EntityPlayer)event.entityLiving);
			if (player.isPotionActive(ModPotions.safetyFall)) {
				if (event.source == DamageSource.fall) {
					event.setCanceled(true);
				}
			}
		}
	}
}

 

Posted

Switch to LivingHurtEvent.

 

Same result and AFAIK it's cleanest to cancel at the attack stage when possible.

 

 

@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
	if (event.entityLiving != null) {
		if(event.entityLiving instanceof EntityPlayer) {    
			EntityPlayer player = ((EntityPlayer)event.entityLiving);
			if (player.isPotionActive(ModPotions.SafetyFall)) {
				if (event.source == DamageSource.fall) {
					event.setCanceled(true);
				}
			}
		}
	}
}

 

 

EDIT: It doesn't seem to be passing the isPotionActive test which is confusing because my living update event handler passes the same event. When exactly are the hurt and attack events called for fall damage?

Posted

Yes it's registered, I've got a LivingUpdateEvent method in the same class that is working perfectly with all my other custom potions.

 

EDIT:

 

Quick context: this is for a powered armor suit that charges up and gains extremely fast flight for a time after charging, then after that time it has to recharge again for a while. This flight is controlled by another potion. The player wearing said suit gains the SafetyFall potion for 5 seconds when the latter is first removed.

 

It works if I use a constantly re-applied potion in the if statement (the suit applies 1 tick of Potion.moveSpeed every tick)

Posted

LivingAttackEvent is called on both server and client side when the event.entity is a player; put some logging statements or printlns in there to see what exactly is going on and on which side it is being called, such as if the potion is active and if so on which side(s).

 

At the very least, you want it to be active on the server side and cancel the server side event, as that is what will actually cause damage to the player. I don't think there is actually anything that happens as a result of processing on the client side, so you probably don't need to worry about that at all.

Posted

LivingAttackEvent is called on both server and client side when the event.entity is a player; put some logging statements or printlns in there to see what exactly is going on and on which side it is being called, such as if the potion is active and if so on which side(s).

 

At the very least, you want it to be active on the server side and cancel the server side event, as that is what will actually cause damage to the player. I don't think there is actually anything that happens as a result of processing on the client side, so you probably don't need to worry about that at all.

 

I'm certain that's not the issue because when I changed my custom potion to be applied once per tick rather than once off for 5 seconds it worked as expected. Of course the problem with that is it gives the player fall immunity 24/7 rather than for a limited period of time after losing power, but it'll do for now.

Posted

Try using event.entity rather than event.entityLiving

Those are exactly the same... -.-

 

@OP It sounds like your potion effect just wasn't active - applying it once per tick for one tick isn't nearly long enough. Do you want the player to take no damage ONLY while still wearing your armor? Check if the player is wearing the armor then, rather than using a potion effect, during the LivingAttackEvent.

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.