NMS Questions

Discussion in 'Spigot Plugin Development' started by Simagdo, Apr 18, 2017.

  1. Hey there,
    i am currently learning NMS and i have some questions about that. I created a custom Skeleton and i wanted to know, if it is possible to change the delay of shooting arrows. Also i want, that he will stand still but the skeleton will move around. Here is the custom skeleton:
    Code (Text):

    public class TowerSkeleton extends EntitySkeleton {

        public TowerSkeleton(World world) {
            super(world);
            r();
        }

        @Override
        public boolean B(Entity entity) {
            super.B(entity);
            this.setSlot(EnumItemSlot.MAINHAND, new ItemStack(Items.BOW));
            this.setSlot(EnumItemSlot.HEAD, new ItemStack(Items.CHAINMAIL_HELMET));
            return true;
        }

        @Override
        protected void r() {
            this.goalSelector = new PathfinderGoalSelector(world.methodProfiler);
            this.targetSelector = new PathfinderGoalSelector(world.methodProfiler);
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntitySheep.class, true));
            this.goalSelector.a(3, new PathfinderGoalFleeSun(this, 0.0D));
            this.goalSelector.a(2, new PathfinderGoalRestrictSun(this));
        }

        public TowerSkeleton spawn(Location location) {
            try {
                if (!(location.getChunk().isLoaded())) location.getChunk().load();
                TowerSkeleton skeleton = new TowerSkeleton(((CraftWorld) location.getWorld()).getHandle());
                B(skeleton);
                skeleton.setPosition(location.getX(), location.getY(), location.getZ());

                this.goalSelector.a(5, new PathfinderGoalArrowAttack(this, 1.0D, 20, 60, 15.0f));

                this.targetSelector.a(5, new PathfinderGoalArrowAttack(this, 1.0D, 20, 60, 15.0f));

                (((CraftWorld) location.getWorld()).getHandle()).addEntity(skeleton, CreatureSpawnEvent.SpawnReason.CUSTOM);
                return skeleton;
            } catch (Exception e) {
                System.err.println("Error: " + e);
                return null;
            }
        }

    }
     
    Also, the skeleton only gets the Bow and the helmet, after he attacks the first enemy, in my case a sheep.
    Another question i have, i want to create another custom entity and i would like to know, if it is possible to disable it, so the entity won't go through water and use instead a bridge or so.

    Yours
    Simon
     
  2. Can nobody help me?
     
  3. Never did much with custom entities, but as far as I know you have to clear the old behaviour first. You are extending a Skeleton so as long as you do not clear the default behavior, all the normal skelleton behaviour is still there.

    Have you read this tutorial on pathfinder goals? link
     
  4. I have cleared the default behavior with this:
     
  5. Moving
    Stop Entity from moving? -> Override the "move(double d0, double d1, double d2)" function in your class or use disable the entity ai by using > setAI(false); .

    Item Slots
    Why does the skeleton only get his item content at attack? -> The "B(Entity entity)" method is for attack and applying ( if skeleton type is 1 - wither) the wither effect / or just ignoring the method
    How do you fix this? Just use the "setSlot()" method at the class constructor beginning or if you received errors, at the "r()" method where you apply the pathfinders.

    Pathfinder Bridges
    How to modify the entity so he walks on blocks like bridges? -> You have to modify some pathfinders, its a bit complicated but possible, you can take a look at the normal entities like pig or similar there's also a pathfinder called PathfinderGoalPanic that has been implemented in pig class, where he also avoids something like water so there you have some beginnings.

    Arrow Speed Delay
    How to modify the Delay between arrows ? -> There's a private final field called "c" in 1.9 that has a PathFinder for Bow shootings,
    ( private final PathfinderGoalBowShoot c = new PathfinderGoalBowShoot(this, 1.0D, 20, 15.0F); )
    I am not very familar with the values for that, but it seems like different values for damage and delay, just change some values and check the difference

    Hope i could help you out a bit

    Cheers, Phloxz
     
    • Informative Informative x 2
  6. First of all, very detailed information. I will try it out and reply again.

    Edit:
    I didn't found the method move(double d0, double d1, double d2), so i tryed to use setAI(false) but the skeleton is still walking around if he find a sheep.
    Also, i tryed to change the speed of shooting arrows, but it still shoots as normal.
     
    #6 Simagdo, Apr 19, 2017
    Last edited: Apr 19, 2017