Posted January 30, 20214 yr Hi 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 January 30, 20214 yr by <Gl33p_0r4nge>
January 31, 20214 yr Author 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: @SubscribeEvent 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"); goalsField.setAccessible(true); 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"); targetClassField.setAccessible(true); Class<?> targetClass = (Class<?>) targetClassField.get(goal); if (targetClass == PlayerEntity.class || targetClass == ServerPlayerEntity.class) { Field targetESField = goal.getClass().getDeclaredField("targetEntitySelector"); targetESField.setAccessible(true); 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) { noSuchFieldException.printStackTrace(); } } } } thanks for help! Edited January 31, 20214 yr by <Gl33p_0r4nge>
January 31, 20214 yr Author Okay I know that what I did is horible but I look at it and rework it so now Im using the ObfuscationReflectionHelper and it works fine. But for the static final, I need to call it only once each time enitity spawns (or the world loads) so I think its not neccessary.
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.