Jump to content

[1.16.4] mob Tracking/Attacking player


Recommended Posts


maybe Im super dumb but I just cant find where to change/cancel what entity should be the mob attacking (I mean the thing when for example zombie follows you and attacks you) can someone tell me where can I find this and how to change the value to null or cancel the tracking?


I just want to make mob neutral when Im wearing my custom mod armor.


Thanks for any help.

Edited by <Gl33p_0r4nge>
Link to comment
Share on other sites

OMG it works but not completly. It will probably be something with my code bcs I have never used predicates or reflections but I somehow managed to make it work (and Im proud of it 😆). So now I have problem with that when it is not "angry" on me and I have the armor its okay he don't even notice me but while he is targeting me and I equip the armor he is still following me and is trying to hit me.


Here is the code:

    public static void onEntityJoin(EntityJoinWorldEvent event){
        if (event.getEntity().isLiving()) {
            LivingEntity living = (LivingEntity) event.getEntity();
            if (living.isEntityUndead()) {
                MonsterEntity monster = (MonsterEntity) event.getEntity();
                Field goalsField = null;
                try {
                    goalsField = monster.targetSelector.getClass().getDeclaredField("goals");
                    Set<PrioritizedGoal> goals = (Set<PrioritizedGoal>) goalsField.get(monster.targetSelector);
                    for (PrioritizedGoal g : goals) {
                        if (g.getGoal() instanceof NearestAttackableTargetGoal<?>){
                            NearestAttackableTargetGoal<?> goal = (NearestAttackableTargetGoal<?>) g.getGoal();
                            Field targetClassField = goal.getClass().getDeclaredField("targetClass");
                            Class<?> targetClass = (Class<?>) targetClassField.get(goal);
                            if (targetClass == PlayerEntity.class || targetClass == ServerPlayerEntity.class) {
                                Field targetESField = goal.getClass().getDeclaredField("targetEntitySelector");
                                EntityPredicate targetEntitySelector = (EntityPredicate) targetESField.get(goal);

                                targetEntitySelector.setCustomPredicate((target) -> {
                                    for (ItemStack itemStack : target.getArmorInventoryList()) {
                                        if (ItemTags.getCollection().getTagByID(
                                                new ResourceLocation("oreganized:silver_tinted_items"))
                                                .contains(itemStack.getItem())) return false;
                                    return true;
                } catch (NoSuchFieldException | IllegalAccessException noSuchFieldException) {


thanks for help!

Edited by <Gl33p_0r4nge>
Link to comment
Share on other sites

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.

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.


  • Create New...

Important Information

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