Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello !
I'm trying to add a Water Resistance effect to the game. But, I must be missing something.

I'm using an event handler (LivingHurtEntity) to check if the damage source is DROWN and that the entity's air supply is higher than 0 (I just want to protect against water damage, but can still drown if they run out of oxygen). Then, checks if the entity has the water resistance effect. If the entity does have it, I cancel the event.

I've tested this by summoning an enderman, giving it the enchantment, then pushing/dropping him into water. I've checked, the event does get cancelled, but the enderman still takes damage on screen (turns red and teleports away).

I was just hoping somebody might have an idea of where I'm going wrong, if I should be using a different event or doing something else entirely. Thank you for your time and help, it is very much appreciated.

And here is my code. First is the event handler, then it's the water_resistance effect.

 

@Mod.EventBusSubscriber(modid = Extras.MOD_ID)
public class ModEvents {

	@SubscribeEvent
    public static void waterResistanceEffect(LivingHurtEvent event){
      
        Extras.LOGGER.debug("Check water dmg");
        Extras.LOGGER.debug("Entity: " + event.getEntity());
        Extras.LOGGER.debug("DamageSource: " + event.getSource());
        Extras.LOGGER.debug("AirSupply: " + event.getEntity().getAirSupply());
      
        if(event.getSource() == DamageSource.DROWN && event.getEntity().getAirSupply() > 0){
            Extras.LOGGER.debug("Entity is getting water damage");
          
            if(event.getEntity().hasEffect(ModMobEffects.WATER_RESISTANCE.get())){
                Extras.LOGGER.debug("Cancel event");
              
                event.setCanceled(true);
            }
        }
    }
}
public class ModEffect extends MobEffect {
    public ModEffect(MobEffectCategory category, int color) {
        super(category, color);
    }

    @Override
    public void applyEffectTick(LivingEntity p_19467_, int p_19468_) {
        super.applyEffectTick(p_19467_, p_19468_);
    }

    @Override
    public boolean isDurationEffectTick(int p_19455_, int p_19456_) {
        return true;
    }
}

 

My understanding from reading the code for LivingEntity.hurt() is that cancelling the event does not stop the all the hurt processing?

It just makes the entity hurt for 0 damage.

 

For the teleportation. That is not related to the entity taking damage.

There is separate logic and event for this: EntityTeleportEvent.EnderEntity

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

Ohhhh, okay ! I thought by cancelling the event, it would stop the whole thing, damage effect and all.
Thank you for your reply ^^

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.