Mounting slimes only working 9 out of 10 times?

Discussion in 'Spigot Plugin Development' started by Simo389, May 31, 2015.

  1. So I've created a custom slime for a plugin I'm working on. It spawns in fine, all of its mechanics are working fine.

    But when I set a passenger for it as a player:
    Code (Text):
    Slime slime = CustomEntitySlime.spawn(loc);
    Code (Text):

    public class CustomEntitySlime extends EntitySlime {
        public CustomEntitySlime(World world) {
            try {
                Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
                Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
                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) {
        public static CraftSlime spawn(Location location){
            World mcWorld = ((CraftWorld) location.getWorld()).getHandle();
            CustomEntitySlime customEntity = new CustomEntitySlime(mcWorld);
            customEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
            mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
            return (CraftSlime) customEntity.getBukkitEntity();
        public void g(float sideMot, float forMot) {
            if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
                super.g(sideMot, forMot);
                this.S = 0.5F;    // Make sure the entity can walk over half slabs, instead of jumping
            this.lastYaw = this.yaw = this.passenger.yaw;
            this.pitch = this.passenger.pitch * 0.5F;

            // Set the entity's pitch, yaw, head rotation etc.
            this.setYawPitch(this.yaw, this.pitch);
            this.aK = this.aI = this.yaw;

            this.S = 1F;    // The custom entity will now automatically climb up 1 high blocks
            sideMot = ((EntityLiving) this.passenger).aZ * 0.5F;
            forMot = ((EntityLiving) this.passenger).ba;
            if (forMot <= 0.0F) {
                forMot *= 0.25F;    // Make backwards slower
            sideMot *= 0.75F;    // Also make sideways slower
            float speed = 0.35F;    // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
            this.k(speed);    // Apply the speed
            super.g(sideMot, forMot);    // Apply the motion to the entity
    9 out of 10 times it won't put the player on the slime. Instead the player glitches out and is put in the same location as the slime, but on the floor.

    Any ideas why this is happening/how to fix it? I've tried disabling the slime jumping using a pathfinder, but this is still happening. I'm running 1.8.3.
  2. Could you try running the mount code 1 tick later? I wonder if that has any effect x)