Jump to content

[1.7.10] Canceling LivingHurtEvent for player doesn't prevent hurt animation


Recommended Posts

Posted

For context, I am trying to create an item that will allow the player to glide when held, and I want fall distance to reset to 0 if the player is gliding. I don't want to just cancel all fall damage because I will eventually create either a magic or stamina bar for the player which depletes as the player is gliding. If the bar reaches zero, the player should not be able to glide, and fall from that height.

 

To accomplish this, I added code to the item's onUpdate to check if the item is equipped and space is held (so the item can act like a parachute), and to modify fall distance appropriately.

 

I tried explicitly setting EntityPlayer's fallDistance property, but that didn't seem to do anything, so I instead saved the player's Y coordinate as lastGlidedYCoord, and created a handler for LivingFallEvent, which set the event.distance to be the difference between player.posY and lastGlidedYCoord. Still no luck.  :-\

 

Finally, I created a LivingHurtEvent handler and, for DamageSource.fall, explicitly computed fallDamage based on my fallDistance, and set event.ammount (actual spelling, I verified) to the value, and that worked.  :D

 

However, even if the player glides all the way to the ground and takes no damage, the hurt sound and animation still play. To try to resolve this, I added a check in the LivingHurtEvent handler to see if the fallDamage was less than .5 hearts. If so, I canceled the event. No change. My current handler method looks like this:

 

// this boolean tracks if the player has glided since jumping
// so that don't recompute every time the player takes fall damage
boolean alterFall;
double lastGlidedYCoord;

@SubscribeEvent
public void onLivingHurtEvent(LivingHurtEvent event) {
    if (alterFall && event.entity instanceof EntityPlayer && event.source == DamageSource.fall) {
        EntityPlayer player = (EntityPlayer)event.entity;
        double recompFallDamage = Math.floor( (lastGlidedYCoord- player.posY - 3) / 2 );
        if (recompFallDamage < 1) {
            event.setCanceled(true);
        } else {
            event.ammount = (float) recompFallDamage;
        }
        alterFall = false;
    }
}

 

 

Any help getting my mod to work as desired would be much appreciated, thanks!

Posted

Not sure if it helps but there is also the LivingFallEvent which can be canceled to set fallDistance to 0.  Not sure if that also prevents the hurt animation, but I think it will because of the following.

 

The hurt animation is related to the attackEntityFrom() method.  If you look in EntityLivingBase there is method called fall() and that is where it triggers the LivingFallEvent (and passes fall distance), plays the hurt sound and also invokes the attackEntityFrom() with a DamageSource.FALL.  If you cancel the event, it won't play the sound or invoke the damage.

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

Posted

The problem is that to check if space is held, you must be on the client side, but to affect the fall distance, you must be on the server side, so your checks are incompatible.

 

Two solutions:

 

a) Set your item in use via right click and check if the player is using the item before setting fall distance

 

b) Check each tick if space bar is still pressed and send a packet when it is first pressed, to set the item in use or something, and then another when it is released; this will give the server the information it needs in your item's onUpdate method.

Posted

Not sure if it helps but there is also the LivingFallEvent which can be canceled to set fallDistance to 0.

 

The problem is that to check if space is held, you must be on the client side, but to affect the fall distance, you must be on the server side, so your checks are incompatible.

 

Turns out, both these things were necessary to fix the problem. I created a handler for LivingFallEvent, gave it access to some data from the client-side gliding checks I was performing in the onUpdate, and made sure it executed on the server side. No more hurt animation or sound!  :)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.