Posted January 22, 20223 yr 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. 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!
January 23, 20223 yr 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?
January 23, 20223 yr 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 Also: PLEASE use SPOILERS for logs!
January 23, 20223 yr Author Great ideas, gonna try them out and let you know if those worked. Thanks! Edited January 23, 20223 yr 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.