Solved Register attack damage

Discussion in 'Spigot Plugin Development' started by palamud, Feb 1, 2020.

  1. Hello everyone i m develoing plugin that makes passive mobs attack monsters now i dealt with pathfinders and entity registering. My pig approaces and tries attack to the target(it means path finders work well) but server crashes after attack action. i believe that is because my pig dosent have attack damage. My nms knowladge is not that much. Can i get help about how i am going to give my pig some attack dmg.

    Here is my pig class

    Code (Java):
    public class CustomPig extends EntityPig{

        public CustomPig(EntityTypes<? extends Entity> entitytypes, World world) {
            super(EntityTypes.PIG, world);
            Pig craftPig = (Pig) this.getBukkitEntity();
            goalSelector.a(1, new PathfinderGoalMeleeAttack(this, 1.0D, true));
              this.targetSelector.a(0, new PathfinderGoalNearestAttackableTarget(this, EntityCreature.class, true));
              this.targetSelector.a(1, new PathfinderGoalNearestAttackableTarget(this, EntityMonster.class, true));

  2. As you suspected, an entity that tries to attack with no damage attribute crashes the server. NMS is fun like that :D You can add the damage attribute with getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE);
    I'm not sure what the default value is, but you can set a new one with getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(value);
    • Winner Winner x 1
  3. You are total life saver thank you. It worked