Posted September 12, 20232 yr Hello, people, sorry for bothering. I'm trying to change every mob to be aggressive to the player, but I can't change their Attributes to add ATTACK_DAMAGE. Can someone help me? Mob mob = (Mob) event.getEntity(); if(!mob.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)){ mob.getAttributes().assignValues(new AttributeMap(AttributeSupplier.builder().add(Attributes.ATTACK_DAMAGE, 1).build())); } if(mob.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)) { mob.setCustomName(Component.literal("Aggressive")); mob.goalSelector.addGoal(1, new MeleeAttackGoal((PathfinderMob) mob, 1.0, false)); mob.goalSelector.addGoal(2, new LookAtPlayerGoal(mob, Player.class, 8.0F)); mob.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(mob, Player.class, true)); } Thanks.
September 12, 20232 yr Author Update, I've seen that I need "TransientAttributeModifiers" to do that, I've managed to change the AI properly, but always something "Pacific" attacks me, the game crashes. The .put to add Attack Damage seems to not work somehow. public static Multimap<Attribute, AttributeModifier> getAttributeModifiers() { Multimap<Attribute, AttributeModifier> temp = LinkedHashMultimap.create(); temp.put(Attributes.ATTACK_DAMAGE, new AttributeModifier("ATTACK_DAMAGE", 1, AttributeModifier.Operation.ADDITION)); return temp; } @SubscribeEvent public static void onEntityJoinLevelEvent(EntityJoinLevelEvent event) { if(!(event.getEntity() instanceof PathfinderMob mob)) return; if(!mob.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)){ mob.setCustomName(Component.literal("Pacific")); mob.getAttributes().addTransientAttributeModifiers(getAttributeModifiers()); } if(mob.getAttributes().hasAttribute(Attributes.ATTACK_DAMAGE)) { mob.setCustomName(Component.literal("Hostile")); mob.goalSelector.addGoal(1, new MeleeAttackGoal(mob, 1.0, false)); mob.goalSelector.addGoal(2, new LookAtPlayerGoal(mob, Player.class, 8.0F)); mob.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(mob, Player.class, true)); } } Thanks
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.