Custom mob AI API

Discussion in 'Bukkit Discussion' started by john01dav, Jun 15, 2014.

?

Do you think this is a good idea?

  1. yes - but I would not use it

    11.1%
  2. yes - I would use it

    77.8%
  3. yes - some other reason (please explain in a reply!)

    0 vote(s)
    0.0%
  4. no - it would be useless

    11.1%
  5. no - some other reason (please explain in a reply!)

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    john01dav

    Hello Bukkit! I think that an api to give mobs a custom api would be good, it would work something like this:
    The way it would work is that there would be a system of AI controllers. Each entity would have a controller, by default the controller is null which gives vanilla behaviour.
    To spawn a custom ai mob you would have the following code (or something similar):
    Code:
    Entity entity = getServer().getWorld("world").spawnEntity(location, EntityType.SKELETON);
            entity.setAIController(new MyCustomAiController());
    Then, the MyCustomAiController class looks like this:
    Code:
    public class MyCustomAiController implements AiController{
        //this method is called each tick, it allows the custom ai to implement it's behaviour. If the programmer wants this to be called every x ticks, they can provide an additional parameter to setAiController(AiController c, int tickInterval)
        public void onTick(Entity entity, AIControllerInterface interface){
            //there is no need to check if the entity is instanceof skeleton, because the api only calls this function for entities that this class was added to, and in this example it is only added to a single skeleton
            Skeleton skeleton = ((Skeleton) entity);
            //the setPathFindTo method tells the api where the skeleton should try to go. This uses the built in pathfinding behaviour. To make the entity stay still, this will be set to null or the entites location. This example makes the entity keep on moving no matter what (unless it dies from lava/cactus/etc., in which case the AIController is dropped so that the garbage collector removes it from memory).
            interface.setPathFindTo(skeleton.getLocation().add(10, 0, 10));
        }
    }
    While you can currently do this with NMS, this makes it much easier because it removes the need for reflection and/or updating the plugin (package names) with each minecraft update.
    Note: special actions (such as skeletons shooting arrows, or creepers blowing up, etc) are not to be triggered by spigot while a custom ai controller is in use, instead the ai controller triggers these actions by calling a method on the entity, for instance creeper.explode().
    EDIT:
    Additionally, there could be a built in AI controller to allow players to ride this mob. It works like this:
    Code:
    //the player rides on the enderdragon
    dragon.setPassenger(player);
    //This built-in AiController allows the player to control the mob with WASD (or whatever their movement keys are). The second argument, if true, allows them to make the mob go up and down with their creative move flight keys (player.setAllowFlight(true) to make the client send the packets)
    dragon.setAiController(new PlayerControllerAiController(player, true));
     
  2. Offline

    ledship

    This would be awesome.
     
    john01dav likes this.
  3. Offline

    stink123456

    I use citizens atm for all my mob happenings.
     
  4. Offline

    ledship

    This would remove the need for an external plugin to create npc's tho which would be good
     
  5. Offline

    stink123456

    true dat
     
Thread Status:
Not open for further replies.

Share This Page