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

Hi,

I am trying to implement "stun" mob effect which would prevent living entity to move or attack.

For prevention of attack I have used LivingAttackEvent like this:
 

    @SubscribeEvent
    public static void onAttacked(final LivingAttackEvent event) {

        // Get source of the damage.
        DamageSource damageSource = event.getSource();
        
        // Get reference to entity that caused the damage.
        Entity entity = damageSource.getEntity();

        // IF: Entity is not alive.
        if (!(entity instanceof LivingEntity)) {
            return;
        }

        // Cast entity to mob.
        LivingEntity mob = (LivingEntity)entity;
        
        // Get reference to level where entity is living.
        Level level = entity.getLevel();

        // IF: Code is executing on the client side.
        if (level.isClientSide()) {
            return;
        }

        // IF: Mob does not have stunned effect applied.
        if(!mob.hasEffect(PlayerMobEffects.STUNNED.get())){
            return;
        }
        
        // Cancel the event - prevent mob from doing anything.
        event.setCanceled(true);
    }

However this does not work as expected as mob still makes the attack but damage is not done so it does not really look like a stun - it's more like its damage is reduced to 0.

I have managed to totally block mob by canceling LivingUpdateEvent - but that has other side effects as living entity is not updated with anything - can't be damaged, can't be hit/burn by sun - basically it becomes immortal. :D

I have also tried with LivingSetAttackTargetEvent but this event can't be canceled. :(

Is there a way to just stop entity from making an attack?

Same question regarding the movement - is there a way to stop living entity from moving?

Thanks!

  • Author

Maybe I am doing this the wrong way?

Is it feasible to remove AI from the mob while the effect has duration?

I.e. remove AI goals responsible for wandering and attack?

I guess I will have to deal with players and mobs differently?

15 hours ago, Adil Yilan said:

Same question regarding the movement - is there a way to stop living entity from moving?

 

Hi!

You can just set the x and z delta movement to zero. But don't change the y delta movement, otherwise the entity wouldn't fall on the ground if the block under it is removed.

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

  • Author

Great ideas, gonna try them out and let you know if those worked. :)

Thanks!

Edited by Adil Yilan

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.