Solved Add potion effects to mobs

Discussion in 'Plugin Development' started by Robin Bi, Jul 25, 2014.

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

    Robin Bi

    Hey there :3


    For a minigame I'm currently working on I need to "enchant" mobs. So the player has a stick with which he can e.g. poison mobs (rightclick).

    Code:java
    1. @EventHandler
    2. public void onRightClick(PlayerInteractEntityEvent piee) {
    3. if (!(piee.getRightClicked() instanceof LivingEntity)) return; // So that the player does not poison a minecart.
    4.  
    5. LivingEntity lentity = (LivingEntity) piee.getRightClicked();
    6. if (piee.getPlayer().getItemInHand().getType() != null && piee.getPlayer().getItemInHand().getType() == Material.STICK) {
    7. lentity.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 1));
    8. }
    9. }


    But there's neither an effect nor an error. Adding the potion effect as i did it seems to not do anything at all...

    By googling I found this thread, where the thread author himself came up with the idea of doing
    Code:java
    1. lentity.hasPotionEffect(PotionEffectType.POISON);

    He / she was sure that this fixed his / her problem, but it just returns a boolean and IMO doesn't do anything but this. It does not really _add_ the effect, does it? :eek:



    Hopefully someone can show me how to add those effects.

    Thanks,
    ~Robin Bi
     
  2. Offline

    Jalau

    Did you added a debug line to check if this line: lentity.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 1)); does get called? And also rightclick a sheep or something like that, because poison won't do anything on zombie, so maybe thats the reason ^^ The other stuff is right and should work,but better check: "piee.getPlayer().getItemInHand() != null" instead of "piee.getPlayer().getItemInHand().getType() != null" ;)
     
  3. Offline

    Robin Bi

    Jalau Oh man, THANK you! I did not know that poison doesn't effect hostile mobs...
     
  4. Offline

    Jalau

    No problem ^^
     
Thread Status:
Not open for further replies.

Share This Page