Pigs attacking while being attacked.

Discussion in 'Plugin Development' started by Bust_Open, Sep 1, 2012.

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

    Bust_Open

    Well so far I'm trying to make it so pigs attack on sight, but it's not working.

    Can anyone help me make it so pigs attack while being attacked?

    current code:

    @EventHandler
    public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    List<
    Entity> worldEntities = world.getEntities();
    for (
    Entity entity : worldEntities) {
    if(
    entity.getClass().getName().equalsIgnoreCase("PIG")) {
    Creature creature = (Creature) entity;
    creature.setTarget(player);
    }
    }
    }
     
  2. Offline

    zachoooo

    Pigs can't actually attack. Even if they we're targetting the player, all they would do if look at the player.
     
  3. Offline

    Bust_Open

    i'm source it's possible with damage event
     
  4. Offline

    zachoooo

    I mean you could make it so that the pigs follow players and cause damage within a certain range or something, but they cannot "naturally" attack players.
     
  5. Offline

    Bust_Open

    mhm, i'm trying to do the unnatural part, care to help? :D

    /help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  6. Offline

    zachoooo

    what are you having trouble with?
     
  7. Offline

    user_43347

    Heads up, looping through all entities in the world every time a player moves, is a recipe for disaster.
     
    np98765 likes this.
  8. Offline

    Courier

    This.

    Also, the entity's class name would be CraftPig, not Pig. You would want to do world.getEntitiesByClass(Pig.class)

    It would be better to only look at entities surrounding the player. player.getNearbyEntities()
    Also, your current code does not account for a pig attacking a player who stands still.
     
Thread Status:
Not open for further replies.

Share This Page