Posted January 27, 201510 yr comment_140155 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); } } } } }
January 27, 201510 yr Author comment_140159 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?
January 27, 201510 yr comment_140164 That should work - did you register your handler to the MinecraftForge event bus? http://i.imgur.com/NdrFdld.png[/img]
January 27, 201510 yr Author comment_140167 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)
January 27, 201510 yr comment_140174 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. http://i.imgur.com/NdrFdld.png[/img]
January 27, 201510 yr Author comment_140181 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.
January 27, 201510 yr comment_140218 Try using event.entity rather than event.entityLiving Maker of the Craft++ mod.
January 27, 201510 yr comment_140222 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. http://i.imgur.com/NdrFdld.png[/img]
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.