How to set animals into breed mode?

Discussion in 'Plugin Development' started by Shzylo, Jul 31, 2013.

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

    Shzylo

    I am trying to add Rotten Flesh to allow animals to breed, and I might have to use NBT or whatever it is, which I have no idea on how to use to allow this. Here is my current code:
    Code:java
    1. @EventHandler
    2. public void onAnimalBreed(PlayerInteractEntityEvent e) {
    3. Player p = e.getPlayer();
    4. Material hand = p.getItemInHand().getType();
    5.  
    6. if(enabled) {
    7. if(hand.equals(Material.ROTTEN_FLESH)) {
    8. if(e.getRightClicked() instanceof Cow) {
    9. Cow cow = (Cow) e.getRightClicked();
    10. if(cow.isAdult()) {
    11.  
    12. }
    13. }
    14. }
    15. }
    16. }
     
  2. Offline

    RROD

    Change instanceof Cow to "instanceof Ageable"
    Then instead of casting to a Cow, cast to an Ageable.
    Finally "ageableEntity.setBreed(true)" will set them to breeding mode, where ageableEntity would be the name of your variable.

    This should mean that right-clicking any breedable animal with rotten flesh will breed them. You could leave it as Cow if you wanted to - setBreed() should be visible.
     
    KingFaris11 likes this.
  3. Offline

    Shzylo

    @RROD I now have this code as:
    Code:java
    1. if(e.getRightClicked() instanceof Ageable) {
    2. Ageable animal = (Ageable) e.getRightClicked();
    3. if(animal.isAdult()) {
    4. animal.setBreed(true);
    5. }
    6. }

    And it does not work, did I do something wrong in this section?
     

  4. Nothing looks wrong... Are you sure it's enabled? You said:
    Code:
    if (enabled) {
    Are you sure that variable is true?
     
  5. Offline

    Shzylo

    Yes I made sure.
     
  6. Offline

    xTrollxDudex

    Shzylo
    I would do this
    PHP:
    //playerinteractentityevent....
    if(e.getRightClicked() instanceof Cow){
    Cow cow = (Cowe.getRightClicked();
    if(
    cow.isAdult()){
    cow.setBreed(true);
    }
    }
     
  7. Offline

    Shzylo

    I noticed that I forgot to register it, so I did that. Still doesn't work. I got it to send me a message when I click on something like a cow, but it doesn't put them in breed mode.

    That should work, but no it doesn't :/

    EDIT:
    I can get it to send me a message in the isAdult() if statment, but no breeding mode..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  8. Offline

    xTrollxDudex

    Shzylo
    I guess this is kind of like setTarget or isOnGround.... Probably doesn't work.
     
  9. Offline

    RROD

    Will it send a message if the animal is an adult? If so then you'd be correct in saying that it doesn't work on the current dev builld, if that's what you're using. Try and build for the most recent release, and test on a server for that version.
     
  10. Offline

    Shzylo

    It will send me a message if they are an adult. I am running on one of the most latest builds (probably not the last released one though) I will probably update it.

    bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    Garris0n

    isOnGround works, it's just not 100% effective on players because fly-hacks and nofall hacks fake it.
     
  12. Offline

    xTrollxDudex

    Garris0n
    Never worked with my arrows.
     
Thread Status:
Not open for further replies.

Share This Page