Mob Controlled Horses

Discussion in 'Plugin Development' started by metalhedd, Aug 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    metalhedd

    With the introduction of horses, and the discovery of the undead variants, I'm sure everyone has thought about encountering a Skeleton King riding an undead horse, wearing fully enchanted diamond gear... Unfortunately, it's not quite as easy as it should be... using the bukkit api, we can spawn an undead horse, and a skeleton, and 'stick them together' but the skeleton doesn't know how to ride a horse, and the horse won't move at all, waiting for some instructions from his rider... We need a solution! something to tell the horse to move where the skeleton wants to. There doesn't appear to be any API for it so its gotta be some NMS voodoo, Has anyone figured this out yet? Anyone have any helpful information, or done any research on it? I'm planning to take a crack at it soon and any advice would be appreciated.
     
  2. Offline

    caseif

    You'll need to get the horse's navigation and play around with that. A Google search or two should point you in the right direction.
     
  3. Offline

    metalhedd

    *bump*

    I started poking around the source code last night. none of the horses navigation appears to be used during riding. When ridden, a horse seems just just bypass all AI and do what it's rider wants. I still can't find the relevant bits of code that decide the movement should be done by the horse instead of the player. I almost suspect that its happening directly in response to the keyboard input by the player, as if, when riding a horse, the arrow key control is given directly to the horse and the player is just along for the ride.. this MIGHT be supported by the fact that the horse is the only other entity in the game (besides player) which overrides the method which MCP calls "moveEntityWithHeading(float strafe, float forward)"
     
  4. Offline

    metalhedd

    bump? I would have thought more people would be interested in this..
     
  5. Offline

    xTrollxDudex

  6. Offline

    metalhedd

    xTrollxDudex PathfinderGoalTame is responsible for the actual taming behaviour of the horse (bucking you off after a set time, and then eventually displaying hearts and becoming tame) it's not related to riding at all.

    I know I can use setVelocity to 'manually' move the horse, but Im fairly sure the moveEntityWithHeading method is the preferred way for horses (though I might be wrong, that's going to be my first attempt I think) The hard part is 'transferring control' so-to-speak, from the skeleton to the horse. I'll end up having to create one or more custom AI's to replace the rider's default functionality and send the movement's to a mount (if there is one). hopefully its as easy as I just made that sound...
     
  7. Offline

    xTrollxDudex

    Scheduler? I got to that part at least, the last part I didn't understand
     
  8. Offline

    metalhedd

    No, a scheduler, isn't going to be of any help, either.... Thanks for trying though :)
     
  9. Offline

    jeremytrains

  10. Offline

    RawCode

    just replace AI of horse to AI of mob that ride horse.
     
  11. Offline

    metalhedd

  12. Offline

    RawCode

    its super easy actually, mob ai is not hidden anywhere.

    Code:
        public EntityZombie(World world) {
            super(world);
            this.getNavigation().b(true);
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
            this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntityVillager.class, 1.0D, true));
            this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
            this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
            this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
            this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
            this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
            this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityVillager.class, 0, false));
            this.a(0.6F, 1.8F);
        }
    this is zombie AI setup, you can find it inside zombie class.

    setting same params for horse will make it behave like zombie and hit like zombie.
     
  13. Offline

    jeremytrains

    metalhedd RawCode
    Would it work if instead I tried using the navigation of the passenger of the Horse? The problem is the passenger is a player, and I can't find a way to get the navigation for a player.
     
  14. Why don't do it like this:
    (This theory will onky work if it's possible to get the entity another entity is mountng and if the skelton class contains a "move(x, y, z, yaw, pitch) method)
    override the move(x, y, z, yaw, pitch) method in the EntitySkeleton class, then get the entity the skelton is mounting (in this case the horse) and just do: horse.move(x, y, z, yaw, pitch);

    Like I said this would only work if both classes contain given methods.
     
  15. Offline

    metalhedd


    Have you actually done this? trust me it's not that easy. If it were there would be a bunch of plugins offering mounted mobs. I've done plenty of work with custom AI, in the past, I know how all of that works, and it doesn't help.

    It's good that this thread is getting some attention again, and maybe it will spark someone's interest enough to actually figure it out... but the speculation doesn't help. all of the simple theories have been exhausted, TBH I forget exactly where I ran into trouble when attempting this, but it's nowhere near as easy as just overriding some methods or injecting some AI. I would love to be proven wrong, but this thread has existed for 4 months, and there are still no plugins on bukkitdev that can spawn a mob on a horse and actually have them properly control the horse.
     
  16. Offline

    jeremytrains

    I will try and look into it and see what I can do. If anybody figures it out and confirms it, post the solution here
     
  17. Offline

    jeremytrains

    metalhedd
    Do you know where the line of code is that says "if the mob is mounted then cancel" when trying to execute navigation? If we can find that we can simply extend the class, create our own version of it without that line of code, and use our version for the mobs we want to control.
     
  18. Offline

    biel

    Using lib's like BKCommonLib to avoid the NMS stuff would work?
     
  19. Offline

    ZodiacTheories

  20. Offline

    biel

  21. It would be nice if we could figure this out.
     
Thread Status:
Not open for further replies.

Share This Page