Bukkit nms

Discussion in 'Spigot Plugin Development' started by wantsome909, Apr 14, 2017.

  1. i made a custom entity (customSheep)
    I'm trying to make it deal damage to players.

    But it targets the player but doesn't deal and damage.


    Code (Text):
    public class customSheep extends EntitySheep {


        public customSheep(World world) {
            super(world);

            this.a(0.9F, 1.3F);
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(4, new PathfinderGoalFollowParent(this, 1.1D));
            this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
            this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, 2, true));
            this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true));
        }


        public void aC(){
            this.getAttributeInstance(GenericAttributes.maxHealth).setValue(20.0D); //Max Health
            this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(20.0D); //Follow Range
            this.getAttributeInstance(GenericAttributes.c).setValue(10.0D); //KnockBack resistance
            this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.4D); //Movement Speed
            this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(5.0D); //Attack damage
        }

        @Override
        public boolean n(Entity entity) {
            float f = (float) this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
            return entity.damageEntity(DamageSource.mobAttack(this), f);
        }


        public static void spawn2 (Location loc){
            World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();

            customSheep sheep = new customSheep(nmsWorld);

            sheep.setPosition(loc.getX(), loc.getY(), loc.getZ());

            nmsWorld.addEntity(sheep);
        }
     
  2. Sheep do not even have any sort of attack, what did you expect them to do?
    You would need to write a new pathfinder that manually makes them attack and deal damage.
     
    • Agree Agree x 1
    • Funny Funny x 1
  3. @FlyingLlama how can i do that? back in 1.8 i was able to make a custom sheep that would attack player just the same way i did up there


    Code (Text):
    public EasySheep(World world) {
    super(world);
    try {
    Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    bField.setAccessible(true);
    Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    cField.setAccessible(true);
    bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    } catch (Exception exc) {
    exc.printStackTrace();
    }
    this.a(0.9F, 1.3F);
    this.getNavigation().a(true);
    this.goalSelector.a(0, new PathfinderGoalFloat(this));
    this.goalSelector.a(4, new PathfinderGoalFollowParent(this, 1.1D));
    this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
    this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
    this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    }
    so i add this to entity sheep to deal damage:

    Code (Text):

        public boolean B(Entity paramEntity)
        {
            boolean bool = paramEntity.damageEntity(DamageSource.mobAttack(this), (int)getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue());
            if (bool) {
                a(this, paramEntity);
            }
            return bool;
        }
    and i get this error:
    https://gyazo.com/73bb868611673da6631162100da45f1f

    ----------------------------------------------------

    Then i tryed this:

    i just extend the entityZombie class instead of entitySheep but make the zombie look like a sheep

    But when i hit the zombie it gives me a red screen or crashes my client

    any help would be helpful
     
    #3 wantsome909, Apr 14, 2017
    Last edited: Apr 15, 2017